Fixed the storage of chapter read information.

This commit is contained in:
2025-02-13 10:47:54 +08:00
parent d2aca7ce44
commit 14c3e9ea43
2 changed files with 36 additions and 16 deletions

View File

@@ -49,19 +49,19 @@ class ComicPage extends StatefulWidget {
class _ComicPageState extends LoadingState<ComicPage, ComicDetails> class _ComicPageState extends LoadingState<ComicPage, ComicDetails>
with _ComicPageActions { with _ComicPageActions {
@override
History? history;
bool showAppbarTitle = false; bool showAppbarTitle = false;
var scrollController = ScrollController(); var scrollController = ScrollController();
bool isDownloaded = false; bool isDownloaded = false;
void updateHistory() async { @override
var newHistory = await HistoryManager() void onReadEnd() {
.find(widget.id, ComicType(widget.sourceKey.hashCode)); // The history is passed by reference, so it will be updated automatically.
if (newHistory?.ep != history?.ep || newHistory?.page != history?.page) { update();
history = newHistory;
update();
}
} }
@override @override
@@ -77,14 +77,12 @@ class _ComicPageState extends LoadingState<ComicPage, ComicDetails>
@override @override
void initState() { void initState() {
scrollController.addListener(onScroll); scrollController.addListener(onScroll);
HistoryManager().addListener(updateHistory);
super.initState(); super.initState();
} }
@override @override
void dispose() { void dispose() {
scrollController.removeListener(onScroll); scrollController.removeListener(onScroll);
HistoryManager().removeListener(updateHistory);
super.dispose(); super.dispose();
} }
@@ -552,7 +550,7 @@ class _ComicPageState extends LoadingState<ComicPage, ComicDetails>
if (comic.chapters == null) { if (comic.chapters == null) {
return const SliverPadding(padding: EdgeInsets.zero); return const SliverPadding(padding: EdgeInsets.zero);
} }
return const _ComicChapters(); return _ComicChapters(history);
} }
Widget buildThumbnails() { Widget buildThumbnails() {
@@ -594,7 +592,7 @@ abstract mixin class _ComicPageActions {
ComicSource get comicSource => ComicSource.find(comic.sourceKey)!; ComicSource get comicSource => ComicSource.find(comic.sourceKey)!;
History? history; History? get history;
bool isLiking = false; bool isLiking = false;
@@ -688,11 +686,13 @@ abstract mixin class _ComicPageActions {
chapters: comic.chapters, chapters: comic.chapters,
initialChapter: ep, initialChapter: ep,
initialPage: page, initialPage: page,
history: History.fromModel(model: comic, ep: 0, page: 0), history: history ?? History.fromModel(model: comic, ep: 0, page: 0),
author: comic.findAuthor() ?? '', author: comic.findAuthor() ?? '',
tags: comic.plainTags, tags: comic.plainTags,
), ),
); ).then((_) {
onReadEnd();
});
} }
void continueRead() { void continueRead() {
@@ -701,6 +701,8 @@ abstract mixin class _ComicPageActions {
read(ep, page); read(ep, page);
} }
void onReadEnd();
void download() async { void download() async {
if (LocalManager().isDownloading(comic.id, comic.comicType)) { if (LocalManager().isDownloading(comic.id, comic.comicType)) {
App.rootContext.showMessage(message: "The comic is downloading".tl); App.rootContext.showMessage(message: "The comic is downloading".tl);
@@ -1083,7 +1085,9 @@ class _ActionButton extends StatelessWidget {
} }
class _ComicChapters extends StatefulWidget { class _ComicChapters extends StatefulWidget {
const _ComicChapters(); const _ComicChapters(this.history);
final History? history;
@override @override
State<_ComicChapters> createState() => _ComicChaptersState(); State<_ComicChapters> createState() => _ComicChaptersState();
@@ -1096,12 +1100,28 @@ class _ComicChaptersState extends State<_ComicChapters> {
bool showAll = false; bool showAll = false;
late History? history;
@override
void initState() {
super.initState();
history = widget.history;
}
@override @override
void didChangeDependencies() { void didChangeDependencies() {
state = context.findAncestorStateOfType<_ComicPageState>()!; state = context.findAncestorStateOfType<_ComicPageState>()!;
super.didChangeDependencies(); super.didChangeDependencies();
} }
@override
void didUpdateWidget(covariant _ComicChapters oldWidget) {
super.didUpdateWidget(oldWidget);
setState(() {
history = widget.history;
});
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final eps = state.comic.chapters!; final eps = state.comic.chapters!;
@@ -1151,8 +1171,7 @@ class _ComicChaptersState extends State<_ComicChapters> {
} }
var key = eps.keys.elementAt(i); var key = eps.keys.elementAt(i);
var value = eps[key]!; var value = eps[key]!;
bool visited = bool visited = (history?.readEpisode ?? {}).contains(i + 1);
(state.history?.readEpisode ?? const {}).contains(i + 1);
return Padding( return Padding(
padding: const EdgeInsets.fromLTRB(6, 4, 6, 4), padding: const EdgeInsets.fromLTRB(6, 4, 6, 4),
child: Material( child: Material(

View File

@@ -237,6 +237,7 @@ class _ReaderState extends State<Reader> with _ReaderLocation, _ReaderWindow {
history!.maxPage = maxPage; history!.maxPage = maxPage;
} }
history!.readEpisode.add(chapter); history!.readEpisode.add(chapter);
print(history!.readEpisode);
history!.time = DateTime.now(); history!.time = DateTime.now();
HistoryManager().addHistory(history!); HistoryManager().addHistory(history!);
} }