mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 15:57:25 +00:00
favorites page
This commit is contained in:
@@ -1,61 +1,115 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:venera/components/components.dart';
|
||||
import 'package:venera/foundation/app.dart';
|
||||
import 'package:venera/foundation/favorites.dart';
|
||||
import 'package:venera/utils/translations.dart';
|
||||
part of 'favorites_page.dart';
|
||||
|
||||
/// Open a dialog to create a new favorite folder.
|
||||
Future<void> newFolder() async {
|
||||
return showDialog(context: App.rootContext, builder: (context) {
|
||||
var controller = TextEditingController();
|
||||
var folders = LocalFavoritesManager().folderNames;
|
||||
String? error;
|
||||
return showDialog(
|
||||
context: App.rootContext,
|
||||
builder: (context) {
|
||||
var controller = TextEditingController();
|
||||
var folders = LocalFavoritesManager().folderNames;
|
||||
String? error;
|
||||
|
||||
return StatefulBuilder(builder: (context, setState) {
|
||||
return ContentDialog(
|
||||
title: "New Folder".tl,
|
||||
content: Column(
|
||||
children: [
|
||||
TextField(
|
||||
controller: controller,
|
||||
decoration: InputDecoration(
|
||||
hintText: "Folder Name".tl,
|
||||
errorText: error,
|
||||
return StatefulBuilder(builder: (context, setState) {
|
||||
return ContentDialog(
|
||||
title: "New Folder".tl,
|
||||
content: Column(
|
||||
children: [
|
||||
TextField(
|
||||
controller: controller,
|
||||
decoration: InputDecoration(
|
||||
hintText: "Folder Name".tl,
|
||||
errorText: error,
|
||||
),
|
||||
onChanged: (s) {
|
||||
if (error != null) {
|
||||
setState(() {
|
||||
error = null;
|
||||
});
|
||||
}
|
||||
},
|
||||
)
|
||||
],
|
||||
).paddingHorizontal(16),
|
||||
actions: [
|
||||
FilledButton(
|
||||
onPressed: () {
|
||||
var e = validateFolderName(controller.text);
|
||||
if (e != null) {
|
||||
setState(() {
|
||||
error = e;
|
||||
});
|
||||
} else {
|
||||
LocalFavoritesManager().createFolder(controller.text);
|
||||
context.pop();
|
||||
}
|
||||
},
|
||||
child: Text("Create".tl),
|
||||
),
|
||||
onChanged: (s) {
|
||||
if(error != null) {
|
||||
setState(() {
|
||||
error = null;
|
||||
});
|
||||
],
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
String? validateFolderName(String newFolderName) {
|
||||
var folders = LocalFavoritesManager().folderNames;
|
||||
if (newFolderName.isEmpty) {
|
||||
return "Folder name cannot be empty".tl;
|
||||
} else if (newFolderName.length > 50) {
|
||||
return "Folder name is too long".tl;
|
||||
} else if (folders.contains(newFolderName)) {
|
||||
return "Folder already exists".tl;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
void addFavorite(Comic comic) {
|
||||
var folders = LocalFavoritesManager().folderNames;
|
||||
|
||||
showDialog(
|
||||
context: App.rootContext,
|
||||
builder: (context) {
|
||||
String? selectedFolder;
|
||||
|
||||
return StatefulBuilder(builder: (context, setState) {
|
||||
return ContentDialog(
|
||||
title: "Select a folder".tl,
|
||||
content: ListTile(
|
||||
title: Text("Folder".tl),
|
||||
trailing: Select(
|
||||
current: selectedFolder,
|
||||
values: folders,
|
||||
minWidth: 112,
|
||||
onTap: (v) {
|
||||
setState(() {
|
||||
selectedFolder = folders[v];
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
FilledButton(
|
||||
onPressed: () {
|
||||
if (selectedFolder != null) {
|
||||
LocalFavoritesManager().addComic(
|
||||
selectedFolder!,
|
||||
FavoriteItem(
|
||||
id: comic.id,
|
||||
name: comic.title,
|
||||
coverPath: comic.cover,
|
||||
author: comic.subtitle ?? '',
|
||||
type: ComicType(comic.sourceKey.hashCode),
|
||||
tags: comic.tags ?? [],
|
||||
),
|
||||
);
|
||||
context.pop();
|
||||
}
|
||||
},
|
||||
)
|
||||
child: Text("Confirm".tl),
|
||||
),
|
||||
],
|
||||
).paddingHorizontal(16),
|
||||
actions: [
|
||||
FilledButton(
|
||||
onPressed: () {
|
||||
if(controller.text.isEmpty) {
|
||||
setState(() {
|
||||
error = "Folder name cannot be empty".tl;
|
||||
});
|
||||
} else if(controller.text.length > 50) {
|
||||
setState(() {
|
||||
error = "Folder name is too long".tl;
|
||||
});
|
||||
} else if(folders.contains(controller.text)) {
|
||||
setState(() {
|
||||
error = "Folder already exists".tl;
|
||||
});
|
||||
} else {
|
||||
LocalFavoritesManager().createFolder(controller.text);
|
||||
context.pop();
|
||||
}
|
||||
},
|
||||
child: Text("Create".tl),
|
||||
),
|
||||
],
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user