From 34eb1def44f39f48b06ba75b2bde5dfc13245ef8 Mon Sep 17 00:00:00 2001 From: bggRGjQaUbCoE Date: Mon, 20 Jan 2025 11:15:58 +0800 Subject: [PATCH] feat: custom enable search suggestion Signed-off-by: bggRGjQaUbCoE --- lib/pages/search/controller.dart | 9 +++++++-- lib/pages/setting/widgets/model.dart | 7 +++++++ lib/utils/storage.dart | 4 ++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/pages/search/controller.dart b/lib/pages/search/controller.dart index ae7bd675..69b4a1d7 100644 --- a/lib/pages/search/controller.dart +++ b/lib/pages/search/controller.dart @@ -4,6 +4,7 @@ import 'package:get/get.dart'; import 'package:PiliPlus/http/search.dart'; import 'package:PiliPlus/models/search/suggest.dart'; import 'package:PiliPlus/utils/storage.dart'; +import 'package:get/get_rx/src/rx_workers/utils/debouncer.dart'; class SSearchController extends GetxController { final searchFocusNode = FocusNode(); @@ -23,6 +24,9 @@ class SSearchController extends GetxController { RxBool showUidBtn = false.obs; + final _debouncer = Debouncer(delay: const Duration(milliseconds: 200)); + late final searchSuggestion = GStorage.searchSuggestion; + @override void onInit() { super.onInit(); @@ -54,8 +58,8 @@ class SSearchController extends GetxController { validateUid(); if (value.isEmpty) { searchSuggestList.clear(); - } else { - querySearchSuggest(value); + } else if (searchSuggestion) { + _debouncer.call(() => querySearchSuggest(value)); } } @@ -136,6 +140,7 @@ class SSearchController extends GetxController { void onClose() { searchFocusNode.dispose(); controller.dispose(); + _debouncer.cancel(); super.onClose(); } } diff --git a/lib/pages/setting/widgets/model.dart b/lib/pages/setting/widgets/model.dart index 29ddc2ed..28398f2b 100644 --- a/lib/pages/setting/widgets/model.dart +++ b/lib/pages/setting/widgets/model.dart @@ -1903,6 +1903,13 @@ List get extraSettings => [ defaultVal: false, needReboot: true, ), + SettingsModel( + settingsType: SettingsType.sw1tch, + title: '搜索建议', + leading: Icon(Icons.search), + setKey: SettingBoxKey.searchSuggestion, + defaultVal: true, + ), SettingsModel( settingsType: SettingsType.sw1tch, enableFeedback: true, diff --git a/lib/utils/storage.dart b/lib/utils/storage.dart index 8a7fa73c..86e2c3a9 100644 --- a/lib/utils/storage.dart +++ b/lib/utils/storage.dart @@ -348,6 +348,9 @@ class GStorage { static bool get mainTabBarView => GStorage.setting.get(SettingBoxKey.mainTabBarView, defaultValue: false); + static bool get searchSuggestion => + GStorage.setting.get(SettingBoxKey.searchSuggestion, defaultValue: true); + static List get dynamicDetailRatio => List.from(setting .get(SettingBoxKey.dynamicDetailRatio, defaultValue: [60.0, 40.0])); @@ -573,6 +576,7 @@ class SettingBoxKey { superResolutionType = 'superResolutionType', preInitPlayer = 'preInitPlayer', mainTabBarView = 'mainTabBarView', + searchSuggestion = 'searchSuggestion', // Sponsor Block enableSponsorBlock = 'enableSponsorBlock',