From 88f093f7e50ef31f14922dac0a86665356cf2d21 Mon Sep 17 00:00:00 2001 From: nyne Date: Thu, 22 May 2025 19:59:42 +0800 Subject: [PATCH] Add clear unfavorited history functionality. Close #372 --- assets/translation.json | 8 +++++--- lib/foundation/history.dart | 17 +++++++++++++++++ lib/pages/history_page.dart | 7 +++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/assets/translation.json b/assets/translation.json index be1e7b4..9bb2ea3 100644 --- a/assets/translation.json +++ b/assets/translation.json @@ -391,7 +391,8 @@ "Click to select an image": "点击选择一张图片", "Source URL": "源地址", "The URL should point to a 'index.json' file": "该URL应指向一个'index.json'文件", - "Double tap to zoom": "双击缩放" + "Double tap to zoom": "双击缩放", + "Clear Unfavorited": "清除未收藏" }, "zh_TW": { "Home": "首頁", @@ -785,6 +786,7 @@ "Click to select an image": "點擊選擇一張圖片", "Source URL": "源地址", "The URL should point to a 'index.json' file": "該URL應指向一個'index.json'文件", - "Double tap to zoom": "雙擊縮放" + "Double tap to zoom": "雙擊縮放", + "Clear Unfavorited": "清除未收藏" } -} +} \ No newline at end of file diff --git a/lib/foundation/history.dart b/lib/foundation/history.dart index 0c017cf..3c45c89 100644 --- a/lib/foundation/history.dart +++ b/lib/foundation/history.dart @@ -10,6 +10,7 @@ import 'package:flutter/widgets.dart' show ChangeNotifier; import 'package:sqlite3/sqlite3.dart'; import 'package:venera/foundation/comic_source/comic_source.dart'; import 'package:venera/foundation/comic_type.dart'; +import 'package:venera/foundation/favorites.dart'; import 'package:venera/foundation/image_provider/image_favorites_provider.dart'; import 'package:venera/foundation/log.dart'; import 'package:venera/utils/ext.dart'; @@ -305,6 +306,22 @@ class HistoryManager with ChangeNotifier { notifyListeners(); } + void clearUnfavoritedHistory() { + final idAndTypes = _db.select(""" + select id, type from history; + """); + for (var element in idAndTypes) { + final id = element["id"] as String; + final type = ComicType(element["type"] as int); + if (!LocalFavoritesManager().isExist(id, type)) { + _db.execute(""" + delete from history + where id == ? and type == ?; + """, [id, type.value]); + } + } + } + void remove(String id, ComicType type) async { _db.execute(""" delete from history diff --git a/lib/pages/history_page.dart b/lib/pages/history_page.dart index 049021e..9a631cf 100644 --- a/lib/pages/history_page.dart +++ b/lib/pages/history_page.dart @@ -140,6 +140,13 @@ class _HistoryPageState extends State { title: 'Clear History'.tl, content: Text('Are you sure you want to clear your history?'.tl), actions: [ + Button.outlined( + onPressed: () { + HistoryManager().clearUnfavoritedHistory(); + context.pop(); + }, + child: Text('Clear Unfavorited'.tl), + ), Button.filled( color: context.colorScheme.error, onPressed: () {