From 01acc4f9debca58dfa323c9fa221462a688687f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A7=92=E7=A0=82=E7=B3=96?= <90336521+lings03@users.noreply.github.com> Date: Sun, 22 Jun 2025 19:49:09 +0800 Subject: [PATCH] Allow user to keep favorite and history when delete local comic. Close #420 --- assets/translation.json | 2 ++ lib/foundation/local.dart | 9 ++++++--- lib/pages/local_comics_page.dart | 31 +++++++++++++++++++++++-------- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/assets/translation.json b/assets/translation.json index 8f8ef7c..e811b68 100644 --- a/assets/translation.json +++ b/assets/translation.json @@ -236,6 +236,7 @@ "No Category Pages": "没有分类页面", "Chapter @ep": "第 @ep 章", "Page @page": "第 @page 页", + "Remove local favorite and history": "删除本地收藏和历史记录", "Also remove files on disk": "同时删除磁盘上的文件", "Copy to app local path": "将漫画复制到本地存储目录中", "Delete all unavailable local favorite items": "删除所有无效的本地收藏", @@ -633,6 +634,7 @@ "No Category Pages": "沒有分類頁面", "Chapter @ep": "第 @ep 章", "Page @page": "第 @page 頁", + "Remove local favorite and history": "刪除本機收藏和歷史記錄", "Also remove files on disk": "同時刪除磁碟上的文件", "Copy to app local path": "將漫畫複製到本機儲存目錄中", "Delete all unavailable local favorite items": "刪除所有無效的本機收藏", diff --git a/lib/foundation/local.dart b/lib/foundation/local.dart index 9a0c100..36cbe47 100644 --- a/lib/foundation/local.dart +++ b/lib/foundation/local.dart @@ -611,7 +611,7 @@ class LocalManager with ChangeNotifier { notifyListeners(); } - void batchDeleteComics(List comics, [bool removeFileOnDisk = true]) { + void batchDeleteComics(List comics, [bool removeFileOnDisk = true, bool removeFavoriteAndHistory = true]) { if (comics.isEmpty) { return; } @@ -640,8 +640,11 @@ class LocalManager with ChangeNotifier { _db.execute('COMMIT;'); var comicIDs = comics.map((e) => ComicID(e.comicType, e.id)).toList(); - LocalFavoritesManager().batchDeleteComicsInAllFolders(comicIDs); - HistoryManager().batchDeleteHistories(comicIDs); + + if (removeFavoriteAndHistory) { + LocalFavoritesManager().batchDeleteComicsInAllFolders(comicIDs); + HistoryManager().batchDeleteHistories(comicIDs); + } notifyListeners(); diff --git a/lib/pages/local_comics_page.dart b/lib/pages/local_comics_page.dart index 6904054..9095ae7 100644 --- a/lib/pages/local_comics_page.dart +++ b/lib/pages/local_comics_page.dart @@ -361,17 +361,31 @@ class _LocalComicsPageState extends State { context: App.rootContext, builder: (context) { bool removeComicFile = true; + bool removeFavoriteAndHistory = true; return StatefulBuilder(builder: (context, state) { return ContentDialog( title: "Delete".tl, - content: CheckboxListTile( - title: Text("Also remove files on disk".tl), - value: removeComicFile, - onChanged: (v) { - state(() { - removeComicFile = !removeComicFile; - }); - }, + content: Column( + children: [ + CheckboxListTile( + title: Text("Remove local favorite and history".tl), + value: removeFavoriteAndHistory, + onChanged: (v) { + state(() { + removeFavoriteAndHistory = !removeFavoriteAndHistory; + }); + }, + ), + CheckboxListTile( + title: Text("Also remove files on disk".tl), + value: removeComicFile, + onChanged: (v) { + state(() { + removeComicFile = !removeComicFile; + }); + }, + ) + ], ), actions: [ if (comics.length == 1 && comics.first.hasChapters) @@ -388,6 +402,7 @@ class _LocalComicsPageState extends State { LocalManager().batchDeleteComics( comics, removeComicFile, + removeFavoriteAndHistory, ); isDeleted = true; },