improve favorites page

This commit is contained in:
nyne
2024-10-18 13:07:57 +08:00
parent 30b3256eec
commit 700630e317
6 changed files with 221 additions and 76 deletions

View File

@@ -1,3 +1,5 @@
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_reorderable_grid_view/widgets/reorderable_builder.dart';
import 'package:venera/components/components.dart';
@@ -90,9 +92,8 @@ class _FavoritesPageState extends State<FavoritesPage> {
return Align(
alignment: Alignment.centerLeft,
child: Material(
color: context.colorScheme.surfaceContainerLow,
child: SizedBox(
width: 256,
width: min(300, context.width-16),
child: _LeftBar(
withAppbar: true,
favPage: this,

View File

@@ -1,5 +1,59 @@
part of 'favorites_page.dart';
// TODO: Add a menu option to delete a comic from favorites
Future<bool> _deleteComic(String cid, String? fid, String sourceKey) async {
var source = ComicSource.find(sourceKey);
if (source == null) {
return false;
}
var result = false;
await showDialog(
context: App.rootContext,
builder: (context) {
bool loading = false;
return StatefulBuilder(builder: (context, setState) {
return ContentDialog(
title: "Delete".tl,
content: Text("Are you sure you want to delete this comic?".tl)
.paddingHorizontal(16),
actions: [
Button.filled(
isLoading: loading,
color: context.colorScheme.error,
onPressed: () async {
setState(() {
loading = true;
});
var res = await source.favoriteData!.addOrDelFavorite!(
cid,
fid ?? '',
false,
);
if (res.success) {
context.showMessage(message: "Deleted".tl);
result = true;
context.pop();
} else {
setState(() {
loading = false;
});
context.showMessage(message: res.errorMessage!);
}
},
child: Text("Confirm".tl),
),
],
);
});
},
);
return result;
}
class NetworkFavoritePage extends StatelessWidget {
const NetworkFavoritePage(this.data, {super.key});
@@ -14,13 +68,16 @@ class NetworkFavoritePage extends StatelessWidget {
}
class _NormalFavoritePage extends StatelessWidget {
const _NormalFavoritePage(this.data);
_NormalFavoritePage(this.data);
final FavoriteData data;
final comicListKey = GlobalKey<ComicListState>();
@override
Widget build(BuildContext context) {
return ComicList(
key: comicListKey,
leadingSliver: SliverAppbar(
leading: Tooltip(
message: "Folders".tl,
@@ -52,6 +109,20 @@ class _NormalFavoritePage extends StatelessWidget {
title: Text(data.title),
),
loadPage: (i) => data.loadComic(i),
menuBuilder: (comic) {
return [
MenuEntry(
icon: Icons.delete_outline,
text: "Remove".tl,
onClick: () async {
var res = await _deleteComic(comic.id, null, comic.sourceKey);
if (res) {
comicListKey.currentState!.remove(comic);
}
},
),
];
},
);
}
}
@@ -413,7 +484,7 @@ class _CreateFolderDialogState extends State<_CreateFolderDialog> {
}
class _FavoriteFolder extends StatelessWidget {
const _FavoriteFolder(this.data, this.folderID, this.title);
_FavoriteFolder(this.data, this.folderID, this.title);
final FavoriteData data;
@@ -421,13 +492,30 @@ class _FavoriteFolder extends StatelessWidget {
final String title;
final comicListKey = GlobalKey<ComicListState>();
@override
Widget build(BuildContext context) {
return ComicList(
key: comicListKey,
leadingSliver: SliverAppbar(
title: Text(title),
),
loadPage: (i) => data.loadComic(i, folderID),
menuBuilder: (comic) {
return [
MenuEntry(
icon: Icons.delete_outline,
text: "Remove".tl,
onClick: () async {
var res = await _deleteComic(comic.id, null, comic.sourceKey);
if (res) {
comicListKey.currentState!.remove(comic);
}
},
),
];
},
);
}
}

View File

@@ -61,13 +61,18 @@ class _LeftBarState extends State<_LeftBar> implements FolderList {
const SizedBox(width: 8),
const CloseButton(),
const SizedBox(width: 8),
Text("Folders".tl, style: ts.s18,),
Text(
"Folders".tl,
style: ts.s18,
),
],
),
).paddingTop(context.padding.top),
Expanded(
child: ListView.builder(
padding: widget.withAppbar ? EdgeInsets.zero : EdgeInsets.only(top: context.padding.top),
padding: widget.withAppbar
? EdgeInsets.zero
: EdgeInsets.only(top: context.padding.top),
itemCount: folders.length + networkFolders.length + 2,
itemBuilder: (context, index) {
if (index == 0) {
@@ -76,8 +81,11 @@ class _LeftBarState extends State<_LeftBar> implements FolderList {
child: Row(
children: [
const SizedBox(width: 16),
const Icon(Icons.local_activity),
const SizedBox(width: 8),
Icon(
Icons.local_activity,
color: context.colorScheme.secondary,
),
const SizedBox(width: 12),
Text("Local".tl),
const Spacer(),
IconButton(
@@ -103,12 +111,23 @@ class _LeftBarState extends State<_LeftBar> implements FolderList {
index -= folders.length;
if (index == 0) {
return Container(
padding: const EdgeInsets.symmetric(vertical: 8),
padding: const EdgeInsets.symmetric(vertical: 12),
decoration: BoxDecoration(
border: Border(
top: BorderSide(
color: context.colorScheme.outlineVariant,
width: 0.6,
),
),
),
child: Row(
children: [
const SizedBox(width: 16),
const Icon(Icons.cloud),
const SizedBox(width: 8),
Icon(
Icons.cloud,
color: context.colorScheme.secondary,
),
const SizedBox(width: 12),
Text("Network".tl),
],
),