diff --git a/lib/services/state_services/torrent_service.dart b/lib/services/state_services/torrent_service.dart index c7e52d1..9e462e2 100644 --- a/lib/services/state_services/torrent_service.dart +++ b/lib/services/state_services/torrent_service.dart @@ -196,6 +196,12 @@ class TorrentService extends ChangeNotifier { return torrentsList.where((torrent) => torrent.label == label).toList(); } + /// Returns the count of torrents matching a given [Filter] + int getFilterCount(Filter filter) { + List? filtered = _filterList(torrentsList.value, filter); + return filtered?.length ?? 0; + } + /// Reloads list of [Torrent]s from seedbox refreshTorrentList() async { log.v("Torrent refresh function called"); diff --git a/lib/ui/widgets/dumb_widgets/filter_tile_list_widgets.dart b/lib/ui/widgets/dumb_widgets/filter_tile_list_widgets.dart index 502ae86..4974217 100644 --- a/lib/ui/widgets/dumb_widgets/filter_tile_list_widgets.dart +++ b/lib/ui/widgets/dumb_widgets/filter_tile_list_widgets.dart @@ -15,6 +15,7 @@ class FilterTile extends StatelessWidget { Widget build(BuildContext context) { bool isSelected = (model.selectedFilter == filter && !model.isLabelSelected); + int count = model.getFilterCount(filter); return Container( color: isSelected ? Theme.of(context).colorScheme.secondary : null, child: ListTile( @@ -36,6 +37,25 @@ class FilterTile extends StatelessWidget { ? Colors.black : Colors.white), ), + trailing: Container( + padding: EdgeInsets.symmetric(horizontal: 8, vertical: 2), + decoration: BoxDecoration( + color: isSelected + ? Colors.white.withOpacity(0.3) + : Theme.of(context).colorScheme.secondary.withOpacity(0.15), + borderRadius: BorderRadius.circular(12), + ), + child: Text( + '$count', + style: TextStyle( + fontSize: 12, + fontWeight: FontWeight.w600, + color: isSelected + ? Colors.white + : Theme.of(context).colorScheme.secondary, + ), + ), + ), onTap: () { model.changeFilter(filter); Navigator.pop(context); diff --git a/lib/ui/widgets/smart_widgets/drawer/drawer_viewmodel.dart b/lib/ui/widgets/smart_widgets/drawer/drawer_viewmodel.dart index 764a03a..e93a291 100644 --- a/lib/ui/widgets/smart_widgets/drawer/drawer_viewmodel.dart +++ b/lib/ui/widgets/smart_widgets/drawer/drawer_viewmodel.dart @@ -47,6 +47,11 @@ class DrawerViewModel extends BaseViewModel { get listOfLabels => _torrentService?.listOfLabels; + /// Returns the count of torrents matching a given [Filter] + int getFilterCount(Filter filter) { + return _torrentService?.getFilterCount(filter) ?? 0; + } + Filter get selectedFilter => _torrentService?.selectedFilter; String get selectedLabel => _torrentService?.selectedLabel;