From 5c162d2800cdb4d22d2db92bbdbffa710147b0fb Mon Sep 17 00:00:00 2001 From: nyne Date: Sat, 15 Feb 2025 16:16:06 +0800 Subject: [PATCH] Display number on local favorites. --- lib/foundation/image_favorites.dart | 8 +++++++- lib/pages/home_page.dart | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/foundation/image_favorites.dart b/lib/foundation/image_favorites.dart index 865ef9f..61a9b76 100644 --- a/lib/foundation/image_favorites.dart +++ b/lib/foundation/image_favorites.dart @@ -396,7 +396,7 @@ class ImageFavoriteManager with ChangeNotifier { var token = ServicesBinding.rootIsolateToken!; var count = ImageFavoriteManager().length; if (count == 0) { - return Future.value(ImageFavoritesComputed([], [], [])); + return Future.value(ImageFavoritesComputed([], [], [], 0)); } else if (count > 100) { return Isolate.run(() async { BackgroundIsolateBinaryMessenger.ensureInitialized(token); @@ -436,8 +436,10 @@ class ImageFavoriteManager with ChangeNotifier { Map authorCount = {}; Map comicImageCount = {}; Map comicMaxPages = {}; + int count = 0; for (var comic in comics) { + count += comic.images.length; for (var tag in comic.tags) { String finalTag = tag; tagCount[finalTag] = (tagCount[finalTag] ?? 0) + 1; @@ -492,6 +494,7 @@ class ImageFavoriteManager with ChangeNotifier { .map((comic) => TextWithCount(comic.key.title, comic.value)) .take(maxLength) .toList(), + count, ); } @@ -524,11 +527,14 @@ class ImageFavoritesComputed { /// 基于喜欢的图片数排序 final List comics; + final int count; + /// 计算后的图片收藏数据 const ImageFavoritesComputed( this.tags, this.authors, this.comics, + this.count, ); bool get isEmpty => tags.isEmpty && authors.isEmpty && comics.isEmpty; diff --git a/lib/pages/home_page.dart b/lib/pages/home_page.dart index 888438b..f11e6d2 100644 --- a/lib/pages/home_page.dart +++ b/lib/pages/home_page.dart @@ -823,6 +823,20 @@ class _ImageFavoritesState extends State { Center( child: Text('Image Favorites'.tl, style: ts.s18), ), + if (hasData) + Container( + margin: const EdgeInsets.symmetric(horizontal: 8), + padding: const EdgeInsets.symmetric( + horizontal: 8, vertical: 2), + decoration: BoxDecoration( + color: Theme.of(context).colorScheme.secondaryContainer, + borderRadius: BorderRadius.circular(8), + ), + child: Text( + imageFavoritesCompute!.count.toString(), + style: ts.s12, + ), + ), const Spacer(), const Icon(Icons.arrow_right), ],