This commit is contained in:
Moustapha Kodjo Amadou 2025-11-05 12:52:09 +01:00
parent 1f2b143585
commit 8eea4eaa4d

View file

@ -244,6 +244,7 @@ class _MangaChapterPageGalleryState
} }
final double _horizontalScaleValue = 1.0; final double _horizontalScaleValue = 1.0;
bool _isNextChapterPreloading = false;
late int pagePreloadAmount = ref.read(pagePreloadAmountStateProvider); late int pagePreloadAmount = ref.read(pagePreloadAmountStateProvider);
late bool _isBookmarked = _readerController.getChapterBookmarked(); late bool _isBookmarked = _readerController.getChapterBookmarked();
@ -617,44 +618,8 @@ class _MangaChapterPageGalleryState
_toggleScale(offset), _toggleScale(offset),
onDoubleTap: () {}, onDoubleTap: () {},
// Chapter transition callbacks // Chapter transition callbacks
onChapterChanged: (newChapter) { onChapterChanged: (newChapter) {},
// Update the current chapter when a chapter change is detected onReachedLastPage: (lastPageIndex) {},
if (newChapter.id != chapter.id) {
if (mounted) {
setState(() {
_readerController = ref.read(
readerControllerProvider(
chapter: newChapter,
).notifier,
);
chapter = newChapter;
_isBookmarked = _readerController
.getChapterBookmarked();
});
}
}
},
onReachedLastPage: (lastPageIndex) {
if (!_isLastPageTransition) {
try {
ref
.watch(
getChapterPagesProvider(
chapter: _readerController
.getNextChapter(),
).future,
)
.then(
(value) => _preloadNextChapter(
value,
chapter,
),
);
} on RangeError {
_addLastPageTransition(chapter);
}
}
},
), ),
), ),
) )
@ -1044,15 +1009,21 @@ class _MangaChapterPageGalleryState
} }
if ((itemPositions.last.index == pagesLength - 1) && if ((itemPositions.last.index == pagesLength - 1) &&
!_isLastPageTransition) { !_isLastPageTransition) {
if (_isNextChapterPreloading) return;
try { try {
_isNextChapterPreloading = true;
ref ref
.watch( .watch(
getChapterPagesProvider( getChapterPagesProvider(
chapter: _readerController.getNextChapter(), chapter: _readerController.getNextChapter(),
).future, ).future,
) )
.then((value) => _preloadNextChapter(value, chapter)); .then((value) {
_preloadNextChapter(value, chapter);
_isNextChapterPreloading = false;
});
} on RangeError { } on RangeError {
_isNextChapterPreloading = false;
_addLastPageTransition(chapter); _addLastPageTransition(chapter);
} }
} }
@ -1222,15 +1193,21 @@ class _MangaChapterPageGalleryState
if ((_uChapDataPreload[index].pageIndex! == _uChapDataPreload.length - 1) && if ((_uChapDataPreload[index].pageIndex! == _uChapDataPreload.length - 1) &&
!_isLastPageTransition) { !_isLastPageTransition) {
if (_isNextChapterPreloading) return;
try { try {
_isNextChapterPreloading = true;
ref ref
.watch( .watch(
getChapterPagesProvider( getChapterPagesProvider(
chapter: _readerController.getNextChapter(), chapter: _readerController.getNextChapter(),
).future, ).future,
) )
.then((value) => _preloadNextChapter(value, chapter)); .then((value) {
_preloadNextChapter(value, chapter);
_isNextChapterPreloading = false;
});
} on RangeError { } on RangeError {
_isNextChapterPreloading = false;
_addLastPageTransition(chapter); _addLastPageTransition(chapter);
} }
} }
@ -2011,7 +1988,7 @@ class _MangaChapterPageGalleryState
void _isViewFunction() { void _isViewFunction() {
final fullScreenReader = ref.watch(fullScreenReaderStateProvider); final fullScreenReader = ref.watch(fullScreenReaderStateProvider);
if (mounted) { if (context.mounted) {
setState(() { setState(() {
_isView = !_isView; _isView = !_isView;
}); });