download comics in local favorites page

This commit is contained in:
2024-12-12 18:00:58 +08:00
parent 60c6be08c5
commit e9aa6fcf30
4 changed files with 93 additions and 31 deletions

View File

@@ -53,23 +53,57 @@ class _LocalFavoritesPageState extends State<_LocalFavoritesPage> {
super.initState();
}
void selectAll() {
setState(() {
selectedComics = comics.asMap().map((k, v) => MapEntry(v, true));
});
}
void invertSelection() {
setState(() {
comics.asMap().forEach((k, v) {
selectedComics[v] = !selectedComics.putIfAbsent(v, () => false);
});
selectedComics.removeWhere((k, v) => !v);
});
}
bool downloadComic(FavoriteItem c) {
var source = c.type.comicSource;
if (source != null) {
bool isDownloaded = LocalManager().isDownloaded(
c.id,
(c).type,
);
if (isDownloaded) {
return false;
}
LocalManager().addTask(ImagesDownloadTask(
source: source,
comicId: c.id,
comicTitle: c.title,
));
return true;
}
return false;
}
void downloadSelected() {
int count = 0;
for (var c in selectedComics.keys) {
if (downloadComic(c as FavoriteItem)) {
count++;
}
}
if (count > 0) {
context.showMessage(
message: "Added @c comics to download queue.".tlParams({"c": count}),
);
}
}
@override
Widget build(BuildContext context) {
void selectAll() {
setState(() {
selectedComics = comics.asMap().map((k, v) => MapEntry(v, true));
});
}
void invertSelection() {
setState(() {
comics.asMap().forEach((k, v) {
selectedComics[v] = !selectedComics.putIfAbsent(v, () => false);
});
selectedComics.removeWhere((k, v) => !v);
});
}
var body = Scaffold(
body: SmoothCustomScrollView(slivers: [
if (!searchMode && !multiSelectMode)
@@ -300,6 +334,11 @@ class _LocalFavoritesPageState extends State<_LocalFavoritesPage> {
},
);
}),
MenuEntry(
icon: Icons.download,
text: "Download".tl,
onClick: downloadSelected,
),
]),
],
)
@@ -336,6 +375,20 @@ class _LocalFavoritesPageState extends State<_LocalFavoritesPage> {
SliverGridComics(
comics: comics,
selections: selectedComics,
menuBuilder: (c) {
return [
MenuEntry(
icon: Icons.download,
text: "Download".tl,
onClick: () {
downloadComic(c as FavoriteItem);
context.showMessage(
message: "Download started".tl,
);
},
),
];
},
onTap: multiSelectMode
? (c) {
setState(() {
@@ -425,7 +478,7 @@ class _LocalFavoritesPageState extends State<_LocalFavoritesPage> {
padding: EdgeInsets.only(bottom: context.padding.bottom + 16),
child: Container(
constraints:
const BoxConstraints(maxHeight: 700, maxWidth: 500),
const BoxConstraints(maxHeight: 700, maxWidth: 500),
child: Column(
children: [
Expanded(
@@ -443,7 +496,7 @@ class _LocalFavoritesPageState extends State<_LocalFavoritesPage> {
targetFolders = LocalFavoritesManager()
.folderNames
.where((folder) =>
folder != favPage.folder)
folder != favPage.folder)
.toList();
});
});
@@ -482,14 +535,14 @@ class _LocalFavoritesPageState extends State<_LocalFavoritesPage> {
onChanged: disabled
? null
: (v) {
setState(() {
if (v!) {
selectedLocalFolders.add(folder);
} else {
selectedLocalFolders.remove(folder);
}
});
},
setState(() {
if (v!) {
selectedLocalFolders.add(folder);
} else {
selectedLocalFolders.remove(folder);
}
});
},
);
},
),
@@ -597,9 +650,12 @@ class _ReorderComicsPageState extends State<_ReorderComicsPage> {
}
Color lightenColor(Color color, double lightenValue) {
int red = (_floatToInt8(color.r) + ((255 - color.r) * lightenValue)).round();
int green = (_floatToInt8(color.g) * 255 + ((255 - color.g) * lightenValue)).round();
int blue = (_floatToInt8(color.b) * 255 + ((255 - color.b) * lightenValue)).round();
int red =
(_floatToInt8(color.r) + ((255 - color.r) * lightenValue)).round();
int green = (_floatToInt8(color.g) * 255 + ((255 - color.g) * lightenValue))
.round();
int blue = (_floatToInt8(color.b) * 255 + ((255 - color.b) * lightenValue))
.round();
return Color.fromARGB(_floatToInt8(color.a), red, green, blue);
}