generated from dellevin/template
原生epub阅读
This commit is contained in:
45
lib/pages/epub_reader/mixins/progress_mixin.dart
Normal file
45
lib/pages/epub_reader/mixins/progress_mixin.dart
Normal file
@@ -0,0 +1,45 @@
|
||||
part of '../reader_screen.dart';
|
||||
|
||||
mixin _ProgressMixin on State<ReaderScreen> {
|
||||
// === Borrowed state (provided by _ReaderScreenState fields) ===
|
||||
int get totalPagesInChapter;
|
||||
|
||||
int get currentPageInChapter;
|
||||
|
||||
int get currentSpineItemIndex;
|
||||
|
||||
BookSession get bookSession;
|
||||
|
||||
bool get isWebViewLoading;
|
||||
|
||||
String get displayProgress;
|
||||
set displayProgress(String v);
|
||||
|
||||
Timer? get progressDebouncer;
|
||||
set progressDebouncer(Timer? v);
|
||||
|
||||
void updateProgressDebounced() {
|
||||
progressDebouncer?.cancel();
|
||||
progressDebouncer = Timer(const Duration(milliseconds: 150), () {
|
||||
if (!mounted) return;
|
||||
if (isWebViewLoading) return;
|
||||
|
||||
final pageInChapterStr =
|
||||
'${currentPageInChapter + 1}/$totalPagesInChapter';
|
||||
|
||||
if (displayProgress != pageInChapterStr) {
|
||||
setState(() {
|
||||
displayProgress = pageInChapterStr;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void saveProgress() {
|
||||
bookSession.saveProgress(
|
||||
currentChapterIndex: currentSpineItemIndex,
|
||||
currentPageInChapter: currentPageInChapter,
|
||||
totalPagesInChapter: totalPagesInChapter,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user