Improve comic chapters.

This commit is contained in:
2025-02-20 13:08:55 +08:00
parent 2b3c7a8564
commit bd5d10e919
14 changed files with 324 additions and 97 deletions

View File

@@ -9,7 +9,6 @@ import 'package:venera/foundation/favorites.dart';
import 'package:venera/foundation/log.dart';
import 'package:venera/network/download.dart';
import 'package:venera/pages/reader/reader.dart';
import 'package:venera/utils/ext.dart';
import 'package:venera/utils/io.dart';
import 'app.dart';
@@ -34,7 +33,7 @@ class LocalComic with HistoryMixin implements Comic {
/// key: chapter id, value: chapter title
///
/// chapter id is the name of the directory in `LocalManager.path/$directory`
final Map<String, String>? chapters;
final ComicChapters? chapters;
bool get hasChapters => chapters != null;
@@ -67,7 +66,7 @@ class LocalComic with HistoryMixin implements Comic {
subtitle = row[2] as String,
tags = List.from(jsonDecode(row[3] as String)),
directory = row[4] as String,
chapters = MapOrNull.from(jsonDecode(row[5] as String)),
chapters = ComicChapters.fromJsonOrNull(jsonDecode(row[5] as String)),
cover = row[6] as String,
comicType = ComicType(row[7] as int),
downloadedChapters = List.from(jsonDecode(row[8] as String)),
@@ -99,6 +98,7 @@ class LocalComic with HistoryMixin implements Comic {
"tags": tags,
"description": description,
"sourceKey": sourceKey,
"chapters": chapters?.toJson(),
};
}
@@ -391,7 +391,7 @@ class LocalManager with ChangeNotifier {
var directory = Directory(comic.baseDir);
if (comic.hasChapters) {
var cid =
ep is int ? comic.chapters!.keys.elementAt(ep - 1) : (ep as String);
ep is int ? comic.chapters!.ids.elementAt(ep - 1) : (ep as String);
directory = Directory(FilePath.join(directory.path, cid));
}
var files = <File>[];
@@ -425,7 +425,7 @@ class LocalManager with ChangeNotifier {
if (comic == null) return false;
if (comic.chapters == null || ep == null) return true;
return comic.downloadedChapters
.contains(comic.chapters!.keys.elementAt(ep - 1));
.contains(comic.chapters!.ids.elementAt(ep - 1));
}
List<DownloadTask> downloadingTasks = [];