show/hide filter bar, show/hide headers
This commit is contained in:
parent
4ab75fe218
commit
e915f1922f
6 changed files with 54 additions and 24 deletions
|
@ -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<CollectionFilter> filters;
|
||||
GroupFactor groupFactor;
|
||||
SortFactor sortFactor;
|
||||
final AChangeNotifier filterChangeNotifier = AChangeNotifier();
|
||||
|
||||
List<ImageEntry> _filteredEntries;
|
||||
List<StreamSubscription> _subscriptions = [];
|
||||
|
@ -63,11 +66,24 @@ class CollectionLens with ChangeNotifier {
|
|||
|
||||
int get entryCount => _filteredEntries.length;
|
||||
|
||||
int get imageCount => _filteredEntries.where((entry) => !entry.isVideo).length;
|
||||
List<ImageEntry> _sortedEntries;
|
||||
|
||||
int get videoCount => _filteredEntries.where((entry) => entry.isVideo).length;
|
||||
List<ImageEntry> get sortedEntries {
|
||||
if (_sortedEntries == null) {
|
||||
_sortedEntries = List.unmodifiable(sections.entries.expand((e) => e.value));
|
||||
}
|
||||
return _sortedEntries;
|
||||
}
|
||||
|
||||
List<ImageEntry> 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();
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ class ImageEntry {
|
|||
AddressDetails addressDetails;
|
||||
|
||||
final AChangeNotifier imageChangeNotifier = AChangeNotifier(), metadataChangeNotifier = AChangeNotifier(), addressChangeNotifier = AChangeNotifier();
|
||||
final isFavouriteNotifier = ValueNotifier(false);
|
||||
final ValueNotifier<bool> isFavouriteNotifier = ValueNotifier(false);
|
||||
|
||||
ImageEntry({
|
||||
this.uri,
|
||||
|
|
|
@ -69,12 +69,17 @@ class _CollectionAppBarState extends State<CollectionAppBar> with SingleTickerPr
|
|||
valueListenable: stateNotifier,
|
||||
builder: (context, state, child) {
|
||||
debugPrint('$runtimeType builder state=$state');
|
||||
return SliverAppBar(
|
||||
return Consumer<CollectionLens>(
|
||||
builder: (context, collection, child) => AnimatedBuilder(
|
||||
animation: collection.filterChangeNotifier,
|
||||
builder: (context, child) => SliverAppBar(
|
||||
leading: _buildAppBarLeading(),
|
||||
title: _buildAppBarTitle(),
|
||||
actions: _buildActions(),
|
||||
bottom: FilterBar(),
|
||||
bottom: collection.filters.isNotEmpty ? FilterBar() : null,
|
||||
floating: true,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
|
|
@ -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,7 +51,8 @@ class SectionSliver extends StatelessWidget {
|
|||
),
|
||||
);
|
||||
|
||||
return SliverStickyHeader(
|
||||
return showHeader
|
||||
? SliverStickyHeader(
|
||||
header: SectionHeader(
|
||||
collection: collection,
|
||||
sections: sections,
|
||||
|
@ -57,7 +60,8 @@ class SectionSliver extends StatelessWidget {
|
|||
),
|
||||
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(
|
||||
return header != null
|
||||
? IgnorePointer(
|
||||
child: header,
|
||||
);
|
||||
)
|
||||
: const SizedBox.shrink();
|
||||
}
|
||||
|
||||
Widget _buildAlbumSectionHeader(BuildContext context) {
|
||||
|
|
|
@ -59,7 +59,6 @@ class ImageSearchDelegate extends SearchDelegate<CollectionFilter> {
|
|||
child: ValueListenableBuilder<String>(
|
||||
valueListenable: expandedSectionNotifier,
|
||||
builder: (context, expandedSection, child) {
|
||||
debugPrint('builder expandedSection=$expandedSection');
|
||||
return ListView(
|
||||
children: [
|
||||
_buildFilterRow(
|
||||
|
|
|
@ -25,6 +25,7 @@ class ThumbnailCollection extends StatelessWidget {
|
|||
final collection = Provider.of<CollectionLens>(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<MediaQueryData, double>(
|
||||
|
|
Loading…
Reference in a new issue