feat: record search history option

Closes #592

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-04-04 12:00:03 +08:00
parent 849329b66b
commit 8c259205f5
5 changed files with 72 additions and 8 deletions

View File

@@ -10,6 +10,9 @@ import 'package:PiliPlus/utils/storage.dart';
import 'package:get/get_rx/src/rx_workers/utils/debouncer.dart'; import 'package:get/get_rx/src/rx_workers/utils/debouncer.dart';
class SSearchController extends GetxController { class SSearchController extends GetxController {
late final historyOff =
'<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#000000"><path d="m785-289-58-58q16-29 24.5-63t8.5-70q0-117-81.5-198.5T480-760q-35 0-68.5 8.5T348-726l-59-59q43-26 91.5-40.5T480-840q75 0 140.5 28.5t114 77q48.5 48.5 77 114T840-480q0 53-14.5 101T785-289ZM520-554l-80-80v-46h80v126ZM792-56 672-176q-42 26-90 41t-102 15q-138 0-240.5-91.5T122-440h82q14 104 92.5 172T480-200q37 0 70.5-8.5T614-234L288-560H120v-168l-64-64 56-56 736 736-56 56Z"/></svg>';
final searchFocusNode = FocusNode(); final searchFocusNode = FocusNode();
final controller = TextEditingController(); final controller = TextEditingController();
@@ -29,6 +32,7 @@ class SSearchController extends GetxController {
final _debouncer = Debouncer(delay: const Duration(milliseconds: 200)); final _debouncer = Debouncer(delay: const Duration(milliseconds: 200));
late final searchSuggestion = GStorage.searchSuggestion; late final searchSuggestion = GStorage.searchSuggestion;
late final RxBool recordSearchHistory = GStorage.recordSearchHistory.obs;
@override @override
void onInit() { void onInit() {
@@ -90,7 +94,7 @@ class SSearchController extends GetxController {
validateUid(); validateUid();
} }
if (MineController.anonymity.value.not) { if (MineController.anonymity.value.not && recordSearchHistory.value) {
historyList.remove(controller.text); historyList.remove(controller.text);
historyList.insert(0, controller.text); historyList.insert(0, controller.text);
GStorage.historyWord.put('cacheList', historyList); GStorage.historyWord.put('cacheList', historyList);

View File

@@ -1,7 +1,9 @@
import 'package:PiliPlus/common/widgets/loading_widget.dart'; import 'package:PiliPlus/common/widgets/loading_widget.dart';
import 'package:PiliPlus/http/loading_state.dart'; import 'package:PiliPlus/http/loading_state.dart';
import 'package:PiliPlus/models/search/suggest.dart'; import 'package:PiliPlus/models/search/suggest.dart';
import 'package:PiliPlus/utils/storage.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'controller.dart'; import 'controller.dart';
import 'widgets/hot_keyword.dart'; import 'widgets/hot_keyword.dart';
@@ -199,15 +201,60 @@ class _SearchPageState extends State<SearchPage> with RouteAware {
Padding( Padding(
padding: const EdgeInsets.fromLTRB(6, 0, 6, 6), padding: const EdgeInsets.fromLTRB(6, 0, 6, 6),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
Text( Text(
'搜索历史', '搜索历史',
strutStyle: StrutStyle(leading: 0, height: 1),
style: Theme.of(context) style: Theme.of(context)
.textTheme .textTheme
.titleMedium! .titleMedium!
.copyWith(fontWeight: FontWeight.bold), .copyWith(height: 1, fontWeight: FontWeight.bold),
), ),
const SizedBox(width: 12),
Obx(
() => SizedBox(
width: 34,
height: 34,
child: IconButton(
iconSize: 22,
tooltip: _searchController.recordSearchHistory.value
? '记录搜索'
: '无痕搜索',
icon: _searchController.recordSearchHistory.value
? Icon(
Icons.history,
color: Theme.of(context)
.colorScheme
.onSurfaceVariant
.withOpacity(0.8),
)
: SvgPicture.string(
width: 22,
height: 22,
colorFilter: ColorFilter.mode(
Theme.of(context)
.colorScheme
.outline
.withOpacity(0.8),
BlendMode.srcIn,
),
_searchController.historyOff,
),
style: IconButton.styleFrom(
padding: EdgeInsets.zero,
),
onPressed: () {
_searchController.recordSearchHistory.value =
!_searchController.recordSearchHistory.value;
GStorage.setting.put(
SettingBoxKey.recordSearchHistory,
_searchController.recordSearchHistory.value,
);
},
),
),
),
const Spacer(),
SizedBox( SizedBox(
height: 34, height: 34,
child: TextButton.icon( child: TextButton.icon(

View File

@@ -1974,6 +1974,13 @@ List<SettingsModel> get extraSettings => [
setKey: SettingBoxKey.searchSuggestion, setKey: SettingBoxKey.searchSuggestion,
defaultVal: true, defaultVal: true,
), ),
SettingsModel(
settingsType: SettingsType.sw1tch,
title: '记录搜索历史',
leading: const Icon(Icons.history),
setKey: SettingBoxKey.recordSearchHistory,
defaultVal: true,
),
SettingsModel( SettingsModel(
settingsType: SettingsType.sw1tch, settingsType: SettingsType.sw1tch,
title: '展示头像/评论/动态装饰', title: '展示头像/评论/动态装饰',

View File

@@ -1763,11 +1763,13 @@ class _VideoDetailPageVState extends State<VideoDetailPageV>
.plPlayerController.isOpenDanmu.value .plPlayerController.isOpenDanmu.value
? 'assets/images/video/danmu_open.svg' ? 'assets/images/video/danmu_open.svg'
: 'assets/images/video/danmu_close.svg', : 'assets/images/video/danmu_close.svg',
// ignore: deprecated_member_use colorFilter: ColorFilter.mode(
color: videoDetailController videoDetailController
.plPlayerController.isOpenDanmu.value .plPlayerController.isOpenDanmu.value
? themeData.colorScheme.secondary ? themeData.colorScheme.secondary
: themeData.colorScheme.outline, : themeData.colorScheme.outline,
BlendMode.srcIn,
),
), ),
), ),
), ),

View File

@@ -442,6 +442,9 @@ class GStorage {
static int get fastForBackwardDuration => GStorage.setting static int get fastForBackwardDuration => GStorage.setting
.get(SettingBoxKey.fastForBackwardDuration, defaultValue: 10); .get(SettingBoxKey.fastForBackwardDuration, defaultValue: 10);
static bool get recordSearchHistory => GStorage.setting
.get(SettingBoxKey.recordSearchHistory, defaultValue: true);
static List<double> get dynamicDetailRatio => List<double>.from(setting static List<double> get dynamicDetailRatio => List<double>.from(setting
.get(SettingBoxKey.dynamicDetailRatio, defaultValue: [60.0, 40.0])); .get(SettingBoxKey.dynamicDetailRatio, defaultValue: [60.0, 40.0]));
@@ -724,6 +727,7 @@ class SettingBoxKey {
appFontWeight = 'appFontWeight', appFontWeight = 'appFontWeight',
enableDragSubtitle = 'enableDragSubtitle', enableDragSubtitle = 'enableDragSubtitle',
fastForBackwardDuration = 'fastForBackwardDuration', fastForBackwardDuration = 'fastForBackwardDuration',
recordSearchHistory = 'recordSearchHistory',
// Sponsor Block // Sponsor Block
enableSponsorBlock = 'enableSponsorBlock', enableSponsorBlock = 'enableSponsorBlock',