mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 07:47:24 +00:00
add favorites option to importing comic dialog
This commit is contained in:
@@ -5,6 +5,7 @@ import 'package:venera/foundation/app.dart';
|
||||
import 'package:venera/foundation/comic_source/comic_source.dart';
|
||||
import 'package:venera/foundation/comic_type.dart';
|
||||
import 'package:venera/foundation/consts.dart';
|
||||
import 'package:venera/foundation/favorites.dart';
|
||||
import 'package:venera/foundation/history.dart';
|
||||
import 'package:venera/foundation/image_provider/cached_image.dart';
|
||||
import 'package:venera/foundation/local.dart';
|
||||
@@ -384,6 +385,10 @@ class _ImportComicsWidgetState extends State<_ImportComicsWidget> {
|
||||
|
||||
var height = 200.0;
|
||||
|
||||
var folders = LocalFavoritesManager().folderNames;
|
||||
|
||||
String? selectedFolder;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
loading = false;
|
||||
@@ -444,6 +449,19 @@ class _ImportComicsWidgetState extends State<_ImportComicsWidget> {
|
||||
});
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: Text("Add to favorites".tl),
|
||||
trailing: Select(
|
||||
current: selectedFolder,
|
||||
values: folders,
|
||||
minWidth: 112,
|
||||
onTap: (v) {
|
||||
setState(() {
|
||||
selectedFolder = folders[v];
|
||||
});
|
||||
},
|
||||
),
|
||||
).paddingHorizontal(8),
|
||||
const SizedBox(height: 8),
|
||||
Text(info).paddingHorizontal(24),
|
||||
],
|
||||
@@ -509,8 +527,18 @@ class _ImportComicsWidgetState extends State<_ImportComicsWidget> {
|
||||
try {
|
||||
var cache = FilePath.join(App.cachePath, xFile?.name ?? 'temp.cbz');
|
||||
await xFile!.saveTo(cache);
|
||||
await CBZ.import(File(cache));
|
||||
await File(cache).delete();
|
||||
var comic = await CBZ.import(File(cache));
|
||||
if (selectedFolder != null) {
|
||||
LocalFavoritesManager().addComic(selectedFolder!, FavoriteItem(
|
||||
id: comic.id,
|
||||
name: comic.title,
|
||||
coverPath: comic.cover,
|
||||
author: comic.subtitle,
|
||||
type: comic.comicType,
|
||||
tags: comic.tags,
|
||||
));
|
||||
}
|
||||
await File(cache).deleteIgnoreError();
|
||||
} catch (e, s) {
|
||||
Log.error("Import Comic", e.toString(), s);
|
||||
context.showMessage(message: e.toString());
|
||||
@@ -581,6 +609,16 @@ class _ImportComicsWidgetState extends State<_ImportComicsWidget> {
|
||||
}
|
||||
for (var comic in comics.values) {
|
||||
LocalManager().add(comic, LocalManager().findValidId(ComicType.local));
|
||||
if (selectedFolder != null) {
|
||||
LocalFavoritesManager().addComic(selectedFolder!, FavoriteItem(
|
||||
id: comic.id,
|
||||
name: comic.title,
|
||||
coverPath: comic.cover,
|
||||
author: comic.subtitle,
|
||||
type: comic.comicType,
|
||||
tags: comic.tags,
|
||||
));
|
||||
}
|
||||
}
|
||||
context.pop();
|
||||
context.showMessage(
|
||||
|
@@ -69,7 +69,7 @@ class _LocalComicsPageState extends State<LocalComicsPage> {
|
||||
LocalManager().deleteComic(c as LocalComic);
|
||||
}),
|
||||
MenuEntry(
|
||||
icon: Icons.delete,
|
||||
icon: Icons.outbox_outlined,
|
||||
text: "Export as cbz".tl,
|
||||
onClick: () async {
|
||||
var controller = showLoadingDialog(
|
||||
|
@@ -59,7 +59,7 @@ class ComicChapter {
|
||||
}
|
||||
|
||||
abstract class CBZ {
|
||||
static Future<void> import(File file) async {
|
||||
static Future<LocalComic> import(File file) async {
|
||||
var cache = Directory(FilePath.join(App.cachePath, 'cbz_import'));
|
||||
if (cache.existsSync()) cache.deleteSync(recursive: true);
|
||||
cache.createSync();
|
||||
@@ -130,8 +130,7 @@ abstract class CBZ {
|
||||
}
|
||||
}
|
||||
}
|
||||
LocalManager().add(
|
||||
LocalComic(
|
||||
var comic = LocalComic(
|
||||
id: LocalManager().findValidId(ComicType.local),
|
||||
title: metaData.title,
|
||||
subtitle: metaData.author,
|
||||
@@ -142,8 +141,10 @@ abstract class CBZ {
|
||||
downloadedChapters: cpMap?.keys.toList() ?? [],
|
||||
cover: 'cover.${coverFile.path.split('.').last}',
|
||||
createdAt: DateTime.now(),
|
||||
),
|
||||
);
|
||||
LocalManager().add(comic);
|
||||
await cache.delete(recursive: true);
|
||||
return comic;
|
||||
}
|
||||
|
||||
static Future<File> export(LocalComic comic) async {
|
||||
|
Reference in New Issue
Block a user