diff --git a/assets/translation.json b/assets/translation.json index 73d62cc..7be6c04 100644 --- a/assets/translation.json +++ b/assets/translation.json @@ -139,8 +139,8 @@ "Block": "屏蔽", "Add new favorite to": "添加新收藏到", "Move favorite after reading": "阅读后移动收藏", - "Delete folder?" : "刪除文件夾?", - "Delete folder '@f' ?" : "删除文件夹 '@f' ?", + "Delete folder?" : "删除文件夹?", + "Delete folder '@f' ?" : "删除文件夹 '@f' ?", "Import from file": "从文件导入", "Failed to import": "导入失败", "Cache Limit": "缓存限制", @@ -324,7 +324,13 @@ "Success": "成功", "Compressing": "压缩中", "Exporting": "导出中", - "Search Sources": "搜索源" + "Search Sources": "搜索源", + "Removed": "已移除", + "Added to favorites": "已添加到收藏", + "Not added": "未添加", + "Create a folder": "新建收藏夹", + "Created successfully": "创建成功", + "name": "名称" }, "zh_TW": { "Home": "首頁", @@ -651,6 +657,12 @@ "Success": "成功", "Compressing": "壓縮中", "Exporting": "匯出中", - "Search Sources": "搜索源" + "Search Sources": "搜索源", + "Removed": "已移除", + "Added to favorites": "已添加到收藏", + "Not added": "未添加", + "Create a folder": "新建收藏夾", + "Created successfully": "創建成功", + "name": "名稱" } } \ No newline at end of file diff --git a/lib/foundation/comic_source/favorites.dart b/lib/foundation/comic_source/favorites.dart index a6423f5..fb845b6 100644 --- a/lib/foundation/comic_source/favorites.dart +++ b/lib/foundation/comic_source/favorites.dart @@ -37,6 +37,8 @@ class FavoriteData { final AddOrDelFavFunc? addOrDelFavorite; + final bool singleFolderForSingleComic; + const FavoriteData({ required this.key, required this.title, @@ -49,6 +51,7 @@ class FavoriteData { this.allFavoritesId, this.addOrDelFavorite, this.isOldToNewSort, + this.singleFolderForSingleComic = false, }); } diff --git a/lib/foundation/comic_source/parser.dart b/lib/foundation/comic_source/parser.dart index 4266193..08d399a 100644 --- a/lib/foundation/comic_source/parser.dart +++ b/lib/foundation/comic_source/parser.dart @@ -620,6 +620,7 @@ class ComicSourceParser { final bool multiFolder = _getValue("favorites.multiFolder"); final bool? isOldToNewSort = _getValue("favorites.isOldToNewSort"); + final bool? singleFolderForSingleComic = _getValue("favorites.singleFolderForSingleComic"); Future> retryZone(Future> Function() func) async { if (!ComicSource.find(_key!)!.isLogged) { @@ -773,6 +774,7 @@ class ComicSourceParser { deleteFolder: deleteFolder, addOrDelFavorite: addOrDelFavFunc, isOldToNewSort: isOldToNewSort, + singleFolderForSingleComic: singleFolderForSingleComic ?? false, ); } diff --git a/lib/pages/comic_page.dart b/lib/pages/comic_page.dart index 6bf09da..d1f2db9 100644 --- a/lib/pages/comic_page.dart +++ b/lib/pages/comic_page.dart @@ -614,8 +614,10 @@ abstract mixin class _ComicPageActions { update(); } + /// whether the comic is added to local favorite bool isAddToLocalFav = false; + /// whether the comic is favorite on the server bool isFavorite = false; FavoriteItem _toFavoriteItem() { @@ -1672,6 +1674,42 @@ class _NetworkFavoritesState extends State<_NetworkFavorites> { } Widget buildMultiFolder() { + if (widget.isFavorite == true && + widget.comicSource.favoriteData!.singleFolderForSingleComic) { + return Column( + children: [ + Expanded( + child: Center( + child: Text("Added to favorites".tl), + ), + ), + Center( + child: Button.filled( + isLoading: isLoading, + onPressed: () async { + setState(() { + isLoading = true; + }); + + var res = await widget.comicSource.favoriteData! + .addOrDelFavorite!(widget.cid, '', false, null); + if (res.success) { + widget.onFavorite(false); + context.pop(); + App.rootContext.showMessage(message: "Removed".tl); + } else { + setState(() { + isLoading = false; + }); + context.showMessage(message: res.errorMessage!); + } + }, + child: Text("Remove".tl), + ).paddingVertical(8), + ), + ], + ); + } if (isLoadingFolders) { loadFolders(); return const Center(child: CircularProgressIndicator()); diff --git a/lib/pages/favorites/network_favorites_page.dart b/lib/pages/favorites/network_favorites_page.dart index 8acc3b1..5baef91 100644 --- a/lib/pages/favorites/network_favorites_page.dart +++ b/lib/pages/favorites/network_favorites_page.dart @@ -476,55 +476,47 @@ class _CreateFolderDialogState extends State<_CreateFolderDialog> { @override Widget build(BuildContext context) { - return SimpleDialog( - title: Text("Create a folder".tl), - children: [ - Padding( - padding: const EdgeInsets.fromLTRB(20, 0, 20, 0), - child: TextField( - controller: controller, - decoration: InputDecoration( - border: const OutlineInputBorder(), - labelText: "name".tl, - ), - ), - ), - const SizedBox( - width: 200, - height: 10, - ), - if (loading) - Center( - child: const CircularProgressIndicator( - strokeWidth: 2, - ).fixWidth(24).fixHeight(24), - ) - else - SizedBox( - height: 35, - child: Center( - child: TextButton( - onPressed: () { - setState(() { - loading = true; - }); - widget.data.addFolder!(controller.text).then((b) { - if (b.error) { - context.showMessage(message: b.errorMessage!); - setState(() { - loading = false; - }); - } else { - context.pop(); - context.showMessage(message: "Created successfully".tl); - widget.updateState(); - } - }); - }, - child: Text("Submit".tl), + return ContentDialog( + title: "Create a folder".tl, + content: Column( + children: [ + Padding( + padding: const EdgeInsets.fromLTRB(16, 0, 16, 0), + child: TextField( + controller: controller, + decoration: InputDecoration( + border: const OutlineInputBorder(), + labelText: "name".tl, ), ), - ) + ), + const SizedBox( + height: 16 + ), + ], + ), + actions: [ + Button.filled( + isLoading: loading, + onPressed: () { + setState(() { + loading = true; + }); + widget.data.addFolder!(controller.text).then((b) { + if (b.error) { + context.showMessage(message: b.errorMessage!); + setState(() { + loading = false; + }); + } else { + context.pop(); + context.showMessage(message: "Created successfully".tl); + widget.updateState(); + } + }); + }, + child: Text("Submit".tl), + ) ], ); }