Skip to content

Commit

Permalink
#327 long press on section header selects all section
Browse files Browse the repository at this point in the history
  • Loading branch information
deckerst committed Sep 15, 2022
1 parent 3ee20d4 commit 3090439
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 5 deletions.
7 changes: 6 additions & 1 deletion lib/widgets/collection/collection_grid.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class _CollectionGridContent extends StatelessWidget {

@override
Widget build(BuildContext context) {
final selectable = context.select<ValueNotifier<AppMode>, bool>((v) => v.value.canSelectMedia);
final settingsRouteKey = context.read<TileExtentController>().settingsRouteKey;
final tileLayout = context.select<Settings, TileLayout>((s) => s.getTileLayout(settingsRouteKey));
return Consumer<CollectionLens>(
Expand Down Expand Up @@ -124,6 +125,7 @@ class _CollectionGridContent extends StatelessWidget {
}
return SectionedEntryListLayoutProvider(
collection: collection,
selectable: selectable,
scrollableWidth: scrollableWidth,
tileLayout: tileLayout,
columnCount: columnCount,
Expand Down Expand Up @@ -160,6 +162,7 @@ class _CollectionGridContent extends StatelessWidget {
isScrollingNotifier: _isScrollingNotifier,
scrollController: PrimaryScrollController.of(context)!,
tileLayout: tileLayout,
selectable: selectable,
),
);
return sectionedListLayoutProvider;
Expand All @@ -173,12 +176,14 @@ class _CollectionSectionedContent extends StatefulWidget {
final ValueNotifier<bool> isScrollingNotifier;
final ScrollController scrollController;
final TileLayout tileLayout;
final bool selectable;

const _CollectionSectionedContent({
required this.collection,
required this.isScrollingNotifier,
required this.scrollController,
required this.tileLayout,
required this.selectable,
});

@override
Expand Down Expand Up @@ -220,7 +225,7 @@ class _CollectionSectionedContentState extends State<_CollectionSectionedContent

final selector = GridSelectionGestureDetector(
scrollableKey: _scrollableKey,
selectable: context.select<ValueNotifier<AppMode>, bool>((v) => v.value.canSelectMedia),
selectable: widget.selectable,
items: collection.sortedEntries,
scrollController: scrollController,
appBarHeightNotifier: _appBarHeightNotifier,
Expand Down
3 changes: 3 additions & 0 deletions lib/widgets/collection/grid/headers/album.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import 'package:flutter/material.dart';

class AlbumSectionHeader extends StatelessWidget {
final String? directory, albumName;
final bool selectable;

const AlbumSectionHeader({
super.key,
required this.directory,
required this.albumName,
required this.selectable,
});

@override
Expand All @@ -41,6 +43,7 @@ class AlbumSectionHeader extends StatelessWidget {
color: Color(0xFF757575),
)
: null,
selectable: selectable,
);
}

Expand Down
21 changes: 18 additions & 3 deletions lib/widgets/collection/grid/headers/any.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ class CollectionSectionHeader extends StatelessWidget {
final CollectionLens collection;
final SectionKey sectionKey;
final double height;
final bool selectable;

const CollectionSectionHeader({
super.key,
required this.collection,
required this.sectionKey,
required this.height,
required this.selectable,
});

@override
Expand All @@ -41,17 +43,29 @@ class CollectionSectionHeader extends StatelessWidget {
case EntryGroupFactor.album:
return _buildAlbumHeader(context);
case EntryGroupFactor.month:
return MonthSectionHeader<AvesEntry>(key: ValueKey(sectionKey), date: (sectionKey as EntryDateSectionKey).date);
return MonthSectionHeader<AvesEntry>(
key: ValueKey(sectionKey),
date: (sectionKey as EntryDateSectionKey).date,
selectable: selectable,
);
case EntryGroupFactor.day:
return DaySectionHeader<AvesEntry>(key: ValueKey(sectionKey), date: (sectionKey as EntryDateSectionKey).date);
return DaySectionHeader<AvesEntry>(
key: ValueKey(sectionKey),
date: (sectionKey as EntryDateSectionKey).date,
selectable: selectable,
);
case EntryGroupFactor.none:
break;
}
break;
case EntrySortFactor.name:
return _buildAlbumHeader(context);
case EntrySortFactor.rating:
return RatingSectionHeader<AvesEntry>(key: ValueKey(sectionKey), rating: (sectionKey as EntryRatingSectionKey).rating);
return RatingSectionHeader<AvesEntry>(
key: ValueKey(sectionKey),
rating: (sectionKey as EntryRatingSectionKey).rating,
selectable: selectable,
);
case EntrySortFactor.size:
break;
}
Expand All @@ -65,6 +79,7 @@ class CollectionSectionHeader extends StatelessWidget {
key: ValueKey(sectionKey),
directory: directory,
albumName: directory != null ? source.getAlbumDisplayName(context, directory) : null,
selectable: selectable,
);
}

Expand Down
6 changes: 6 additions & 0 deletions lib/widgets/collection/grid/headers/date.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import 'package:intl/intl.dart';

class DaySectionHeader<T> extends StatelessWidget {
final DateTime? date;
final bool selectable;

const DaySectionHeader({
super.key,
required this.date,
required this.selectable,
});

// Examples (en_US):
Expand Down Expand Up @@ -48,16 +50,19 @@ class DaySectionHeader<T> extends StatelessWidget {
return SectionHeader<T>(
sectionKey: EntryDateSectionKey(date),
title: _formatDate(context, date),
selectable: selectable,
);
}
}

class MonthSectionHeader<T> extends StatelessWidget {
final DateTime? date;
final bool selectable;

const MonthSectionHeader({
super.key,
required this.date,
required this.selectable,
});

static String _formatDate(BuildContext context, DateTime? date) {
Expand All @@ -74,6 +79,7 @@ class MonthSectionHeader<T> extends StatelessWidget {
return SectionHeader<T>(
sectionKey: EntryDateSectionKey(date),
title: _formatDate(context, date),
selectable: selectable,
);
}
}
3 changes: 3 additions & 0 deletions lib/widgets/collection/grid/headers/rating.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@ import 'package:flutter/material.dart';

class RatingSectionHeader<T> extends StatelessWidget {
final int rating;
final bool selectable;

const RatingSectionHeader({
super.key,
required this.rating,
required this.selectable,
});

@override
Widget build(BuildContext context) {
return SectionHeader<T>(
sectionKey: EntryRatingSectionKey(rating),
title: RatingFilter.formatRating(context, rating),
selectable: selectable,
);
}
}
3 changes: 3 additions & 0 deletions lib/widgets/collection/grid/section_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import 'package:flutter/material.dart';

class SectionedEntryListLayoutProvider extends SectionedListLayoutProvider<AvesEntry> {
final CollectionLens collection;
final bool selectable;

const SectionedEntryListLayoutProvider({
super.key,
required this.collection,
required this.selectable,
required super.scrollableWidth,
required super.tileLayout,
required super.columnCount,
Expand Down Expand Up @@ -42,6 +44,7 @@ class SectionedEntryListLayoutProvider extends SectionedListLayoutProvider<AvesE
collection: collection,
sectionKey: sectionKey,
height: headerExtent,
selectable: selectable,
);
}
}
15 changes: 14 additions & 1 deletion lib/widgets/common/grid/header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ class SectionHeader<T> extends StatelessWidget {
constraints: BoxConstraints(minHeight: leadingSize.height),
child: GestureDetector(
onTap: selectable ? () => _toggleSectionSelection(context) : null,
onLongPress: selectable
? () {
final selection = context.read<Selection<T>>();
if (selection.isSelecting) {
_toggleSectionSelection(context);
} else {
selection.select();
selection.addToSelection(_getSectionEntries(context));
}
}
: null,
child: Text.rich(
TextSpan(
children: [
Expand Down Expand Up @@ -74,8 +85,10 @@ class SectionHeader<T> extends StatelessWidget {
);
}

List<T> _getSectionEntries(BuildContext context) => context.read<SectionedListLayout<T>>().sections[sectionKey] ?? [];

void _toggleSectionSelection(BuildContext context) {
final sectionEntries = context.read<SectionedListLayout<T>>().sections[sectionKey] ?? [];
final sectionEntries = _getSectionEntries(context);
final selection = context.read<Selection<T>>();
final isSelected = selection.isSelected(sectionEntries);
if (isSelected) {
Expand Down
1 change: 1 addition & 0 deletions lib/widgets/filter_grids/common/filter_grid_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ class _FilterGridContent<T extends CollectionFilter> extends StatelessWidget {
child: SectionedFilterListLayoutProvider<T>(
sections: visibleSections,
showHeaders: showHeaders,
selectable: selectable,
tileLayout: tileLayout,
scrollableWidth: scrollableWidth,
columnCount: columnCount,
Expand Down
3 changes: 3 additions & 0 deletions lib/widgets/filter_grids/common/section_header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import 'package:flutter/material.dart';

class FilterChipSectionHeader<T> extends StatelessWidget {
final ChipSectionKey sectionKey;
final bool selectable;

const FilterChipSectionHeader({
super.key,
required this.sectionKey,
required this.selectable,
});

@override
Expand All @@ -16,6 +18,7 @@ class FilterChipSectionHeader<T> extends StatelessWidget {
sectionKey: sectionKey,
leading: sectionKey.leading,
title: sectionKey.title,
selectable: selectable,
);
}

Expand Down
4 changes: 4 additions & 0 deletions lib/widgets/filter_grids/common/section_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ import 'package:aves/widgets/filter_grids/common/section_keys.dart';
import 'package:flutter/material.dart';

class SectionedFilterListLayoutProvider<T extends CollectionFilter> extends SectionedListLayoutProvider<FilterGridItem<T>> {
final bool selectable;

const SectionedFilterListLayoutProvider({
super.key,
required this.sections,
required this.showHeaders,
required this.selectable,
required super.scrollableWidth,
required super.tileLayout,
required super.columnCount,
Expand Down Expand Up @@ -37,6 +40,7 @@ class SectionedFilterListLayoutProvider<T extends CollectionFilter> extends Sect
Widget buildHeader(BuildContext context, SectionKey sectionKey, double headerExtent) {
return FilterChipSectionHeader<FilterGridItem<T>>(
sectionKey: sectionKey as ChipSectionKey,
selectable: selectable,
);
}
}

0 comments on commit 3090439

Please sign in to comment.