Fix an issue where it was impossible to read a new chapter of a downloaded comic. Close #256

This commit is contained in:
2025-03-17 19:18:18 +08:00
parent 533497ead1
commit 55ad652191
4 changed files with 26 additions and 5 deletions

View File

@@ -422,12 +422,30 @@ class LocalManager with ChangeNotifier {
return files.map((e) => "file://${e.path}").toList();
}
bool isDownloaded(String id, ComicType type, [int? ep]) {
bool isDownloaded(String id, ComicType type,
[int? ep, ComicChapters? chapters]) {
var comic = find(id, type);
if (comic == null) return false;
if (comic.chapters == null || ep == null) return true;
if (chapters != null) {
if (comic.chapters?.length != chapters.length) {
// update
add(LocalComic(
id: comic.id,
title: comic.title,
subtitle: comic.subtitle,
tags: comic.tags,
directory: comic.directory,
chapters: chapters,
cover: comic.cover,
comicType: comic.comicType,
downloadedChapters: comic.downloadedChapters,
createdAt: comic.createdAt,
));
}
}
return comic.downloadedChapters
.contains(comic.chapters!.ids.elementAt(ep - 1));
.contains((chapters ?? comic.chapters)!.ids.elementAtOrNull(ep - 1));
}
List<DownloadTask> downloadingTasks = [];

View File

@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:venera/components/components.dart';
import 'package:venera/foundation/app.dart';
import 'package:venera/foundation/appdata.dart';
import 'package:venera/foundation/comic_type.dart';
import 'package:venera/foundation/local.dart';
import 'package:venera/foundation/log.dart';
import 'package:venera/pages/comic_details_page/comic_page.dart';
@@ -304,7 +305,9 @@ class _LocalComicsPageState extends State<LocalComicsPage> {
}
});
} else {
(c as LocalComic).read();
// prevent dirty data
var comic = LocalManager().find(c.id, ComicType(c.sourceKey.hashCode))!;
comic.read();
}
},
menuBuilder: (c) {

View File

@@ -26,7 +26,7 @@ class _ReaderImagesState extends State<_ReaderImages> {
inProgress = true;
if (reader.type == ComicType.local ||
(LocalManager()
.isDownloaded(reader.cid, reader.type, reader.chapter))) {
.isDownloaded(reader.cid, reader.type, reader.chapter, reader.widget.chapters))) {
try {
var images = await LocalManager()
.getImages(reader.cid, reader.type, reader.chapter);

View File

@@ -115,7 +115,7 @@ class _ReaderState extends State<Reader>
String get cid => widget.cid;
String get eid => widget.chapters?.ids.elementAt(chapter - 1) ?? '0';
String get eid => widget.chapters?.ids.elementAtOrNull(chapter - 1) ?? '0';
List<String>? images;