From e915f1922f1063efcbec878ee8b5341ff6d7b9b5 Mon Sep 17 00:00:00 2001 From: Thibault Deckers Date: Mon, 30 Mar 2020 18:05:03 +0900 Subject: [PATCH] show/hide filter bar, show/hide headers --- lib/model/collection_lens.dart | 24 ++++++++++++-- lib/model/image_entry.dart | 2 +- lib/widgets/album/collection_app_bar.dart | 17 ++++++---- lib/widgets/album/collection_section.dart | 32 +++++++++++-------- lib/widgets/album/search/search_delegate.dart | 1 - lib/widgets/album/thumbnail_collection.dart | 2 ++ 6 files changed, 54 insertions(+), 24 deletions(-) diff --git a/lib/model/collection_lens.dart b/lib/model/collection_lens.dart index 023ae962d..cf3027fc4 100644 --- a/lib/model/collection_lens.dart +++ b/lib/model/collection_lens.dart @@ -2,9 +2,11 @@ import 'dart:async'; import 'dart:collection'; import 'package:aves/model/collection_source.dart'; +import 'package:aves/model/filters/album.dart'; import 'package:aves/model/filters/filters.dart'; import 'package:aves/model/image_entry.dart'; import 'package:aves/model/settings.dart'; +import 'package:aves/utils/change_notifier.dart'; import 'package:collection/collection.dart'; import 'package:flutter/foundation.dart'; @@ -13,6 +15,7 @@ class CollectionLens with ChangeNotifier { final Set filters; GroupFactor groupFactor; SortFactor sortFactor; + final AChangeNotifier filterChangeNotifier = AChangeNotifier(); List _filteredEntries; List _subscriptions = []; @@ -63,11 +66,24 @@ class CollectionLens with ChangeNotifier { int get entryCount => _filteredEntries.length; - int get imageCount => _filteredEntries.where((entry) => !entry.isVideo).length; + List _sortedEntries; - int get videoCount => _filteredEntries.where((entry) => entry.isVideo).length; + List get sortedEntries { + if (_sortedEntries == null) { + _sortedEntries = List.unmodifiable(sections.entries.expand((e) => e.value)); + } + return _sortedEntries; + } - List get sortedEntries => List.unmodifiable(sections.entries.expand((e) => e.value)); + bool get showHeaders { + if (sortFactor == SortFactor.size) return false; + + final albumSections = sortFactor == SortFactor.name || (sortFactor == SortFactor.date && groupFactor == GroupFactor.album); + final filterByAlbum = filters.any((f) => f is AlbumFilter); + if (albumSections && filterByAlbum) return false; + + return true; + } Object heroTag(ImageEntry entry) => '$hashCode${entry.uri}'; @@ -90,6 +106,7 @@ class CollectionLens with ChangeNotifier { _applyFilters(); _applySort(); _applyGroup(); + filterChangeNotifier.notifyListeners(); } void sort(SortFactor sortFactor) { @@ -156,6 +173,7 @@ class CollectionLens with ChangeNotifier { sections = Map.unmodifiable(SplayTreeMap.of(byAlbum, compare)); break; } + _sortedEntries = null; notifyListeners(); } diff --git a/lib/model/image_entry.dart b/lib/model/image_entry.dart index 9dcc42bb5..177701c5b 100644 --- a/lib/model/image_entry.dart +++ b/lib/model/image_entry.dart @@ -30,7 +30,7 @@ class ImageEntry { AddressDetails addressDetails; final AChangeNotifier imageChangeNotifier = AChangeNotifier(), metadataChangeNotifier = AChangeNotifier(), addressChangeNotifier = AChangeNotifier(); - final isFavouriteNotifier = ValueNotifier(false); + final ValueNotifier isFavouriteNotifier = ValueNotifier(false); ImageEntry({ this.uri, diff --git a/lib/widgets/album/collection_app_bar.dart b/lib/widgets/album/collection_app_bar.dart index 0fd8ada1a..7b59b58cf 100644 --- a/lib/widgets/album/collection_app_bar.dart +++ b/lib/widgets/album/collection_app_bar.dart @@ -69,12 +69,17 @@ class _CollectionAppBarState extends State with SingleTickerPr valueListenable: stateNotifier, builder: (context, state, child) { debugPrint('$runtimeType builder state=$state'); - return SliverAppBar( - leading: _buildAppBarLeading(), - title: _buildAppBarTitle(), - actions: _buildActions(), - bottom: FilterBar(), - floating: true, + return Consumer( + builder: (context, collection, child) => AnimatedBuilder( + animation: collection.filterChangeNotifier, + builder: (context, child) => SliverAppBar( + leading: _buildAppBarLeading(), + title: _buildAppBarTitle(), + actions: _buildActions(), + bottom: collection.filters.isNotEmpty ? FilterBar() : null, + floating: true, + ), + ), ); }, ); diff --git a/lib/widgets/album/collection_section.dart b/lib/widgets/album/collection_section.dart index 7a8b3f2dd..d135dbbf5 100644 --- a/lib/widgets/album/collection_section.dart +++ b/lib/widgets/album/collection_section.dart @@ -14,12 +14,14 @@ class SectionSliver extends StatelessWidget { final CollectionLens collection; final dynamic sectionKey; final int columnCount; + final bool showHeader; const SectionSliver({ Key key, @required this.collection, @required this.sectionKey, @required this.columnCount, + @required this.showHeader, }) : super(key: key); @override @@ -49,15 +51,17 @@ class SectionSliver extends StatelessWidget { ), ); - return SliverStickyHeader( - header: SectionHeader( - collection: collection, - sections: sections, - sectionKey: sectionKey, - ), - sliver: sliver, - overlapsContent: false, - ); + return showHeader + ? SliverStickyHeader( + header: SectionHeader( + collection: collection, + sections: sections, + sectionKey: sectionKey, + ), + sliver: sliver, + overlapsContent: false, + ) + : sliver; } } @@ -133,7 +137,7 @@ class SectionHeader extends StatelessWidget { @override Widget build(BuildContext context) { - Widget header = const SizedBox.shrink(); + Widget header; switch (collection.sortFactor) { case SortFactor.date: if (collection.sortFactor == SortFactor.date) { @@ -156,9 +160,11 @@ class SectionHeader extends StatelessWidget { header = _buildAlbumSectionHeader(context); break; } - return IgnorePointer( - child: header, - ); + return header != null + ? IgnorePointer( + child: header, + ) + : const SizedBox.shrink(); } Widget _buildAlbumSectionHeader(BuildContext context) { diff --git a/lib/widgets/album/search/search_delegate.dart b/lib/widgets/album/search/search_delegate.dart index 8c1e16f2f..811b95997 100644 --- a/lib/widgets/album/search/search_delegate.dart +++ b/lib/widgets/album/search/search_delegate.dart @@ -59,7 +59,6 @@ class ImageSearchDelegate extends SearchDelegate { child: ValueListenableBuilder( valueListenable: expandedSectionNotifier, builder: (context, expandedSection, child) { - debugPrint('builder expandedSection=$expandedSection'); return ListView( children: [ _buildFilterRow( diff --git a/lib/widgets/album/thumbnail_collection.dart b/lib/widgets/album/thumbnail_collection.dart index 64caa9e07..80048f504 100644 --- a/lib/widgets/album/thumbnail_collection.dart +++ b/lib/widgets/album/thumbnail_collection.dart @@ -25,6 +25,7 @@ class ThumbnailCollection extends StatelessWidget { final collection = Provider.of(context); final sections = collection.sections; final sectionKeys = sections.keys.toList(); + final showHeaders = collection.showHeaders; double topPadding = 0; if (appBar != null) { @@ -64,6 +65,7 @@ class ThumbnailCollection extends StatelessWidget { collection: collection, sectionKey: sectionKey, columnCount: columnCount, + showHeader: showHeaders, )), SliverToBoxAdapter( child: Selector(