Do not switch chapters if the current chapter is the first or last chapter in the chapter group.

This commit is contained in:
2025-02-21 14:13:05 +08:00
parent bf51cd5cee
commit a014587a94
4 changed files with 41 additions and 8 deletions

View File

@@ -131,11 +131,11 @@ class _ReaderGestureDetectorState extends AutomaticGlobalState<_ReaderGestureDet
}
if (context.reader.mode.key.startsWith('gallery')) {
if (forward) {
if (!context.reader.toNextPage()) {
if (!context.reader.toNextPage() && !context.reader.isLastChapterOfGroup) {
context.reader.toNextChapter();
}
} else {
if (!context.reader.toPrevPage()) {
if (!context.reader.toPrevPage() && !context.reader.isFirstChapterOfGroup) {
context.reader.toPrevChapter();
}
}

View File

@@ -206,11 +206,11 @@ class _GalleryModeState extends State<_GalleryMode>
),
onPageChanged: (i) {
if (i == 0) {
if (!reader.toPrevChapter()) {
if (reader.isFirstChapterOfGroup || !reader.toPrevChapter()) {
reader.toPage(1);
}
} else if (i == totalPages + 1) {
if (!reader.toNextChapter()) {
if (reader.isLastChapterOfGroup || !reader.toNextChapter()) {
reader.toPage(totalPages);
}
} else {
@@ -575,15 +575,14 @@ class _ContinuousModeState extends State<_ContinuousMode>
}
if (notification is ScrollUpdateNotification) {
var length = reader.maxChapter;
if (!scrollController.hasClients) return false;
if (scrollController.position.pixels <=
scrollController.position.minScrollExtent &&
reader.chapter != 1) {
!reader.isFirstChapterOfGroup) {
context.readerScaffold.setFloatingButton(-1);
} else if (scrollController.position.pixels >=
scrollController.position.maxScrollExtent &&
reader.chapter < length) {
!reader.isLastChapterOfGroup) {
context.readerScaffold.setFloatingButton(1);
} else {
context.readerScaffold.setFloatingButton(0);

View File

@@ -265,6 +265,40 @@ class _ReaderState extends State<Reader>
});
}
}
bool get isFirstChapterOfGroup {
if (widget.chapters?.isGrouped ?? false) {
int c = chapter - 1;
int g = 1;
while (c > 0) {
c -= widget.chapters!.getGroupByIndex(g - 1).length;
g++;
}
if (c == 0) {
return true;
} else {
return false;
}
}
return chapter == 1;
}
bool get isLastChapterOfGroup {
if (widget.chapters?.isGrouped ?? false) {
int c = chapter;
int g = 1;
while (c > 0) {
c -= widget.chapters!.getGroupByIndex(g - 1).length;
g++;
}
if (c == 0) {
return true;
} else {
return false;
}
}
return chapter == maxChapter;
}
}
abstract mixin class _ImagePerPageHandler {