mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 07:47:24 +00:00
add archive download
This commit is contained in:
@@ -682,6 +682,122 @@ abstract mixin class _ComicPageActions {
|
||||
App.rootContext.showMessage(message: "The comic is downloaded".tl);
|
||||
return;
|
||||
}
|
||||
|
||||
if (comicSource.archiveDownloader != null) {
|
||||
bool useNormalDownload = false;
|
||||
List<ArchiveInfo>? archives;
|
||||
int selected = -1;
|
||||
bool isLoading = false;
|
||||
bool isGettingLink = false;
|
||||
await showDialog(
|
||||
context: App.rootContext,
|
||||
builder: (context) {
|
||||
return StatefulBuilder(
|
||||
builder: (context, setState) {
|
||||
return ContentDialog(
|
||||
title: "Download".tl,
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
RadioListTile<int>(
|
||||
value: -1,
|
||||
groupValue: selected,
|
||||
title: Text("Normal".tl),
|
||||
onChanged: (v) {
|
||||
setState(() {
|
||||
selected = v!;
|
||||
});
|
||||
},
|
||||
),
|
||||
ExpansionTile(
|
||||
title: Text("Archive".tl),
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.zero,
|
||||
),
|
||||
collapsedShape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.zero,
|
||||
),
|
||||
onExpansionChanged: (b) {
|
||||
if (!isLoading && b && archives == null) {
|
||||
isLoading = true;
|
||||
comicSource.archiveDownloader!
|
||||
.getArchives(comic.id)
|
||||
.then((value) {
|
||||
if (value.success) {
|
||||
archives = value.data;
|
||||
} else {
|
||||
App.rootContext
|
||||
.showMessage(message: value.errorMessage!);
|
||||
}
|
||||
setState(() {
|
||||
isLoading = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
children: [
|
||||
if (archives == null)
|
||||
const ListLoadingIndicator().toCenter()
|
||||
else
|
||||
for (int i = 0; i < archives!.length; i++)
|
||||
RadioListTile<int>(
|
||||
value: i,
|
||||
groupValue: selected,
|
||||
onChanged: (v) {
|
||||
setState(() {
|
||||
selected = v!;
|
||||
});
|
||||
},
|
||||
title: Text(archives![i].title),
|
||||
subtitle: Text(archives![i].description),
|
||||
)
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
Button.filled(
|
||||
isLoading: isGettingLink,
|
||||
onPressed: () async {
|
||||
if (selected == -1) {
|
||||
useNormalDownload = true;
|
||||
context.pop();
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
isGettingLink = true;
|
||||
});
|
||||
var res =
|
||||
await comicSource.archiveDownloader!.getDownloadUrl(
|
||||
comic.id,
|
||||
archives![selected].id,
|
||||
);
|
||||
if (res.error) {
|
||||
App.rootContext.showMessage(message: res.errorMessage!);
|
||||
setState(() {
|
||||
isGettingLink = false;
|
||||
});
|
||||
} else if (context.mounted) {
|
||||
LocalManager()
|
||||
.addTask(ArchiveDownloadTask(res.data, comic));
|
||||
App.rootContext
|
||||
.showMessage(message: "Download started".tl);
|
||||
context.pop();
|
||||
}
|
||||
},
|
||||
child: Text("Confirm".tl),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
if (!useNormalDownload) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (comic.chapters == null) {
|
||||
LocalManager().addTask(ImagesDownloadTask(
|
||||
source: comicSource,
|
||||
|
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:venera/components/components.dart';
|
||||
import 'package:venera/foundation/app.dart';
|
||||
import 'package:venera/foundation/image_provider/cached_image.dart';
|
||||
import 'package:venera/foundation/local.dart';
|
||||
import 'package:venera/network/download.dart';
|
||||
import 'package:venera/utils/io.dart';
|
||||
@@ -161,8 +162,8 @@ class _DownloadTaskTileState extends State<_DownloadTaskTile> {
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: widget.task.cover == null
|
||||
? null
|
||||
: Image.file(
|
||||
File(widget.task.cover!),
|
||||
: Image(
|
||||
image: CachedImageProvider(widget.task.cover!),
|
||||
filterQuality: FilterQuality.medium,
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
@@ -206,6 +207,7 @@ class _DownloadTaskTileState extends State<_DownloadTaskTile> {
|
||||
Text(
|
||||
widget.task.message,
|
||||
style: ts.s12,
|
||||
maxLines: 3,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
LinearProgressIndicator(
|
||||
|
Reference in New Issue
Block a user