Skip to content

Commit

Permalink
feat: jm导入, pica历史记录nhentai有问题, 一键反转
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyray-fan committed Jan 5, 2025
1 parent aee64a3 commit 55d8f07
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 140 deletions.
6 changes: 1 addition & 5 deletions android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,4 @@ android.useAndroidX=true
android.enableJetifier=true
android.defaults.buildfeatures.buildconfig=true
android.nonTransitiveRClass=false
android.nonFinalResIds=false
systemProp.http.proxyHost=127.0.0.1
systemProp.http.proxyPort=7890
systemProp.https.proxyHost=127.0.0.1
systemProp.https.proxyPort=7890
android.nonFinalResIds=false
2 changes: 2 additions & 0 deletions assets/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"Select a folder": "选择一个文件夹",
"Folder": "文件夹",
"Confirm": "确认",
"Reversed successfully": "反转成功",
"Remove comic from favorite?": "从收藏中移除漫画?",
"Move": "移动",
"Move to folder": "移动到文件夹",
Expand Down Expand Up @@ -460,6 +461,7 @@
"Date": "日期",
"Date Desc": "日期降序",
"Start": "開始",
"Reversed successfully": "反轉成功",
"Export App Data": "匯出應用數據",
"Import App Data (Please restart after success)": "匯入應用數據(成功后請手動重啟)",
"Export": "匯出",
Expand Down
6 changes: 3 additions & 3 deletions lib/foundation/comic_source/favorites.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class FavoriteData {
final bool multiFolder;

// 这个收藏时间新旧顺序, 是为了最小成本同步远端的收藏, 只拉取远程最新收藏的漫画, 就不需要全拉取一遍了
// 如果为 null, 不做处理, 拉取全部
final bool? isNewToOldSort;
// 如果为 null, 当做从新到旧
final bool? isOldToNewSort;

final Future<Res<List<Comic>>> Function(int page, [String? folder])?
loadComic;
Expand Down Expand Up @@ -48,7 +48,7 @@ class FavoriteData {
this.addFolder,
this.allFavoritesId,
this.addOrDelFavorite,
this.isNewToOldSort,
this.isOldToNewSort,
});
}

Expand Down
4 changes: 2 additions & 2 deletions lib/foundation/comic_source/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ class ComicSourceParser {
if (!_checkExists("favorites")) return null;

final bool multiFolder = _getValue("favorites.multiFolder");
final bool? isNewToOldSort = _getValue("favorites.isNewToOldSort");
final bool? isOldToNewSort = _getValue("favorites.isOldToNewSort");

Future<Res<T>> retryZone<T>(Future<Res<T>> Function() func) async {
if (!ComicSource.find(_key!)!.isLogged) {
Expand Down Expand Up @@ -771,7 +771,7 @@ class ComicSourceParser {
addFolder: addFolder,
deleteFolder: deleteFolder,
addOrDelFavorite: addOrDelFavFunc,
isNewToOldSort: isNewToOldSort,
isOldToNewSort: isOldToNewSort,
);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/foundation/image_favorites.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class ImageFavoritePro extends ImageFavorite {
}

class ImageFavoritesEp {
final String eid;
String eid;
final int ep;
int maxPage;
String epName;
Expand Down
8 changes: 4 additions & 4 deletions lib/pages/favorites/favorite_actions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -333,15 +333,15 @@ Future<void> importNetworkFolder(
folderID ?? "",
);
}
bool isNewToOldSort = comicSource.favoriteData?.isNewToOldSort ?? true;
bool isOldToNewSort = comicSource.favoriteData?.isOldToNewSort ?? false;
var current = 0;
int receivedComics = 0;
int requestCount = 0;
var isFinished = false;
int maxPage = 1;
String? next;
// 如果是从旧到新, 先取一下maxPage
if (!isNewToOldSort) {
if (isOldToNewSort) {
var res = await comicSource.favoriteData?.loadComic!(1, folderID);
maxPage = res?.subData ?? 1;
}
Expand All @@ -350,7 +350,7 @@ Future<void> importNetworkFolder(
while (updatePageNum >= requestCount && !isFinished) {
try {
if (comicSource.favoriteData?.loadComic != null) {
next ??= isNewToOldSort ? '1' : maxPage.toString();
next ??= isOldToNewSort ? maxPage.toString() : '1';
var page = int.parse(next!);
var res = await comicSource.favoriteData!.loadComic!(page, folderID);
var count = 0;
Expand Down Expand Up @@ -378,7 +378,7 @@ Future<void> importNetworkFolder(
next = null;
} else {
next =
isNewToOldSort ? (page + 1).toString() : (page - 1).toString();
isOldToNewSort ? (page - 1).toString() : (page + 1).toString();
}
} else if (comicSource.favoriteData?.loadNext != null) {
var res = await comicSource.favoriteData!.loadNext!(next, folderID);
Expand Down
58 changes: 34 additions & 24 deletions lib/pages/favorites/local_favorites_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,30 +44,29 @@ class _SelectUpdatePageNumState extends State<_SelectUpdatePageNum> {
Row(
children: [Text(text)],
),
if (source?.favoriteData?.isNewToOldSort != null)
Row(
children: [
Text("Update the page number by the latest collection".tl),
Spacer(),
Select(
current: updatePageNum.toString() == '9999999'
? allPageText
: updatePageNum.toString(),
values: pageNumList,
minWidth: 64,
onTap: (index) {
setState(() {
updatePageNum = int.parse(pageNumList[index] == allPageText
? '9999999'
: pageNumList[index]);
appdata.implicitData["local_favorites_update_page_num"] =
updatePageNum;
appdata.writeImplicitData();
});
},
)
],
),
Row(
children: [
Text("Update the page number by the latest collection".tl),
Spacer(),
Select(
current: updatePageNum.toString() == '9999999'
? allPageText
: updatePageNum.toString(),
values: pageNumList,
minWidth: 64,
onTap: (index) {
setState(() {
updatePageNum = int.parse(pageNumList[index] == allPageText
? '9999999'
: pageNumList[index]);
appdata.implicitData["local_favorites_update_page_num"] =
updatePageNum;
appdata.writeImplicitData();
});
},
)
],
),
],
);
}
Expand Down Expand Up @@ -816,6 +815,17 @@ class _ReorderComicsPageState extends State<_ReorderComicsPage> {
);
},
),
IconButton(
icon: const Icon(Icons.swap_vert),
onPressed: () {
setState(() {
comics = comics.reversed.toList();
changed = true;
showToast(
message: "Reversed successfully".tl, context: context);
});
},
),
],
),
body: ReorderableBuilder<FavoriteItem>(
Expand Down
96 changes: 63 additions & 33 deletions lib/pages/image_favorites_page/image_favorites_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ImageFavoritesItemState extends State<ImageFavoritesItem> {
bool hasRefreshImageKeyOnErr = false;
late LoadingImageFavoritesComicRes loadingImageFavoritesComicRes;

// 如果 imageKey 失效了, 或者刚从pica导入(没有imageKey)
// 如果刚从pica导入(没有imageKey) 或者 imageKey 失效了, 刷新一下
void refreshImageKey(ImageFavoritesEp imageFavoritesEp) async {
if (isImageKeyLoading ||
hasRefreshImageKeyOnErr ||
Expand All @@ -40,6 +40,7 @@ class ImageFavoritesItemState extends State<ImageFavoritesItem> {
isImageKeyLoading = true;
ComicSource? comicSource =
ComicSource.find(widget.imageFavoritesComic.sourceKey);
// 拿一下漫画信息和对应章节的图片
var resArr = await Future.wait([
comicSource!.loadComicPages!(
widget.imageFavoritesComic.id,
Expand All @@ -54,33 +55,62 @@ class ImageFavoritesItemState extends State<ImageFavoritesItem> {
if (comicInfoRes.errorMessage?.contains("404") ?? false) {
loadingImageFavoritesComicRes.isInvalid = true;
widget.setRefreshComicList(loadingImageFavoritesComicRes);
} else if (!comicPagesRes.error && !comicInfoRes.error) {
List<String> images = comicPagesRes.data;
if (mounted) {
setState(() {});
}
return;
}
if (!comicInfoRes.error) {
ImageFavoritesSomething something =
ImageFavoritesComic.getSomethingFromComicDetails(
comicInfoRes.data, imageFavoritesEp.ep);
// 刷新一下值, 保存最新的
widget.imageFavoritesComic.author = something.author;
widget.imageFavoritesComic.maxPage = images.length;
widget.imageFavoritesComic.subTitle = something.subTitle;
widget.imageFavoritesComic.tags = something.tags;
widget.imageFavoritesComic.translatedTags = something.translatedTags;
imageFavoritesEp.maxPage = images.length;
imageFavoritesEp.epName = something.epName;
// 塞一个封面进去
if (!imageFavoritesEp.isHasFirstPage) {
ImageFavoritePro copy =
ImageFavoritePro.copy(imageFavoritesEp.imageFavorites[0]);
copy.page = ImageFavoritesEp.firstPage;
copy.isAutoFavorite = true;
imageFavoritesEp.imageFavorites.insert(0, copy);
} else {
return;
}
if (comicPagesRes.error) {
// 能加载漫画信息, 说明只是章节对不太上, 刷新一下章节
var chapters = comicInfoRes.data.chapters;
// 兜底一下, 如果章节对不上return, 说明是调用接口更新过章节的, 比如拷贝, jm, 避免丢失最初正确的eid
// 拷贝, jm可能会更新章节顺序, 以eid为准比较好
if (imageFavoritesEp.eid != imageFavoritesEp.ep.toString()) {
return;
}
// 统一刷一下最新的imageKey
for (var ele in imageFavoritesEp.imageFavorites) {
ele.imageKey = images[ele.page - 1];
var finalEid = chapters?.keys.elementAt(imageFavoritesEp.ep - 1) ?? '0';
var resArr = await Future.wait([
comicSource!.loadComicPages!(
widget.imageFavoritesComic.id,
finalEid,
)
]);
comicPagesRes = resArr[0];
if (comicPagesRes.error) {
return;
} else {
imageFavoritesEp.eid = finalEid;
}
ImageFavoriteManager.addOrUpdateOrDelete(widget.imageFavoritesComic);
}
List<String> images = comicPagesRes.data;
widget.imageFavoritesComic.maxPage = images.length;
imageFavoritesEp.maxPage = images.length;
// 塞一个封面进去
if (!imageFavoritesEp.isHasFirstPage) {
ImageFavoritePro copy =
ImageFavoritePro.copy(imageFavoritesEp.imageFavorites[0]);
copy.page = ImageFavoritesEp.firstPage;
copy.isAutoFavorite = true;
imageFavoritesEp.imageFavorites.insert(0, copy);
}
// 统一刷一下最新的imageKey
for (var ele in imageFavoritesEp.imageFavorites) {
ele.imageKey = images[ele.page - 1];
}
ImageFavoriteManager.addOrUpdateOrDelete(widget.imageFavoritesComic);
if (mounted) {
setState(() {});
}
Expand Down Expand Up @@ -212,25 +242,9 @@ class ImageFavoritesItemState extends State<ImageFavoritesItem> {
.firstWhere((e) {
return e.eid == curImageFavorite.eid;
});
ImageProvider image =
ImageFavoritesProvider(curImageFavorite);
bool isSelected =
widget.selectedImageFavorites[curImageFavorite] ??
false;
Widget imageWidget = AnimatedImage(
image: image,
width: 96,
height: 128,
fit: BoxFit.cover,
filterQuality: FilterQuality.medium,
onError: (Object error, StackTrace? stackTrace) {
if (loadingImageFavoritesComicRes.isLoaded) {
return;
}
refreshImageKey(curImageFavoritesEp);
hasRefreshImageKeyOnErr = true;
},
);
int curPage = curImageFavorite.page;
String pageText = curPage == ImageFavoritesEp.firstPage
? '@a Cover'
Expand Down Expand Up @@ -287,7 +301,23 @@ class ImageFavoritesItemState extends State<ImageFavoritesItem> {
.secondaryContainer,
),
clipBehavior: Clip.antiAlias,
child: imageWidget),
child: AnimatedImage(
image: ImageFavoritesProvider(
curImageFavorite),
width: 96,
height: 128,
fit: BoxFit.cover,
filterQuality: FilterQuality.medium,
onError: (Object error,
StackTrace? stackTrace) {
if (loadingImageFavoritesComicRes
.isLoaded) {
return;
}
refreshImageKey(curImageFavoritesEp);
hasRefreshImageKeyOnErr = true;
},
)),
Text(
pageText,
style: ts.s10,
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/image_favorites_page/image_favorites_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ class ImageFavoritesPageState extends State<ImageFavoritesPage> {
_debouncer.run(() {
keyword = _textEditingController.text;
update();
}, Duration(seconds: 1));
}, Duration(milliseconds: 500));
},
),
),
Expand Down
5 changes: 3 additions & 2 deletions lib/utils/data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -198,17 +198,18 @@ Future<void> importPicaData(File file) async {
2 => 'jm'.hashCode,
3 => 'hitomi'.hashCode,
4 => 'wnacg'.hashCode,
6 => 'nhentai'.hashCode,
5 => 'nhentai'.hashCode,
_ => comic['type']
},
"id": comic['target'],
"maxPage": comic["max_page"],
"max_page": comic["max_page"],
"ep": comic["ep"],
"page": comic["page"],
"time": comic["time"],
"title": comic["title"],
"subtitle": comic["subtitle"],
"cover": comic["cover"],
"readEpisode": [comic["ep"]],
}),
);
}
Expand Down
1 change: 0 additions & 1 deletion lib/utils/io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,6 @@ class _IOOverrides extends IOOverrides {
return super.createFile(path);
}
}

}

T overrideIO<T>(T Function() f) {
Expand Down
Loading

0 comments on commit 55d8f07

Please sign in to comment.