diff --git a/assets/translation.json b/assets/translation.json index 8169596..2a47bee 100644 --- a/assets/translation.json +++ b/assets/translation.json @@ -206,7 +206,8 @@ "Updating": "更新中", "Update Comics Info": "更新漫画信息", "Create Folder": "新建文件夹", - "Select an image on screen": "选择屏幕上的图片" + "Select an image on screen": "选择屏幕上的图片", + "Added @count comics to download queue.": "已添加 @count 本漫画到下载队列" }, "zh_TW": { "Home": "首頁", @@ -415,6 +416,7 @@ "Updating": "更新中", "Update Comics Info": "更新漫畫信息", "Create Folder": "新建文件夾", - "Select an image on screen": "選擇屏幕上的圖片" + "Select an image on screen": "選擇屏幕上的圖片", + "Added @count comics to download queue.": "已添加 @count 本漫畫到下載隊列" } } \ No newline at end of file diff --git a/lib/foundation/local.dart b/lib/foundation/local.dart index cc2fde8..16b8247 100644 --- a/lib/foundation/local.dart +++ b/lib/foundation/local.dart @@ -365,10 +365,10 @@ class LocalManager with ChangeNotifier { return files.map((e) => "file://${e.path}").toList(); } - Future isDownloaded(String id, ComicType type, int ep) async { + Future isDownloaded(String id, ComicType type, [int? ep]) async { var comic = find(id, type); if (comic == null) return false; - if (comic.chapters == null) return true; + if (comic.chapters == null || ep == null) return true; return comic.downloadedChapters .contains(comic.chapters!.keys.elementAt(ep-1)); } diff --git a/lib/network/download.dart b/lib/network/download.dart index 565237a..e68fa26 100644 --- a/lib/network/download.dart +++ b/lib/network/download.dart @@ -76,11 +76,14 @@ class ImagesDownloadTask extends DownloadTask with _TransferSpeedMixin { @override ComicType get comicType => ComicType(source.key.hashCode); + String? comicTitle; + ImagesDownloadTask({ required this.source, required this.comicId, this.comic, this.chapters, + this.comicTitle, }); @override @@ -379,7 +382,7 @@ class ImagesDownloadTask extends DownloadTask with _TransferSpeedMixin { int get speed => currentSpeed; @override - String get title => comic?.title ?? "Loading..."; + String get title => comic?.title ?? comicTitle ?? "Loading..."; @override Map toJson() { diff --git a/lib/pages/favorites/favorites_page.dart b/lib/pages/favorites/favorites_page.dart index 042058e..c380a9a 100644 --- a/lib/pages/favorites/favorites_page.dart +++ b/lib/pages/favorites/favorites_page.dart @@ -9,7 +9,9 @@ import 'package:venera/foundation/appdata.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/local.dart'; import 'package:venera/foundation/res.dart'; +import 'package:venera/network/download.dart'; import 'package:venera/utils/io.dart'; import 'package:venera/utils/translations.dart'; diff --git a/lib/pages/favorites/local_favorites_page.dart b/lib/pages/favorites/local_favorites_page.dart index d3bb263..4bbef38 100644 --- a/lib/pages/favorites/local_favorites_page.dart +++ b/lib/pages/favorites/local_favorites_page.dart @@ -105,7 +105,7 @@ class _LocalFavoritesPageState extends State<_LocalFavoritesPage> { }, ).then( (value) { - if(mounted) { + if (mounted) { setState(() {}); } }, @@ -128,13 +128,40 @@ class _LocalFavoritesPageState extends State<_LocalFavoritesPage> { text: "Update Comics Info".tl, onClick: () { updateComicsInfo(widget.folder).then((newComics) { - if(mounted) { + if (mounted) { setState(() { comics = newComics; }); } }); }), + MenuEntry( + icon: Icons.update, + text: "Download All".tl, + onClick: () async { + int count = 0; + for (var c in comics) { + if (await LocalManager().isDownloaded(c.id, c.type)) { + continue; + } + var comicSource = c.type.comicSource; + if (comicSource == null) { + continue; + } + LocalManager().addTask(ImagesDownloadTask( + source: comicSource, + comicId: c.id, + comic: null, + comicTitle: c.name, + )); + count++; + } + context.showMessage( + message: "Added @count comics to download queue." + .tlParams({ + "count": count.toString(), + })); + }), ], ), ], @@ -219,7 +246,8 @@ class _ReorderComicsPageState extends State<_ReorderComicsPage> { e.author, e.tags, "${e.time} | ${comicSource?.name ?? "Unknown"}", - comicSource?.key ?? (e.type == ComicType.local ? "local" : "Unknown"), + comicSource?.key ?? + (e.type == ComicType.local ? "local" : "Unknown"), null, null, ),