Skip to content

基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。

feat: timeline page fliter (#1469)

林晨06d9f6a6d474
diff --git a/.gitignore b/.gitignore
index 55b8f2ef..74138746 100644
--- a/.gitignore
+++ b/.gitignore
@@ -47,3 +47,10 @@ app.*.map.json
# Added after flutter 3.29
/android/app/.cxx/
android/build/reports/problems/
+
+# CocoaPods - iOS/macOS dependencies
+# Podfile.lock is auto-generated by Flutter, no need to commit
+**/ios/Pods/
+**/macos/Pods/
+**/ios/Podfile.lock
+**/macos/Podfile.lock
diff --git a/lib/modules/collect/collect_type.dart b/lib/modules/collect/collect_type.dart
new file mode 100644
index 00000000..1ed4b3c4
--- /dev/null
+++ b/lib/modules/collect/collect_type.dart
@@ -0,0 +1,41 @@
+/// 收藏类型枚举
+///
+/// 用于标识番剧的收藏状态
+enum CollectType {
+ /// 未收藏
+ none(0, '未收藏'),
+
+ /// 在看
+ watching(1, '在看'),
+
+ /// 想看
+ planToWatch(2, '想看'),
+
+ /// 搁置
+ onHold(3, '搁置'),
+
+ /// 看过
+ watched(4, '看过'),
+
+ /// 抛弃
+ abandoned(5, '抛弃');
+
+ const CollectType(this.value, this.label);
+
+ /// 数值表示
+ final int value;
+
+ /// 显示标签
+ final String label;
+
+ /// 根据数值获取枚举
+ static CollectType fromValue(int value) {
+ return CollectType.values.firstWhere(
+ (type) => type.value == value,
+ orElse: () => CollectType.none,
+ );
+ }
+
+ /// 是否为有效的收藏状态(排除未收藏)
+ bool get isCollected => this != CollectType.none;
+}
diff --git a/lib/pages/collect/collect_controller.dart b/lib/pages/collect/collect_controller.dart
index b986eba4..70f5df63 100644
--- a/lib/pages/collect/collect_controller.dart
+++ b/lib/pages/collect/collect_controller.dart
@@ -1,9 +1,13 @@
+import 'package:flutter_modular/flutter_modular.dart';
import 'package:kazumi/bean/dialog/dialog_helper.dart';
import 'package:kazumi/modules/bangumi/bangumi_item.dart';
import 'package:kazumi/modules/collect/collect_module.dart';
import 'package:kazumi/modules/collect/collect_change_module.dart';
+import 'package:kazumi/modules/collect/collect_type.dart';
import 'package:kazumi/utils/storage.dart';
import 'package:kazumi/utils/webdav.dart';
+import 'package:kazumi/repositories/collect_crud_repository.dart';
+import 'package:kazumi/repositories/collect_repository.dart';
import 'package:hive/hive.dart';
import 'package:mobx/mobx.dart';
import 'package:logger/logger.dart';
@@ -14,8 +18,11 @@ part 'collect_controller.g.dart';
class CollectController = _CollectController with _$CollectController;
abstract class _CollectController with Store {
+ final _collectCrudRepository = Modular.get<ICollectCrudRepository>();
+ final _collectRepository = Modular.get<ICollectRepository>();
+
Box setting = GStorage.setting;
- List<BangumiItem> get favorites => GStorage.favorites.values.toList();
+ List<BangumiItem> get favorites => _collectCrudRepository.getFavorites();
@observable
ObservableList<CollectedBangumi> collectibles =
@@ -23,28 +30,20 @@ abstract class _CollectController with Store {
void loadCollectibles() {
collectibles.clear();
- collectibles.addAll(GStorage.collectibles.values.toList());
+ collectibles.addAll(_collectCrudRepository.getAllCollectibles());
}
int getCollectType(BangumiItem bangumiItem) {
- CollectedBangumi? collectedBangumi =
- GStorage.collectibles.get(bangumiItem.id);
- if (collectedBangumi == null) {
- return 0;
- } else {
- return collectedBangumi.type;
- }
+ return _collectCrudRepository.getCollectType(bangumiItem.id);
}
+ @action
Future<void> addCollect(BangumiItem bangumiItem, {type = 1}) async {
if (type == 0) {
await deleteCollect(bangumiItem);
return;
}
- CollectedBangumi collectedBangumi =
- CollectedBangumi(bangumiItem, DateTime.now(), type);
- await GStorage.collectibles.put(bangumiItem.id, collectedBangumi);
- await GStorage.collectibles.flush();
+ await _collectCrudRepository.addCollectible(bangumiItem, type);
final int collectChangeId = (DateTime.now().millisecondsSinceEpoch ~/ 1000);
final CollectedBangumiChange collectChange = CollectedBangumiChange(
collectChangeId,
@@ -52,14 +51,13 @@ abstract class _CollectController with Store {
1,
type,
(DateTime.now().millisecondsSinceEpoch ~/ 1000));
- await GStorage.collectChanges.put(collectChangeId, collectChange);
- await GStorage.collectChanges.flush();
+ await _collectCrudRepository.addCollectChange(collectChange);
loadCollectibles();
}
+ @action
Future<void> deleteCollect(BangumiItem bangumiItem) async {
- await GStorage.collectibles.delete(bangumiItem.id);
- await GStorage.collectibles.flush();
+ await _collectCrudRepository.deleteCollectible(bangumiItem.id);
final int collectChangeId = (DateTime.now().millisecondsSinceEpoch ~/ 1000);
final CollectedBangumiChange collectChange = CollectedBangumiChange(
collectChangeId,
@@ -67,22 +65,13 @@ abstract class _CollectController with Store {
3,
5,
(DateTime.now().millisecondsSinceEpoch ~/ 1000));
- await GStorage.collectChanges.put(collectChangeId, collectChange);
- await GStorage.collectChanges.flush();
+ await _collectCrudRepository.addCollectChange(collectChange);
loadCollectibles();
}
Future<void> updateLocalCollect(BangumiItem bangumiItem) async {
- CollectedBangumi? collectedBangumi =
- GStorage.collectibles.get(bangumiItem.id);
- if (collectedBangumi == null) {
- return;
- } else {
- collectedBangumi.bangumiItem = bangumiItem;
- await GStorage.collectibles.put(bangumiItem.id, collectedBangumi);
- await GStorage.collectibles.flush();
- loadCollectibles();
- }
+ await _collectCrudRepository.updateCollectible(bangumiItem);
+ loadCollectibles();
}
Future<void> syncCollectibles() async {
@@ -117,9 +106,29 @@ abstract class _CollectController with Store {
await addCollect(bangumiItem, type: 1);
count++;
}
- await GStorage.favorites.clear();
- await GStorage.favorites.flush();
+ await _collectCrudRepository.clearFavorites();
KazumiLogger().log(Level.debug, '检测到$count条未分类追番记录, 已迁移');
}
}
+
+ /// 根据收藏类型获取番剧ID集合
+ ///
+ /// [type] 收藏类型
+ /// 返回番剧ID集合
+ Set<int> getBangumiIdsByType(CollectType type) {
+ return _collectRepository.getBangumiIdsByType(type);
+ }
+
+ /// 过滤掉指定收藏类型的番剧
+ ///
+ /// [bangumiList] 原始番剧列表
+ /// [excludeType] 要排除的收藏类型
+ /// 返回过滤后的番剧列表
+ List<BangumiItem> filterBangumiByType(
+ List<BangumiItem> bangumiList, CollectType excludeType) {
+ final excludeIds = getBangumiIdsByType(excludeType);
+ return bangumiList
+ .where((item) => !excludeIds.contains(item.id))
+ .toList();
+ }
}
diff --git a/lib/pages/collect/collect_controller.g.dart b/lib/pages/collect/collect_controller.g.dart
index c36e8ce5..4ed5a1c4 100644
--- a/lib/pages/collect/collect_controller.g.dart
+++ b/lib/pages/collect/collect_controller.g.dart
@@ -25,6 +25,24 @@ mixin _$CollectController on _CollectController, Store {
});
}
+ late final _$addCollectAsyncAction =
+ AsyncAction('_CollectController.addCollect', context: context);
+
+ @override
+ Future<void> addCollect(BangumiItem bangumiItem, {dynamic type = 1}) {
+ return _$addCollectAsyncAction
+ .run(() => super.addCollect(bangumiItem, type: type));
+ }
+
+ late final _$deleteCollectAsyncAction =
+ AsyncAction('_CollectController.deleteCollect', context: context);
+
+ @override
+ Future<void> deleteCollect(BangumiItem bangumiItem) {
+ return _$deleteCollectAsyncAction
+ .run(() => super.deleteCollect(bangumiItem));
+ }
+
@override
String toString() {
return '''
diff --git a/lib/pages/index_module.dart b/lib/pages/index_module.dart
index b46f451f..fa149cb6 100644
--- a/lib/pages/index_module.dart
+++ b/lib/pages/index_module.dart
@@ -15,6 +15,9 @@ import 'package:kazumi/pages/info/info_module.dart';
import 'package:kazumi/pages/settings/settings_module.dart';
import 'package:kazumi/shaders/shaders_controller.dart';
import 'package:kazumi/pages/search/search_module.dart';
+import 'package:kazumi/repositories/collect_repository.dart';
+import 'package:kazumi/repositories/search_history_repository.dart';
+import 'package:kazumi/repositories/collect_crud_repository.dart';
class IndexModule extends Module {
@override
@@ -22,6 +25,12 @@ class IndexModule extends Module {
@override
void binds(i) {
+ // Repository层
+ i.addSingleton<ICollectRepository>(CollectRepository.new);
+ i.addSingleton<ISearchHistoryRepository>(SearchHistoryRepository.new);
+ i.addSingleton<ICollectCrudRepository>(CollectCrudRepository.new);
+
+ // Controller层
i.addSingleton(PopularController.new);
i.addSingleton(PluginsController.new);
i.addSingleton(VideoPageController.new);
diff --git a/lib/pages/search/search_controller.dart b/lib/pages/search/search_controller.dart
index fe54afb8..5400db8e 100644
--- a/lib/pages/search/search_controller.dart
+++ b/lib/pages/search/search_controller.dart
@@ -1,19 +1,20 @@
+import 'package:flutter_modular/flutter_modular.dart';
import 'package:mobx/mobx.dart';
import 'package:kazumi/modules/bangumi/bangumi_item.dart';
import 'package:kazumi/request/bangumi.dart';
import 'package:kazumi/utils/search_parser.dart';
-import 'package:kazumi/utils/storage.dart';
import 'package:kazumi/modules/search/search_history_module.dart';
-import 'package:hive/hive.dart';
+import 'package:kazumi/repositories/collect_repository.dart';
+import 'package:kazumi/repositories/search_history_repository.dart';
+import 'package:kazumi/modules/collect/collect_type.dart';
part 'search_controller.g.dart';
class SearchPageController = _SearchPageController with _$SearchPageController;
abstract class _SearchPageController with Store {
- final Box setting = GStorage.setting;
- final Box searchHistoryBox = GStorage.searchHistory;
- final Box collectiblesBox = GStorage.collectibles;
+ final _collectRepository = Modular.get<ICollectRepository>();
+ final _searchHistoryRepository = Modular.get<ISearchHistoryRepository>();
@observable
bool isLoading = false;
@@ -22,8 +23,10 @@ abstract class _SearchPageController with Store {
bool isTimeOut = false;
@observable
- late bool notShowWatchedBangumis =
- setting.get(SettingBoxKey.searchNotShowWatchedBangumis, defaultValue: false);
+ late bool notShowWatchedBangumis = _collectRepository.getSearchNotShowWatchedBangumis();
+
+ @observable
+ late bool notShowAbandonedBangumis = _collectRepository.getSearchNotShowAbandonedBangumis();
@observable
ObservableList<BangumiItem> bangumiList = ObservableList.of([]);
@@ -33,12 +36,9 @@ abstract class _SearchPageController with Store {
@action
void loadSearchHistories() {
- var temp = searchHistoryBox.values.toList().cast<SearchHistory>();
- temp.sort(
- (a, b) => b.timestamp - a.timestamp,
- );
+ final histories = _searchHistoryRepository.getAllHistories();
searchHistories.clear();
- searchHistories.addAll(temp);
+ searchHistories.addAll(histories);
}
/// Avaliable sort parameters:
@@ -56,22 +56,17 @@ abstract class _SearchPageController with Store {
Future<void> searchBangumi(String input, {String type = 'add'}) async {
if (type != 'add') {
bangumiList.clear();
- bool privateMode =
- await setting.get(SettingBoxKey.privateMode, defaultValue: false);
+ bool privateMode = _collectRepository.getPrivateMode();
if (!privateMode) {
- if (searchHistories.length >= 10) {
- await searchHistoryBox.delete(searchHistories.last.key);
+ // 检查是否已满,删除最旧的记录
+ if (_searchHistoryRepository.isHistoryFull(10)) {
+ await _searchHistoryRepository.deleteOldest();
}
- final historiesToDelete =
- searchHistories.where((element) => element.keyword == input);
- if (historiesToDelete.isNotEmpty) {
- for (var history in historiesToDelete) {
- await searchHistoryBox.delete(history.key);
- }
- }
- await searchHistoryBox.put(
- DateTime.now().millisecondsSinceEpoch.toString(),
- SearchHistory(input, DateTime.now().millisecondsSinceEpoch));
+ // 删除重复的历史记录
+ await _searchHistoryRepository.deleteDuplicates(input);
+ // 保存新的搜索历史
+ await _searchHistoryRepository.saveHistory(input);
+ // 重新加载历史记录
loadSearchHistories();
}
}
@@ -103,27 +98,33 @@ abstract class _SearchPageController with Store {
@action
Future<void> deleteSearchHistory(SearchHistory history) async {
- await searchHistoryBox.delete(history.key);
+ await _searchHistoryRepository.deleteHistory(history);
loadSearchHistories();
}
@action
Future<void> clearSearchHistory() async {
- await searchHistoryBox.clear();
+ await _searchHistoryRepository.clearAllHistories();
loadSearchHistories();
}
@action
Future<void> setNotShowWatchedBangumis(bool value) async {
notShowWatchedBangumis = value;
- await setting.put(SettingBoxKey.searchNotShowWatchedBangumis, value);
+ await _collectRepository.updateSearchNotShowWatchedBangumis(value);
}
@action
- Set<String> loadWatchedBangumiNames() {
- return collectiblesBox.values
- .where((item) => item.type == 4)
- .map((item) => item.bangumiItem.name.toString())
- .toSet();
+ Future<void> setNotShowAbandonedBangumis(bool value) async {
+ notShowAbandonedBangumis = value;
+ await _collectRepository.updateSearchNotShowAbandonedBangumis(value);
+ }
+
+ Set<int> loadWatchedBangumiIds() {
+ return _collectRepository.getBangumiIdsByType(CollectType.watched);
+ }
+
+ Set<int> loadAbandonedBangumiIds() {
+ return _collectRepository.getBangumiIdsByType(CollectType.abandoned);
}
}
diff --git a/lib/pages/search/search_controller.g.dart b/lib/pages/search/search_controller.g.dart
index a4670193..a5043434 100644
--- a/lib/pages/search/search_controller.g.dart
+++ b/lib/pages/search/search_controller.g.dart
@@ -64,6 +64,29 @@ mixin _$SearchPageController on _SearchPageController, Store {
});
}
+ late final _$notShowAbandonedBangumisAtom = Atom(
+ name: '_SearchPageController.notShowAbandonedBangumis', context: context);
+
+ @override
+ bool get notShowAbandonedBangumis {
+ _$notShowAbandonedBangumisAtom.reportRead();
+ return super.notShowAbandonedBangumis;
+ }
+
+ bool _notShowAbandonedBangumisIsInitialized = false;
+
+ @override
+ set notShowAbandonedBangumis(bool value) {
+ _$notShowAbandonedBangumisAtom.reportWrite(
+ value,
+ _notShowAbandonedBangumisIsInitialized
+ ? super.notShowAbandonedBangumis
+ : null, () {
+ super.notShowAbandonedBangumis = value;
+ _notShowAbandonedBangumisIsInitialized = true;
+ });
+ }
+
late final _$bangumiListAtom =
Atom(name: '_SearchPageController.bangumiList', context: context);
@@ -134,6 +157,16 @@ mixin _$SearchPageController on _SearchPageController, Store {
.run(() => super.setNotShowWatchedBangumis(value));
}
+ late final _$setNotShowAbandonedBangumisAsyncAction = AsyncAction(
+ '_SearchPageController.setNotShowAbandonedBangumis',
+ context: context);
+
+ @override
+ Future<void> setNotShowAbandonedBangumis(bool value) {
+ return _$setNotShowAbandonedBangumisAsyncAction
+ .run(() => super.setNotShowAbandonedBangumis(value));
+ }
+
late final _$_SearchPageControllerActionController =
ActionController(name: '_SearchPageController', context: context);
@@ -148,23 +181,13 @@ mixin _$SearchPageController on _SearchPageController, Store {
}
}
- @override
- Set<String> loadWatchedBangumiNames() {
- final _$actionInfo = _$_SearchPageControllerActionController.startAction(
- name: '_SearchPageController.loadWatchedBangumiNames');
- try {
- return super.loadWatchedBangumiNames();
- } finally {
- _$_SearchPageControllerActionController.endAction(_$actionInfo);
- }
- }
-
@override
String toString() {
return '''
isLoading: ${isLoading},
isTimeOut: ${isTimeOut},
notShowWatchedBangumis: ${notShowWatchedBangumis},
+notShowAbandonedBangumis: ${notShowAbandonedBangumis},
bangumiList: ${bangumiList},
searchHistories: ${searchHistories}
''';
diff --git a/lib/pages/search/search_page.dart b/lib/pages/search/search_page.dart
index e0571ee7..1e8b03f4 100644
--- a/lib/pages/search/search_page.dart
+++ b/lib/pages/search/search_page.dart
@@ -5,6 +5,7 @@ import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:kazumi/bean/widget/error_widget.dart';
import 'package:kazumi/pages/search/search_controller.dart';
import 'package:kazumi/bean/appbar/sys_app_bar.dart';
+import 'package:kazumi/modules/bangumi/bangumi_item.dart';
class SearchPage extends StatefulWidget {
const SearchPage({super.key, this.inputTag = ''});
@@ -23,8 +24,6 @@ class _SearchPageState extends State<SearchPage> {
final SearchPageController searchPageController = SearchPageController();
final ScrollController scrollController = ScrollController();
- late final Set<String> watchedBangumiNames;
-
final List<Tab> tabs = [
Tab(text: "排序方式"),
Tab(text: "过滤器"),
@@ -35,7 +34,6 @@ class _SearchPageState extends State<SearchPage> {
super.initState();
scrollController.addListener(scrollListener);
searchPageController.loadSearchHistories();
- watchedBangumiNames = searchPageController.loadWatchedBangumiNames();
}
@override
@@ -76,6 +74,23 @@ class _SearchPageState extends State<SearchPage> {
),
),
),
+ Observer(
+ builder: (context) => InkWell(
+ onTap: () {
+ searchPageController.setNotShowAbandonedBangumis(
+ !searchPageController.notShowAbandonedBangumis);
+ },
+ child: ListTile(
+ title: const Text('不显示已抛弃的番剧'),
+ trailing: Switch(
+ value: searchPageController.notShowAbandonedBangumis,
+ onChanged: (value) {
+ searchPageController.setNotShowAbandonedBangumis(value);
+ },
+ ),
+ ),
+ ),
+ ),
],
);
}
@@ -291,11 +306,21 @@ class _SearchPageState extends State<SearchPage> {
LayoutBreakpoint.medium['width']!) {
crossCount = 6;
}
- final filteredList = searchPageController.notShowWatchedBangumis
- ? searchPageController.bangumiList
- .where((item) => !watchedBangumiNames.contains(item.name))
- .toList()
- : searchPageController.bangumiList;
+ List<BangumiItem> filteredList = searchPageController.bangumiList.toList();
+
+ if (searchPageController.notShowWatchedBangumis) {
+ final watchedBangumiIds = searchPageController.loadWatchedBangumiIds();
+ filteredList = filteredList
+ .where((item) => !watchedBangumiIds.contains(item.id))
+ .toList();
+ }
+
+ if (searchPageController.notShowAbandonedBangumis) {
+ final abandonedBangumiIds = searchPageController.loadAbandonedBangumiIds();
+ filteredList = filteredList
+ .where((item) => !abandonedBangumiIds.contains(item.id))
+ .toList();
+ }
return GridView.builder(
controller: scrollController,
diff --git a/lib/pages/timeline/timeline_controller.dart b/lib/pages/timeline/timeline_controller.dart
index adb56854..52f8da2e 100644
--- a/lib/pages/timeline/timeline_controller.dart
+++ b/lib/pages/timeline/timeline_controller.dart
@@ -1,6 +1,9 @@
+import 'package:flutter_modular/flutter_modular.dart';
import 'package:kazumi/modules/bangumi/bangumi_item.dart';
import 'package:kazumi/request/bangumi.dart';
import 'package:kazumi/utils/anime_season.dart';
+import 'package:kazumi/repositories/collect_repository.dart';
+import 'package:kazumi/modules/collect/collect_type.dart';
import 'package:mobx/mobx.dart';
part 'timeline_controller.g.dart';
@@ -8,6 +11,8 @@ part 'timeline_controller.g.dart';
class TimelineController = _TimelineController with _$TimelineController;
abstract class _TimelineController with Store {
+ final _collectRepository = Modular.get<ICollectRepository>();
+
@observable
ObservableList<List<BangumiItem>> bangumiCalendar =
ObservableList<List<BangumiItem>>();
@@ -21,6 +26,12 @@ abstract class _TimelineController with Store {
@observable
bool isTimeOut = false;
+ @observable
+ late bool notShowAbandonedBangumis = _collectRepository.getTimelineNotShowAbandonedBangumis();
+
+ @observable
+ late bool notShowWatchedBangumis = _collectRepository.getTimelineNotShowWatchedBangumis();
+
int sortType = 1;
late DateTime selectedDate;
@@ -105,4 +116,24 @@ abstract class _TimelineController with Store {
bangumiCalendar.clear();
bangumiCalendar.addAll(resBangumiCalendar);
}
+
+ @action
+ Future<void> setNotShowAbandonedBangumis(bool value) async {
+ notShowAbandonedBangumis = value;
+ await _collectRepository.updateTimelineNotShowAbandonedBangumis(value);
+ }
+
+ @action
+ Future<void> setNotShowWatchedBangumis(bool value) async {
+ notShowWatchedBangumis = value;
+ await _collectRepository.updateTimelineNotShowWatchedBangumis(value);
+ }
+
+ Set<int> loadAbandonedBangumiIds() {
+ return _collectRepository.getBangumiIdsByType(CollectType.abandoned);
+ }
+
+ Set<int> loadWatchedBangumiIds() {
+ return _collectRepository.getBangumiIdsByType(CollectType.watched);
+ }
}
diff --git a/lib/pages/timeline/timeline_controller.g.dart b/lib/pages/timeline/timeline_controller.g.dart
index 523111d8..90b6d615 100644
--- a/lib/pages/timeline/timeline_controller.g.dart
+++ b/lib/pages/timeline/timeline_controller.g.dart
@@ -73,13 +73,81 @@ mixin _$TimelineController on _TimelineController, Store {
});
}
+ late final _$notShowAbandonedBangumisAtom = Atom(
+ name: '_TimelineController.notShowAbandonedBangumis', context: context);
+
+ @override
+ bool get notShowAbandonedBangumis {
+ _$notShowAbandonedBangumisAtom.reportRead();
+ return super.notShowAbandonedBangumis;
+ }
+
+ bool _notShowAbandonedBangumisIsInitialized = false;
+
+ @override
+ set notShowAbandonedBangumis(bool value) {
+ _$notShowAbandonedBangumisAtom.reportWrite(
+ value,
+ _notShowAbandonedBangumisIsInitialized
+ ? super.notShowAbandonedBangumis
+ : null, () {
+ super.notShowAbandonedBangumis = value;
+ _notShowAbandonedBangumisIsInitialized = true;
+ });
+ }
+
+ late final _$notShowWatchedBangumisAtom = Atom(
+ name: '_TimelineController.notShowWatchedBangumis', context: context);
+
+ @override
+ bool get notShowWatchedBangumis {
+ _$notShowWatchedBangumisAtom.reportRead();
+ return super.notShowWatchedBangumis;
+ }
+
+ bool _notShowWatchedBangumisIsInitialized = false;
+
+ @override
+ set notShowWatchedBangumis(bool value) {
+ _$notShowWatchedBangumisAtom.reportWrite(
+ value,
+ _notShowWatchedBangumisIsInitialized
+ ? super.notShowWatchedBangumis
+ : null, () {
+ super.notShowWatchedBangumis = value;
+ _notShowWatchedBangumisIsInitialized = true;
+ });
+ }
+
+ late final _$setNotShowAbandonedBangumisAsyncAction = AsyncAction(
+ '_TimelineController.setNotShowAbandonedBangumis',
+ context: context);
+
+ @override
+ Future<void> setNotShowAbandonedBangumis(bool value) {
+ return _$setNotShowAbandonedBangumisAsyncAction
+ .run(() => super.setNotShowAbandonedBangumis(value));
+ }
+
+ late final _$setNotShowWatchedBangumisAsyncAction = AsyncAction(
+ '_TimelineController.setNotShowWatchedBangumis',
+ context: context);
+
+ @override
+ Future<void> setNotShowWatchedBangumis(bool value) {
+ return _$setNotShowWatchedBangumisAsyncAction
+ .run(() => super.setNotShowWatchedBangumis(value));
+ }
+
@override
String toString() {
return '''
bangumiCalendar: ${bangumiCalendar},
seasonString: ${seasonString},
isLoading: ${isLoading},
-isTimeOut: ${isTimeOut}
+isTimeOut: ${isTimeOut},
+notShowAbandonedBangumis: ${notShowAbandonedBangumis},
+notShowWatchedBangumis: ${notShowWatchedBangumis}
''';
}
}
diff --git a/lib/pages/timeline/timeline_page.dart b/lib/pages/timeline/timeline_page.dart
index 74c26721..960525a8 100644
--- a/lib/pages/timeline/timeline_page.dart
+++ b/lib/pages/timeline/timeline_page.dart
@@ -27,6 +27,11 @@ class _TimelinePageState extends State<TimelinePage>
late NavigationBarState navigationBarState;
TabController? tabController;
+ final List<Tab> optionTabs = [
+ Tab(text: "排序方式"),
+ Tab(text: "过滤器"),
+ ];
+
@override
void initState() {
super.initState();
@@ -319,45 +324,102 @@ class _TimelinePageState extends State<TimelinePage>
AnimeSeason(timelineController.selectedDate).toString();
}
- void showSortSwitcher() {
- KazumiDialog.showBottomSheet(
- // context: context,
- isScrollControlled: true,
- builder: (context) {
- return Wrap(
+ Widget showFilterSwitcher() {
+ return Wrap(
+ children: [
+ Observer(
+ builder: (context) => InkWell(
+ onTap: () {
+ timelineController.setNotShowAbandonedBangumis(
+ !timelineController.notShowAbandonedBangumis);
+ },
+ child: ListTile(
+ title: const Text('不显示已抛弃的番剧'),
+ trailing: Switch(
+ value: timelineController.notShowAbandonedBangumis,
+ onChanged: (value) {
+ timelineController.setNotShowAbandonedBangumis(value);
+ },
+ ),
+ ),
+ ),
+ ),
+ Observer(
+ builder: (context) => InkWell(
+ onTap: () {
+ timelineController.setNotShowWatchedBangumis(
+ !timelineController.notShowWatchedBangumis);
+ },
+ child: ListTile(
+ title: const Text('不显示已看过的番剧'),
+ trailing: Switch(
+ value: timelineController.notShowWatchedBangumis,
+ onChanged: (value) {
+ timelineController.setNotShowWatchedBangumis(value);
+ },
+ ),
+ ),
+ ),
+ ),
+ ],
+ );
+ }
+
+ Widget showSortSwitcher() {
+ return Wrap(
+ children: [
+ Column(
+ mainAxisSize: MainAxisSize.min,
children: [
- Column(
- mainAxisSize: MainAxisSize.min,
- children: [
- ListTile(
- title: const Text('按热度排序'),
- onTap: () {
- Navigator.pop(context);
- timelineController.changeSortType(3);
- },
- ),
- ListTile(
- title: const Text('按评分排序'),
- onTap: () {
- Navigator.pop(context);
- timelineController.changeSortType(2);
- },
- ),
- ListTile(
- title: const Text('按时间排序'),
- onTap: () {
- Navigator.pop(context);
- timelineController.changeSortType(1);
- },
- ),
- ],
+ ListTile(
+ title: const Text('按热度排序'),
+ onTap: () {
+ Navigator.pop(context);
+ timelineController.changeSortType(3);
+ },
+ ),
+ ListTile(
+ title: const Text('按评分排序'),
+ onTap: () {
+ Navigator.pop(context);
+ timelineController.changeSortType(2);
+ },
+ ),
+ ListTile(
+ title: const Text('按时间排序'),
+ onTap: () {
+ Navigator.pop(context);
+ timelineController.changeSortType(1);
+ },
),
],
- );
- },
+ ),
+ ],
);
}
+ Widget showTimelineOptionTabBar({required List<Widget> options}) {
+ return DefaultTabController(
+ length: optionTabs.length,
+ child: Scaffold(
+ body: Column(
+ children: [
+ PreferredSize(
+ preferredSize: Size.fromHeight(kToolbarHeight),
+ child: Material(
+ child: TabBar(
+ tabs: optionTabs,
+ ),
+ ),
+ ),
+ Expanded(
+ child: TabBarView(
+ children: options,
+ ))
+ ],
+ )));
+ }
+
@override
Widget build(BuildContext context) {
return PopScope(
@@ -388,11 +450,30 @@ class _TimelinePageState extends State<TimelinePage>
),
),
floatingActionButton: FloatingActionButton.extended(
- onPressed: () {
- showSortSwitcher();
+ onPressed: () async {
+ showModalBottomSheet(
+ isScrollControlled: true,
+ constraints: BoxConstraints(
+ maxHeight: (MediaQuery.sizeOf(context).height >=
+ LayoutBreakpoint.compact['height']!)
+ ? MediaQuery.of(context).size.height * 1 / 4
+ : MediaQuery.of(context).size.height,
+ maxWidth: (MediaQuery.sizeOf(context).width >=
+ LayoutBreakpoint.medium['width']!)
+ ? MediaQuery.of(context).size.width * 9 / 16
+ : MediaQuery.of(context).size.width,
+ ),
+ clipBehavior: Clip.antiAlias,
+ backgroundColor: Theme.of(context).scaffoldBackgroundColor,
+ context: context,
+ builder: (context) {
+ return showTimelineOptionTabBar(
+ options: [showSortSwitcher(), showFilterSwitcher()]);
+ },
+ );
},
icon: const Icon(Icons.sort),
- label: const Text("排序方式"),
+ label: const Text("时间表设置"),
),
body: Observer(builder: (context) {
if (timelineController.isLoading &&
@@ -437,6 +518,23 @@ class _TimelinePageState extends State<TimelinePage>
double cardHeight =
Utils.isDesktop() ? 160 : (Utils.isTablet() ? 140 : 120);
for (var bangumiList in bangumiCalendar) {
+ // 根据过滤器设置过滤番剧
+ var filteredList = bangumiList;
+
+ if (timelineController.notShowAbandonedBangumis) {
+ final abandonedBangumiIds = timelineController.loadAbandonedBangumiIds();
+ filteredList = filteredList
+ .where((item) => !abandonedBangumiIds.contains(item.id))
+ .toList();
+ }
+
+ if (timelineController.notShowWatchedBangumis) {
+ final watchedBangumiIds = timelineController.loadWatchedBangumiIds();
+ filteredList = filteredList
+ .where((item) => !watchedBangumiIds.contains(item.id))
+ .toList();
+ }
+
gridViewList.add(
CustomScrollView(
slivers: [
@@ -449,12 +547,12 @@ class _TimelinePageState extends State<TimelinePage>
),
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
- if (bangumiList.isEmpty) return null;
- final item = bangumiList[index];
+ if (filteredList.isEmpty) return null;
+ final item = filteredList[index];
return BangumiTimelineCard(
bangumiItem: item, cardHeight: cardHeight);
},
- childCount: bangumiList.isNotEmpty ? bangumiList.length : 10,
+ childCount: filteredList.isNotEmpty ? filteredList.length : 10,
),
),
],
diff --git a/lib/repositories/collect_crud_repository.dart b/lib/repositories/collect_crud_repository.dart
new file mode 100644
index 00000000..f1bed217
--- /dev/null
+++ b/lib/repositories/collect_crud_repository.dart
@@ -0,0 +1,217 @@
+import 'package:kazumi/utils/storage.dart';
+import 'package:kazumi/modules/bangumi/bangumi_item.dart';
+import 'package:kazumi/modules/collect/collect_module.dart';
+import 'package:kazumi/modules/collect/collect_change_module.dart';
+import 'package:kazumi/utils/logger.dart';
+import 'package:logger/logger.dart';
+
+/// 收藏CRUD数据访问接口
+///
+/// 提供收藏数据的增删改查操作
+abstract class ICollectCrudRepository {
+ /// 获取所有收藏
+ List<CollectedBangumi> getAllCollectibles();
+
+ /// 获取单个收藏
+ ///
+ /// [id] 番剧ID
+ /// 返回收藏对象,如果不存在返回null
+ CollectedBangumi? getCollectible(int id);
+
+ /// 获取收藏类型
+ ///
+ /// [id] 番剧ID
+ /// 返回收藏类型值,未收藏返回0
+ int getCollectType(int id);
+
+ /// 添加或更新收藏
+ ///
+ /// [bangumiItem] 番剧信息
+ /// [type] 收藏类型
+ Future<void> addCollectible(BangumiItem bangumiItem, int type);
+
+ /// 更新收藏的番剧信息
+ ///
+ /// [bangumiItem] 更新后的番剧信息
+ Future<void> updateCollectible(BangumiItem bangumiItem);
+
+ /// 删除收藏
+ ///
+ /// [id] 番剧ID
+ Future<void> deleteCollectible(int id);
+
+ /// 记录收藏变更(用于WebDAV同步)
+ ///
+ /// [change] 变更记录
+ Future<void> addCollectChange(CollectedBangumiChange change);
+
+ /// 获取旧版收藏列表(用于迁移)
+ List<BangumiItem> getFavorites();
+
+ /// 清空旧版收藏(迁移后)
+ Future<void> clearFavorites();
+}
+
+/// 收藏CRUD数据访问实现类
+///
+/// 基于Hive实现的收藏CRUD数据访问层
+class CollectCrudRepository implements ICollectCrudRepository {
+ final _collectiblesBox = GStorage.collectibles;
+ final _collectChangesBox = GStorage.collectChanges;
+ final _favoritesBox = GStorage.favorites;
+
+ @override
+ List<CollectedBangumi> getAllCollectibles() {
+ try {
+ return _collectiblesBox.values.cast<CollectedBangumi>().toList();
+ } catch (e, stackTrace) {
+ KazumiLogger().log(
+ Level.warning,
+ '获取所有收藏失败',
+ error: e,
+ stackTrace: stackTrace,
+ );
+ return [];
+ }
+ }
+
+ @override
+ CollectedBangumi? getCollectible(int id) {
+ try {
+ return _collectiblesBox.get(id);
+ } catch (e, stackTrace) {
+ KazumiLogger().log(
+ Level.warning,
+ '获取收藏失败: id=$id',
+ error: e,
+ stackTrace: stackTrace,
+ );
+ return null;
+ }
+ }
+
+ @override
+ int getCollectType(int id) {
+ try {
+ final collectible = _collectiblesBox.get(id);
+ return collectible?.type ?? 0;
+ } catch (e, stackTrace) {
+ KazumiLogger().log(
+ Level.warning,
+ '获取收藏类型失败: id=$id',
+ error: e,
+ stackTrace: stackTrace,
+ );
+ return 0;
+ }
+ }
+
+ @override
+ Future<void> addCollectible(BangumiItem bangumiItem, int type) async {
+ try {
+ final collectedBangumi = CollectedBangumi(
+ bangumiItem,
+ DateTime.now(),
+ type,
+ );
+ await _collectiblesBox.put(bangumiItem.id, collectedBangumi);
+ await _collectiblesBox.flush();
+ } catch (e, stackTrace) {
+ KazumiLogger().log(
+ Level.error,
+ '添加收藏失败: id=${bangumiItem.id}, type=$type',
+ error: e,
+ stackTrace: stackTrace,
+ );
+ rethrow;
+ }
+ }
+
+ @override
+ Future<void> updateCollectible(BangumiItem bangumiItem) async {
+ try {
+ final collectible = _collectiblesBox.get(bangumiItem.id);
+ if (collectible == null) {
+ KazumiLogger().log(
+ Level.warning,
+ '更新收藏失败: 收藏不存在, id=${bangumiItem.id}',
+ );
+ return;
+ }
+ collectible.bangumiItem = bangumiItem;
+ await _collectiblesBox.put(bangumiItem.id, collectible);
+ await _collectiblesBox.flush();
+ } catch (e, stackTrace) {
+ KazumiLogger().log(
+ Level.error,
+ '更新收藏失败: id=${bangumiItem.id}',
+ error: e,
+ stackTrace: stackTrace,
+ );
+ rethrow;
+ }
+ }
+
+ @override
+ Future<void> deleteCollectible(int id) async {
+ try {
+ await _collectiblesBox.delete(id);
+ await _collectiblesBox.flush();
+ } catch (e, stackTrace) {
+ KazumiLogger().log(
+ Level.error,
+ '删除收藏失败: id=$id',
+ error: e,
+ stackTrace: stackTrace,
+ );
+ rethrow;
+ }
+ }
+
+ @override
+ Future<void> addCollectChange(CollectedBangumiChange change) async {
+ try {
+ await _collectChangesBox.put(change.id, change);
+ await _collectChangesBox.flush();
+ } catch (e, stackTrace) {
+ KazumiLogger().log(
+ Level.error,
+ '记录收藏变更失败: changeId=${change.id}',
+ error: e,
+ stackTrace: stackTrace,
+ );
+ rethrow;
+ }
+ }
+
+ @override
+ List<BangumiItem> getFavorites() {
+ try {
+ return _favoritesBox.values.cast<BangumiItem>().toList();
+ } catch (e, stackTrace) {
+ KazumiLogger().log(
+ Level.warning,
+ '获取旧版收藏失败',
+ error: e,
+ stackTrace: stackTrace,
+ );
+ return [];
+ }
+ }
+
+ @override
+ Future<void> clearFavorites() async {
+ try {
+ await _favoritesBox.clear();
+ await _favoritesBox.flush();
+ } catch (e, stackTrace) {
+ KazumiLogger().log(
+ Level.error,
+ '清空旧版收藏失败',
+ error: e,
+ stackTrace: stackTrace,
+ );
+ rethrow;
+ }
+ }
+}
diff --git a/lib/repositories/collect_repository.dart b/lib/repositories/collect_repository.dart
new file mode 100644
index 00000000..6fbdbbbf
--- /dev/null
+++ b/lib/repositories/collect_repository.dart
@@ -0,0 +1,256 @@
+import 'package:kazumi/utils/storage.dart';
+import 'package:kazumi/modules/collect/collect_type.dart';
+import 'package:kazumi/utils/logger.dart';
+import 'package:logger/logger.dart';
+
+/// 收藏数据访问接口
+///
+/// 提供收藏相关的数据访问抽象,解耦业务逻辑与数据存储
+abstract class ICollectRepository {
+ /// 根据收藏类型获取番剧ID集合
+ ///
+ /// [type] 收藏类型
+ /// 返回符合条件的番剧ID集合
+ Set<int> getBangumiIdsByType(CollectType type);
+
+ /// 批量获取多种类型的番剧ID集合
+ ///
+ /// [types] 收藏类型列表
+ /// 返回符合条件的番剧ID集合(并集)
+ Set<int> getBangumiIdsByTypes(List<CollectType> types);
+
+ // ========== 搜索页过滤器设置 ==========
+
+ /// 获取搜索页"不显示已看过番剧"设置
+ bool getSearchNotShowWatchedBangumis();
+
+ /// 更新搜索页"不显示已看过番剧"设置
+ Future<void> updateSearchNotShowWatchedBangumis(bool value);
+
+ /// 获取搜索页"不显示已抛弃番剧"设置
+ bool getSearchNotShowAbandonedBangumis();
+
+ /// 更新搜索页"不显示已抛弃番剧"设置
+ Future<void> updateSearchNotShowAbandonedBangumis(bool value);
+
+ // ========== 时间表页过滤器设置 ==========
+
+ /// 获取时间表页"不显示已抛弃番剧"设置
+ bool getTimelineNotShowAbandonedBangumis();
+
+ /// 更新时间表页"不显示已抛弃番剧"设置
+ Future<void> updateTimelineNotShowAbandonedBangumis(bool value);
+
+ /// 获取时间表页"不显示已看过番剧"设置
+ bool getTimelineNotShowWatchedBangumis();
+
+ /// 更新时间表页"不显示已看过番剧"设置
+ Future<void> updateTimelineNotShowWatchedBangumis(bool value);
+
+ // ========== 其他设置 ==========
+
+ /// 获取隐私模式设置
+ bool getPrivateMode();
+}
+
+/// 收藏数据访问实现类
+///
+/// 基于Hive实现的收藏数据访问层
+class CollectRepository implements ICollectRepository {
+ final _collectiblesBox = GStorage.collectibles;
+ final _settingBox = GStorage.setting;
+
+ @override
+ Set<int> getBangumiIdsByType(CollectType type) {
+ try {
+ return _collectiblesBox.values
+ .where((item) => item.type == type.value)
+ .map<int>((item) => item.bangumiItem.id)
+ .toSet();
+ } catch (e, stackTrace) {
+ KazumiLogger().log(
+ Level.warning,
+ '获取收藏番剧ID失败: type=${type.label}',
+ error: e,
+ stackTrace: stackTrace,
+ );
+ return <int>{};
+ }
+ }
+
+ @override
+ Set<int> getBangumiIdsByTypes(List<CollectType> types) {
+ try {
+ final typeValues = types.map((t) => t.value).toSet();
+ return _collectiblesBox.values
+ .where((item) => typeValues.contains(item.type))
+ .map<int>((item) => item.bangumiItem.id)
+ .toSet();
+ } catch (e, stackTrace) {
+ KazumiLogger().log(
+ Level.warning,
+ '批量获取收藏番剧ID失败: types=${types.map((t) => t.label).join(", ")}',
+ error: e,
+ stackTrace: stackTrace,
+ );
+ return <int>{};
+ }
+ }
+
+ // ========== 搜索页过滤器设置实现 ==========
+
+ @override
+ bool getSearchNotShowWatchedBangumis() {
+ try {
+ final value = _settingBox.get(
+ SettingBoxKey.searchNotShowWatchedBangumis,
+ defaultValue: false,
+ );
+ return value is bool ? value : false;
+ } catch (e, stackTrace) {
+ KazumiLogger().log(
+ Level.warning,
+ '获取搜索页"不显示已看过"设置失败,使用默认值false',
+ error: e,
+ stackTrace: stackTrace,
+ );
+ return false;
+ }
+ }
+
+ @override
+ Future<void> updateSearchNotShowWatchedBangumis(bool value) async {
+ try {
+ await _settingBox.put(SettingBoxKey.searchNotShowWatchedBangumis, value);
+ } catch (e, stackTrace) {
+ KazumiLogger().log(
+ Level.error,
+ '更新搜索页"不显示已看过"设置失败: value=$value',
+ error: e,
+ stackTrace: stackTrace,
+ );
+ }
+ }
+
+ @override
+ bool getSearchNotShowAbandonedBangumis() {
+ try {
+ final value = _settingBox.get(
+ SettingBoxKey.searchNotShowAbandonedBangumis,
+ defaultValue: false,
+ );
+ return value is bool ? value : false;
+ } catch (e, stackTrace) {
+ KazumiLogger().log(
+ Level.warning,
+ '获取搜索页"不显示已抛弃"设置失败,使用默认值false',
+ error: e,
+ stackTrace: stackTrace,
+ );
+ return false;
+ }
+ }
+
+ @override
+ Future<void> updateSearchNotShowAbandonedBangumis(bool value) async {
+ try {
+ await _settingBox.put(SettingBoxKey.searchNotShowAbandonedBangumis, value);
+ } catch (e, stackTrace) {
+ KazumiLogger().log(
+ Level.error,
+ '更新搜索页"不显示已抛弃"设置失败: value=$value',
+ error: e,
+ stackTrace: stackTrace,
+ );
+ }
+ }
+
+ // ========== 时间表页过滤器设置实现 ==========
+
+ @override
+ bool getTimelineNotShowAbandonedBangumis() {
+ try {
+ final value = _settingBox.get(
+ SettingBoxKey.timelineNotShowAbandonedBangumis,
+ defaultValue: false,
+ );
+ return value is bool ? value : false;
+ } catch (e, stackTrace) {
+ KazumiLogger().log(
+ Level.warning,
+ '获取时间表页"不显示已抛弃"设置失败,使用默认值false',
+ error: e,
+ stackTrace: stackTrace,
+ );
+ return false;
+ }
+ }
+
+ @override
+ Future<void> updateTimelineNotShowAbandonedBangumis(bool value) async {
+ try {
+ await _settingBox.put(SettingBoxKey.timelineNotShowAbandonedBangumis, value);
+ } catch (e, stackTrace) {
+ KazumiLogger().log(
+ Level.error,
+ '更新时间表页"不显示已抛弃"设置失败: value=$value',
+ error: e,
+ stackTrace: stackTrace,
+ );
+ }
+ }
+
+ @override
+ bool getTimelineNotShowWatchedBangumis() {
+ try {
+ final value = _settingBox.get(
+ SettingBoxKey.timelineNotShowWatchedBangumis,
+ defaultValue: false,
+ );
+ return value is bool ? value : false;
+ } catch (e, stackTrace) {
+ KazumiLogger().log(
+ Level.warning,
+ '获取时间表页"不显示已看过"设置失败,使用默认值false',
+ error: e,
+ stackTrace: stackTrace,
+ );
+ return false;
+ }
+ }
+
+ @override
+ Future<void> updateTimelineNotShowWatchedBangumis(bool value) async {
+ try {
+ await _settingBox.put(SettingBoxKey.timelineNotShowWatchedBangumis, value);
+ } catch (e, stackTrace) {
+ KazumiLogger().log(
+ Level.error,
+ '更新时间表页"不显示已看过"设置失败: value=$value',
+ error: e,
+ stackTrace: stackTrace,
+ );
+ }
+ }
+
+ // ========== 其他设置实现 ==========
+
+ @override
+ bool getPrivateMode() {
+ try {
+ final value = _settingBox.get(
+ SettingBoxKey.privateMode,
+ defaultValue: false,
+ );
+ return value is bool ? value : false;
+ } catch (e, stackTrace) {
+ KazumiLogger().log(
+ Level.warning,
+ '获取隐私模式设置失败,使用默认值false',
+ error: e,
+ stackTrace: stackTrace,
+ );
+ return false;
+ }
+ }
+}
diff --git a/lib/repositories/search_history_repository.dart b/lib/repositories/search_history_repository.dart
new file mode 100644
index 00000000..20a3e246
--- /dev/null
+++ b/lib/repositories/search_history_repository.dart
@@ -0,0 +1,160 @@
+import 'package:kazumi/utils/storage.dart';
+import 'package:kazumi/modules/search/search_history_module.dart';
+import 'package:kazumi/utils/logger.dart';
+import 'package:logger/logger.dart';
+
+/// 搜索历史数据访问接口
+///
+/// 提供搜索历史相关的数据访问抽象
+abstract class ISearchHistoryRepository {
+ /// 获取所有搜索历史(按时间戳倒序)
+ List<SearchHistory> getAllHistories();
+
+ /// 保存搜索历史
+ ///
+ /// [keyword] 搜索关键词
+ /// 返回是否成功
+ Future<bool> saveHistory(String keyword);
+
+ /// 删除指定搜索历史
+ ///
+ /// [history] 要删除的历史记录
+ Future<void> deleteHistory(SearchHistory history);
+
+ /// 清空所有搜索历史
+ Future<void> clearAllHistories();
+
+ /// 删除重复的历史记录
+ ///
+ /// [keyword] 关键词
+ Future<void> deleteDuplicates(String keyword);
+
+ /// 检查是否达到最大历史记录数
+ ///
+ /// [maxCount] 最大记录数
+ /// 返回是否已满
+ bool isHistoryFull(int maxCount);
+
+ /// 删除最旧的历史记录
+ Future<void> deleteOldest();
+}
+
+/// 搜索历史数据访问实现类
+///
+/// 基于Hive实现的搜索历史数据访问层
+class SearchHistoryRepository implements ISearchHistoryRepository {
+ final _searchHistoryBox = GStorage.searchHistory;
+
+ @override
+ List<SearchHistory> getAllHistories() {
+ try {
+ final histories = _searchHistoryBox.values.toList().cast<SearchHistory>();
+ histories.sort((a, b) => b.timestamp - a.timestamp);
+ return histories;
+ } catch (e, stackTrace) {
+ KazumiLogger().log(
+ Level.warning,
+ '获取搜索历史失败',
+ error: e,
+ stackTrace: stackTrace,
+ );
+ return [];
+ }
+ }
+
+ @override
+ Future<bool> saveHistory(String keyword) async {
+ try {
+ final timestamp = DateTime.now().millisecondsSinceEpoch;
+ final history = SearchHistory(keyword, timestamp);
+ await _searchHistoryBox.put(timestamp.toString(), history);
+ return true;
+ } catch (e, stackTrace) {
+ KazumiLogger().log(
+ Level.error,
+ '保存搜索历史失败: keyword=$keyword',
+ error: e,
+ stackTrace: stackTrace,
+ );
+ return false;
+ }
+ }
+
+ @override
+ Future<void> deleteHistory(SearchHistory history) async {
+ try {
+ await _searchHistoryBox.delete(history.key);
+ } catch (e, stackTrace) {
+ KazumiLogger().log(
+ Level.error,
+ '删除搜索历史失败: key=${history.key}',
+ error: e,
+ stackTrace: stackTrace,
+ );
+ }
+ }
+
+ @override
+ Future<void> clearAllHistories() async {
+ try {
+ await _searchHistoryBox.clear();
+ } catch (e, stackTrace) {
+ KazumiLogger().log(
+ Level.error,
+ '清空搜索历史失败',
+ error: e,
+ stackTrace: stackTrace,
+ );
+ }
+ }
+
+ @override
+ Future<void> deleteDuplicates(String keyword) async {
+ try {
+ final histories = getAllHistories();
+ final duplicates = histories.where((h) => h.keyword == keyword);
+ for (var history in duplicates) {
+ await deleteHistory(history);
+ }
+ } catch (e, stackTrace) {
+ KazumiLogger().log(
+ Level.warning,
+ '删除重复搜索历史失败: keyword=$keyword',
+ error: e,
+ stackTrace: stackTrace,
+ );
+ }
+ }
+
+ @override
+ bool isHistoryFull(int maxCount) {
+ try {
+ return _searchHistoryBox.length >= maxCount;
+ } catch (e, stackTrace) {
+ KazumiLogger().log(
+ Level.warning,
+ '检查搜索历史数量失败',
+ error: e,
+ stackTrace: stackTrace,
+ );
+ return false;
+ }
+ }
+
+ @override
+ Future<void> deleteOldest() async {
+ try {
+ final histories = getAllHistories();
+ if (histories.isNotEmpty) {
+ await deleteHistory(histories.last);
+ }
+ } catch (e, stackTrace) {
+ KazumiLogger().log(
+ Level.warning,
+ '删除最旧搜索历史失败',
+ error: e,
+ stackTrace: stackTrace,
+ );
+ }
+ }
+}
diff --git a/lib/utils/storage.dart b/lib/utils/storage.dart
index c934d3ca..1ecb51ee 100644
--- a/lib/utils/storage.dart
+++ b/lib/utils/storage.dart
@@ -259,5 +259,8 @@ class SettingBoxKey {
superResolutionWarn = 'superResolutionWarn',
playerDisableAnimations = 'playerDisableAnimations',
playerLogLevel = 'playerLogLevel',
- searchNotShowWatchedBangumis = 'searchNotShowWatchedBangumis';
+ searchNotShowWatchedBangumis = 'searchNotShowWatchedBangumis',
+ searchNotShowAbandonedBangumis = 'searchNotShowAbandonedBangumis',
+ timelineNotShowAbandonedBangumis = 'timelineNotShowAbandonedBangumis',
+ timelineNotShowWatchedBangumis = 'timelineNotShowWatchedBangumis';
}