From a245cc6134a549b6cb47d320473f1f68e061c155 Mon Sep 17 00:00:00 2001 From: Yoshiro_fan Date: Thu, 9 Jan 2025 22:47:28 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=B0=BD=E9=87=8F=E4=BF=9D=E8=AF=81?= =?UTF-8?q?=E5=92=8C=E7=BD=91=E7=BB=9C=E6=94=B6=E8=97=8F=E9=A1=BA=E5=BA=8F?= =?UTF-8?q?=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/favorites/favorite_actions.dart | 49 +++++++++++++---------- lib/pages/favorites/favorites_page.dart | 1 + 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/lib/pages/favorites/favorite_actions.dart b/lib/pages/favorites/favorite_actions.dart index 82e155b..1fb5a9a 100644 --- a/lib/pages/favorites/favorite_actions.dart +++ b/lib/pages/favorites/favorite_actions.dart @@ -339,6 +339,7 @@ Future importNetworkFolder( int requestCount = 0; var isFinished = false; int maxPage = 1; + List comics = []; String? next; // 如果是从旧到新, 先取一下maxPage if (isOldToNewSort) { @@ -350,25 +351,25 @@ Future importNetworkFolder( while (updatePageNum > requestCount && !isFinished) { try { if (comicSource.favoriteData?.loadComic != null) { - next ??= isOldToNewSort ? maxPage.toString() : '1'; + // 从旧到新的情况下, 假设有10页, 更新3页, 则从第8页开始, 8, 9, 10 三页 + next ??= + isOldToNewSort ? (maxPage - updatePageNum + 1).toString() : '1'; var page = int.parse(next!); var res = await comicSource.favoriteData!.loadComic!(page, folderID); var count = 0; receivedComics += res.data.length; for (var c in res.data) { - var result = LocalFavoritesManager().addComic( - resultName, - FavoriteItem( + if (!LocalFavoritesManager() + .comicExists(resultName, c.id, ComicType(source.hashCode))) { + count++; + comics.add(FavoriteItem( id: c.id, name: c.title, coverPath: c.cover, type: ComicType(source.hashCode), author: c.subtitle ?? '', tags: c.tags ?? [], - ), - ); - if (result) { - count++; + )); } } requestCount++; @@ -377,31 +378,24 @@ Future importNetworkFolder( isFinished = true; next = null; } else { - next = - isOldToNewSort ? (page - 1).toString() : (page + 1).toString(); - // 兼容收藏顺序按时间从旧到新的漫画拉取 - if (next == '0') { - isFinished = true; - } + next = (page + 1).toString(); } } else if (comicSource.favoriteData?.loadNext != null) { var res = await comicSource.favoriteData!.loadNext!(next, folderID); var count = 0; receivedComics += res.data.length; for (var c in res.data) { - var result = LocalFavoritesManager().addComic( - resultName, - FavoriteItem( + if (!LocalFavoritesManager() + .comicExists(resultName, c.id, ComicType(source.hashCode))) { + count++; + comics.add(FavoriteItem( id: c.id, name: c.title, coverPath: c.cover, type: ComicType(source.hashCode), author: c.subtitle ?? '', tags: c.tags ?? [], - ), - ); - if (result) { - count++; + )); } } requestCount++; @@ -499,5 +493,16 @@ Future importNetworkFolder( break; } } - closeDialog?.call(); + try { + if (appdata.settings['newFavoriteAddTo'] == "start" && !isOldToNewSort) { + // 如果是插到最前, 并且是从新到旧, 反转一下 + comics = comics.reversed.toList(); + } + for (var c in comics) { + LocalFavoritesManager().addComic(resultName, c); + } + closeDialog?.call(); + } catch (e, stackTrace) { + Log.error("Unhandled Exception", e.toString(), stackTrace); + } } diff --git a/lib/pages/favorites/favorites_page.dart b/lib/pages/favorites/favorites_page.dart index 3fe2d5f..80445b2 100644 --- a/lib/pages/favorites/favorites_page.dart +++ b/lib/pages/favorites/favorites_page.dart @@ -11,6 +11,7 @@ import 'package:venera/foundation/comic_type.dart'; import 'package:venera/foundation/consts.dart'; import 'package:venera/foundation/favorites.dart'; import 'package:venera/foundation/local.dart'; +import 'package:venera/foundation/log.dart'; import 'package:venera/foundation/res.dart'; import 'package:venera/network/download.dart'; import 'package:venera/pages/comic_page.dart';