Skip to content

Commit

Permalink
feat: 尽量保证和网络收藏顺序一致
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyray-fan committed Jan 9, 2025
1 parent c03c3f7 commit a245cc6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
49 changes: 27 additions & 22 deletions lib/pages/favorites/favorite_actions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ Future<void> importNetworkFolder(
int requestCount = 0;
var isFinished = false;
int maxPage = 1;
List<FavoriteItem> comics = [];
String? next;
// 如果是从旧到新, 先取一下maxPage
if (isOldToNewSort) {
Expand All @@ -350,25 +351,25 @@ Future<void> 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++;
Expand All @@ -377,31 +378,24 @@ Future<void> 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++;
Expand Down Expand Up @@ -499,5 +493,16 @@ Future<void> 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);
}
}
1 change: 1 addition & 0 deletions lib/pages/favorites/favorites_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit a245cc6

Please sign in to comment.