Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Stop sorting returned anime list from remote #12

Merged
merged 2 commits into from
Apr 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 10 additions & 42 deletions lib/request/list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,55 +30,23 @@ class ListRequest {
} else {
debugPrint('非法的Json ${res.toString()}');
}
list.sort((a, b) => b.link!.compareTo(a.link!));

final PopularController popularController =
Modular.get<PopularController>();

// fix bug below 1.0.2
if (!isSorted(popularController.list)) {
debugPrint('缓存结构错误, 尝试重置');
popularController.list.clear();
}

if (list.length != 0) {
List<AnimeInfo> oldlist = popularController.list;
debugPrint('老缓存列表长度为 ${oldlist.length}');
debugPrint('新缓存列表长度为 ${list.length}');
if (popularController.list.length > list.length) {
needFix == true;
}
if (needFix == false) {
newList.addAll(list.getRange(0, list.length - oldlist.length));
newList.addAll(oldlist);
newList.asMap().forEach((index, item) {
if (item.episode!.startsWith('連載中')) {
if (newList[index].link == list[index].link) {
newList[index].episode = list[index].episode;
} else {
needFix = true;
}
}
});
}

// 在 Anime01 目录发生变动时进行深拷贝
if (isSorted(newList) && !needFix) {
debugPrint('新缓存符合规范');
} else {
debugPrint('检测到远方番剧数据库变动');
newList.clear();
newList.addAll(list);
for (var oldAnime in oldlist) {
if (oldAnime.follow == true) {
var index = newList
.indexWhere((newAnime) => newAnime.name == oldAnime.name);
if (index != -1) {
newList[index].follow = oldAnime.follow;
newList[index].progress = oldAnime.progress;
}
}
debugPrint('检测到远方番剧数据库变动');
newList.clear();
newList.addAll(list);
for (var oldAnime in oldlist) {
var index = newList
.indexWhere((newAnime) => newAnime.name == oldAnime.name);
if (index != -1) {
newList[index].follow = oldAnime.follow;
newList[index].progress = oldAnime.progress;
}
;
}
await GStorage.listCahce.clear();
await GStorage.listCahce.addAll(newList);
Expand Down