diff --git a/lib/foundation/favorites.dart b/lib/foundation/favorites.dart index d8cc0bb..c50f4ed 100644 --- a/lib/foundation/favorites.dart +++ b/lib/foundation/favorites.dart @@ -83,7 +83,9 @@ class FavoriteItem implements Comic { int? get maxPage => null; @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 double? get stars => null; @@ -108,17 +110,17 @@ class FavoriteItem implements Comic { static FavoriteItem fromJson(Map json) { 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; - } else if(type == 1) { + } else if (type == 1) { type = 'ehentai'.hashCode; - } else if(type == 2) { + } else if (type == 2) { type = 'jm'.hashCode; - } else if(type == 3) { + } else if (type == 3) { type = 'hitomi'.hashCode; - } else if(type == 4) { + } else if (type == 4) { type = 'wnacg'.hashCode; - } else if(type == 6) { + } else if (type == 6) { type = 'nhentai'.hashCode; } return FavoriteItem( @@ -132,21 +134,18 @@ class FavoriteItem implements Comic { } } -class FavoriteItemWithFolderInfo { - FavoriteItem comic; +class FavoriteItemWithFolderInfo extends FavoriteItem { String folder; - FavoriteItemWithFolderInfo(this.comic, this.folder); - - @override - bool operator ==(Object other) { - return other is FavoriteItemWithFolderInfo && - other.comic == comic && - other.folder == folder; - } - - @override - int get hashCode => comic.hashCode ^ folder.hashCode; + FavoriteItemWithFolderInfo(FavoriteItem item, this.folder) + : super( + id: item.id, + name: item.name, + coverPath: item.coverPath, + author: item.author, + type: item.type, + tags: item.tags, + ); } class LocalFavoritesManager { @@ -498,11 +497,11 @@ class LocalFavoritesManager { } bool test(FavoriteItemWithFolderInfo comic, String keyword) { - if (comic.comic.name.contains(keyword)) { + if (comic.name.contains(keyword)) { return true; - } else if (comic.comic.author.contains(keyword)) { + } else if (comic.author.contains(keyword)) { return true; - } else if (comic.comic.tags.any((element) => element.contains(keyword))) { + } else if (comic.tags.any((element) => element.contains(keyword))) { return true; } return false; @@ -577,7 +576,7 @@ class LocalFavoritesManager { void fromJson(String json) { var data = jsonDecode(json); var folder = data["name"]; - if(folder == null || folder is! String) { + if (folder == null || folder is! String) { throw "Invalid data"; } if (folderNames.contains(folder)) { @@ -591,8 +590,7 @@ class LocalFavoritesManager { for (var comic in data["comics"]) { try { addComic(folder, FavoriteItem.fromJson(comic)); - } - catch(e) { + } catch (e) { Log.error("Import Data", e.toString()); } } diff --git a/lib/pages/favorites/favorites_page.dart b/lib/pages/favorites/favorites_page.dart index e3cbc09..f069923 100644 --- a/lib/pages/favorites/favorites_page.dart +++ b/lib/pages/favorites/favorites_page.dart @@ -17,6 +17,7 @@ part 'favorite_actions.dart'; part 'side_bar.dart'; part 'local_favorites_page.dart'; part 'network_favorites_page.dart'; +part 'local_search_page.dart'; const _kLeftBarWidth = 256.0; diff --git a/lib/pages/favorites/local_search_page.dart b/lib/pages/favorites/local_search_page.dart new file mode 100644 index 0000000..f798bc5 --- /dev/null +++ b/lib/pages/favorites/local_search_page.dart @@ -0,0 +1,41 @@ +part of 'favorites_page.dart'; + +class LocalSearchPage extends StatefulWidget { + const LocalSearchPage({super.key}); + + @override + State createState() => _LocalSearchPageState(); +} + +class _LocalSearchPageState extends State { + String keyword = ''; + + var comics = []; + + 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; + }, + ), + ]), + ); + } +} diff --git a/lib/pages/favorites/side_bar.dart b/lib/pages/favorites/side_bar.dart index 71839f6..acc403f 100644 --- a/lib/pages/favorites/side_bar.dart +++ b/lib/pages/favorites/side_bar.dart @@ -88,6 +88,13 @@ class _LeftBarState extends State<_LeftBar> implements FolderList { const SizedBox(width: 12), Text("Local".tl), const Spacer(), + IconButton( + icon: const Icon(Icons.search), + color: context.colorScheme.primary, + onPressed: () { + context.to(() => const LocalSearchPage()); + }, + ), IconButton( icon: const Icon(Icons.add), color: context.colorScheme.primary, @@ -112,6 +119,7 @@ class _LeftBarState extends State<_LeftBar> implements FolderList { if (index == 0) { return Container( padding: const EdgeInsets.symmetric(vertical: 12), + margin: const EdgeInsets.only(top: 8), decoration: BoxDecoration( border: Border( top: BorderSide(