mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 07:47:24 +00:00
favorites page
This commit is contained in:
158
lib/pages/favorites/favorites_page.dart
Normal file
158
lib/pages/favorites/favorites_page.dart
Normal file
@@ -0,0 +1,158 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_reorderable_grid_view/widgets/reorderable_builder.dart';
|
||||
import 'package:venera/components/components.dart';
|
||||
import 'package:venera/foundation/app.dart';
|
||||
import 'package:venera/foundation/appdata.dart';
|
||||
import 'package:venera/foundation/comic_source/comic_source.dart';
|
||||
import 'package:venera/foundation/comic_type.dart';
|
||||
import 'package:venera/foundation/favorites.dart';
|
||||
import 'package:venera/foundation/res.dart';
|
||||
import 'package:venera/utils/translations.dart';
|
||||
|
||||
part 'favorite_actions.dart';
|
||||
part 'side_bar.dart';
|
||||
part 'local_favorites_page.dart';
|
||||
part 'network_favorites_page.dart';
|
||||
|
||||
const _kLeftBarWidth = 256.0;
|
||||
|
||||
const _kTwoPanelChangeWidth = 720.0;
|
||||
|
||||
class FavoritesPage extends StatefulWidget {
|
||||
const FavoritesPage({super.key});
|
||||
|
||||
@override
|
||||
State<FavoritesPage> createState() => _FavoritesPageState();
|
||||
}
|
||||
|
||||
class _FavoritesPageState extends State<FavoritesPage> {
|
||||
String? folder;
|
||||
|
||||
bool isNetwork = false;
|
||||
|
||||
FolderList? folderList;
|
||||
|
||||
void setFolder(bool isNetwork, String? folder) {
|
||||
setState(() {
|
||||
this.isNetwork = isNetwork;
|
||||
this.folder = folder;
|
||||
});
|
||||
folderList?.update();
|
||||
appdata.implicitData['favoriteFolder'] = {
|
||||
'name': folder,
|
||||
'isNetwork': isNetwork,
|
||||
};
|
||||
appdata.writeImplicitData();
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
var data = appdata.implicitData['favoriteFolder'];
|
||||
if(data != null){
|
||||
folder = data['name'];
|
||||
isNetwork = data['isNetwork'] ?? false;
|
||||
}
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return IconTheme(
|
||||
data: IconThemeData(color: Theme.of(context).colorScheme.secondary),
|
||||
child: Stack(
|
||||
children: [
|
||||
AnimatedPositioned(
|
||||
left: context.width <= _kTwoPanelChangeWidth ? -_kLeftBarWidth : 0,
|
||||
top: 0,
|
||||
bottom: 0,
|
||||
duration: const Duration(milliseconds: 200),
|
||||
child: (const _LeftBar()).fixWidth(_kLeftBarWidth),
|
||||
),
|
||||
Positioned(
|
||||
top: 0,
|
||||
left: context.width <= _kTwoPanelChangeWidth ? 0 : _kLeftBarWidth,
|
||||
right: 0,
|
||||
bottom: 0,
|
||||
child: buildBody(),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void showFolderSelector() {
|
||||
Navigator.of(App.rootContext).push(PageRouteBuilder(
|
||||
barrierDismissible: true,
|
||||
fullscreenDialog: true,
|
||||
opaque: false,
|
||||
barrierColor: Colors.black.withOpacity(0.36),
|
||||
pageBuilder: (context, animation, secondary) {
|
||||
return Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Material(
|
||||
color: context.colorScheme.surfaceContainerLow,
|
||||
child: SizedBox(
|
||||
width: 256,
|
||||
child: _LeftBar(
|
||||
withAppbar: true,
|
||||
favPage: this,
|
||||
onSelected: () {
|
||||
context.pop();
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
transitionsBuilder: (context, animation, secondary, child) {
|
||||
var offset =
|
||||
Tween<Offset>(begin: const Offset(-1, 0), end: const Offset(0, 0));
|
||||
return SlideTransition(
|
||||
position: offset.animate(CurvedAnimation(
|
||||
parent: animation,
|
||||
curve: Curves.fastOutSlowIn,
|
||||
)),
|
||||
child: child,
|
||||
);
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
Widget buildBody() {
|
||||
if (folder == null) {
|
||||
return CustomScrollView(
|
||||
slivers: [
|
||||
SliverAppbar(
|
||||
leading: Tooltip(
|
||||
message: "Folders".tl,
|
||||
child: context.width <= _kTwoPanelChangeWidth
|
||||
? IconButton(
|
||||
icon: const Icon(Icons.menu),
|
||||
color: context.colorScheme.primary,
|
||||
onPressed: showFolderSelector,
|
||||
)
|
||||
: null,
|
||||
),
|
||||
title: Text("Unselected".tl),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
if (!isNetwork) {
|
||||
return _LocalFavoritesPage(folder: folder!, key: Key(folder!));
|
||||
} else {
|
||||
var favoriteData = getFavoriteDataOrNull(folder!);
|
||||
if (favoriteData == null) {
|
||||
return const Center(child: Text("Unknown source"));
|
||||
} else {
|
||||
return NetworkFavoritePage(favoriteData, key: Key(folder!));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
abstract interface class FolderList {
|
||||
void update();
|
||||
|
||||
void updateFolders();
|
||||
}
|
Reference in New Issue
Block a user