local favorites search page

This commit is contained in:
nyne
2024-11-02 20:29:44 +08:00
parent c4d867db89
commit 49174a7d8e
4 changed files with 74 additions and 26 deletions

View File

@@ -83,7 +83,9 @@ class FavoriteItem implements Comic {
int? get maxPage => null; int? get maxPage => null;
@override @override
String get sourceKey => type == ComicType.local ? 'local' : type.comicSource?.key ?? "Unknown:${type.value}"; String get sourceKey => type == ComicType.local
? 'local'
: type.comicSource?.key ?? "Unknown:${type.value}";
@override @override
double? get stars => null; double? get stars => null;
@@ -108,17 +110,17 @@ class FavoriteItem implements Comic {
static FavoriteItem fromJson(Map<String, dynamic> json) { static FavoriteItem fromJson(Map<String, dynamic> json) {
var type = json["type"] as int; var type = json["type"] as int;
if(type == 0 && json['coverPath'].toString().startsWith('http')) { if (type == 0 && json['coverPath'].toString().startsWith('http')) {
type = 'picacg'.hashCode; type = 'picacg'.hashCode;
} else if(type == 1) { } else if (type == 1) {
type = 'ehentai'.hashCode; type = 'ehentai'.hashCode;
} else if(type == 2) { } else if (type == 2) {
type = 'jm'.hashCode; type = 'jm'.hashCode;
} else if(type == 3) { } else if (type == 3) {
type = 'hitomi'.hashCode; type = 'hitomi'.hashCode;
} else if(type == 4) { } else if (type == 4) {
type = 'wnacg'.hashCode; type = 'wnacg'.hashCode;
} else if(type == 6) { } else if (type == 6) {
type = 'nhentai'.hashCode; type = 'nhentai'.hashCode;
} }
return FavoriteItem( return FavoriteItem(
@@ -132,21 +134,18 @@ class FavoriteItem implements Comic {
} }
} }
class FavoriteItemWithFolderInfo { class FavoriteItemWithFolderInfo extends FavoriteItem {
FavoriteItem comic;
String folder; String folder;
FavoriteItemWithFolderInfo(this.comic, this.folder); FavoriteItemWithFolderInfo(FavoriteItem item, this.folder)
: super(
@override id: item.id,
bool operator ==(Object other) { name: item.name,
return other is FavoriteItemWithFolderInfo && coverPath: item.coverPath,
other.comic == comic && author: item.author,
other.folder == folder; type: item.type,
} tags: item.tags,
);
@override
int get hashCode => comic.hashCode ^ folder.hashCode;
} }
class LocalFavoritesManager { class LocalFavoritesManager {
@@ -498,11 +497,11 @@ class LocalFavoritesManager {
} }
bool test(FavoriteItemWithFolderInfo comic, String keyword) { bool test(FavoriteItemWithFolderInfo comic, String keyword) {
if (comic.comic.name.contains(keyword)) { if (comic.name.contains(keyword)) {
return true; return true;
} else if (comic.comic.author.contains(keyword)) { } else if (comic.author.contains(keyword)) {
return true; return true;
} else if (comic.comic.tags.any((element) => element.contains(keyword))) { } else if (comic.tags.any((element) => element.contains(keyword))) {
return true; return true;
} }
return false; return false;
@@ -577,7 +576,7 @@ class LocalFavoritesManager {
void fromJson(String json) { void fromJson(String json) {
var data = jsonDecode(json); var data = jsonDecode(json);
var folder = data["name"]; var folder = data["name"];
if(folder == null || folder is! String) { if (folder == null || folder is! String) {
throw "Invalid data"; throw "Invalid data";
} }
if (folderNames.contains(folder)) { if (folderNames.contains(folder)) {
@@ -591,8 +590,7 @@ class LocalFavoritesManager {
for (var comic in data["comics"]) { for (var comic in data["comics"]) {
try { try {
addComic(folder, FavoriteItem.fromJson(comic)); addComic(folder, FavoriteItem.fromJson(comic));
} } catch (e) {
catch(e) {
Log.error("Import Data", e.toString()); Log.error("Import Data", e.toString());
} }
} }

View File

@@ -17,6 +17,7 @@ part 'favorite_actions.dart';
part 'side_bar.dart'; part 'side_bar.dart';
part 'local_favorites_page.dart'; part 'local_favorites_page.dart';
part 'network_favorites_page.dart'; part 'network_favorites_page.dart';
part 'local_search_page.dart';
const _kLeftBarWidth = 256.0; const _kLeftBarWidth = 256.0;

View File

@@ -0,0 +1,41 @@
part of 'favorites_page.dart';
class LocalSearchPage extends StatefulWidget {
const LocalSearchPage({super.key});
@override
State<LocalSearchPage> createState() => _LocalSearchPageState();
}
class _LocalSearchPageState extends State<LocalSearchPage> {
String keyword = '';
var comics = <FavoriteItemWithFolderInfo>[];
late final SearchBarController controller;
@override
void initState() {
super.initState();
controller = SearchBarController(onSearch: (text) {
keyword = text;
comics = LocalFavoritesManager().search(keyword);
setState(() {});
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SmoothCustomScrollView(slivers: [
SliverSearchBar(controller: controller),
SliverGridComics(
comics: comics,
badgeBuilder: (c) {
return (c as FavoriteItemWithFolderInfo).folder;
},
),
]),
);
}
}

View File

@@ -88,6 +88,13 @@ class _LeftBarState extends State<_LeftBar> implements FolderList {
const SizedBox(width: 12), const SizedBox(width: 12),
Text("Local".tl), Text("Local".tl),
const Spacer(), const Spacer(),
IconButton(
icon: const Icon(Icons.search),
color: context.colorScheme.primary,
onPressed: () {
context.to(() => const LocalSearchPage());
},
),
IconButton( IconButton(
icon: const Icon(Icons.add), icon: const Icon(Icons.add),
color: context.colorScheme.primary, color: context.colorScheme.primary,
@@ -112,6 +119,7 @@ class _LeftBarState extends State<_LeftBar> implements FolderList {
if (index == 0) { if (index == 0) {
return Container( return Container(
padding: const EdgeInsets.symmetric(vertical: 12), padding: const EdgeInsets.symmetric(vertical: 12),
margin: const EdgeInsets.only(top: 8),
decoration: BoxDecoration( decoration: BoxDecoration(
border: Border( border: Border(
top: BorderSide( top: BorderSide(