use chip action delegates
This commit is contained in:
parent
7e530aed74
commit
c19b266e76
6 changed files with 85 additions and 81 deletions
|
@ -6,8 +6,8 @@ import 'package:aves/model/source/collection_source.dart';
|
|||
import 'package:aves/model/source/enums.dart';
|
||||
import 'package:aves/utils/android_file_utils.dart';
|
||||
import 'package:aves/widgets/collection/empty.dart';
|
||||
import 'package:aves/widgets/common/aves_selection_dialog.dart';
|
||||
import 'package:aves/widgets/common/icons.dart';
|
||||
import 'package:aves/widgets/filter_grids/chip_action_delegate.dart';
|
||||
import 'package:aves/widgets/filter_grids/filter_grid_page.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
@ -17,6 +17,8 @@ class AlbumListPage extends StatelessWidget {
|
|||
|
||||
final CollectionSource source;
|
||||
|
||||
static final ChipActionDelegate actionDelegate = AlbumChipActionDelegate();
|
||||
|
||||
const AlbumListPage({@required this.source});
|
||||
|
||||
@override
|
||||
|
@ -31,7 +33,7 @@ class AlbumListPage extends StatelessWidget {
|
|||
builder: (context, snapshot) => FilterNavigationPage(
|
||||
source: source,
|
||||
title: 'Albums',
|
||||
onChipActionSelected: _onChipActionSelected,
|
||||
actionDelegate: actionDelegate,
|
||||
filterEntries: getAlbumEntries(source),
|
||||
filterBuilder: (s) => AlbumFilter(s, source.getUniqueAlbumName(s)),
|
||||
emptyBuilder: () => EmptyContent(
|
||||
|
@ -45,27 +47,6 @@ class AlbumListPage extends StatelessWidget {
|
|||
);
|
||||
}
|
||||
|
||||
void _onChipActionSelected(BuildContext context, ChipAction action) async {
|
||||
switch (action) {
|
||||
case ChipAction.sort:
|
||||
final factor = await showDialog<ChipSortFactor>(
|
||||
context: context,
|
||||
builder: (context) => AvesSelectionDialog<ChipSortFactor>(
|
||||
initialValue: settings.albumSortFactor,
|
||||
options: {
|
||||
ChipSortFactor.date: 'By date',
|
||||
ChipSortFactor.name: 'By name',
|
||||
},
|
||||
title: 'Sort',
|
||||
),
|
||||
);
|
||||
if (factor != null) {
|
||||
settings.albumSortFactor = factor;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// common with album selection page to move/copy entries
|
||||
|
||||
static Map<String, ImageEntry> getAlbumEntries(CollectionSource source) {
|
||||
|
|
65
lib/widgets/filter_grids/chip_action_delegate.dart
Normal file
65
lib/widgets/filter_grids/chip_action_delegate.dart
Normal file
|
@ -0,0 +1,65 @@
|
|||
import 'package:aves/model/settings/settings.dart';
|
||||
import 'package:aves/model/source/enums.dart';
|
||||
import 'package:aves/utils/durations.dart';
|
||||
import 'package:aves/widgets/common/aves_selection_dialog.dart';
|
||||
import 'package:aves/widgets/filter_grids/chip_actions.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
|
||||
abstract class ChipActionDelegate {
|
||||
ChipSortFactor get sortFactor;
|
||||
|
||||
set sortFactor(ChipSortFactor factor);
|
||||
|
||||
Future<void> onChipActionSelected(BuildContext context, ChipAction action) async {
|
||||
// wait for the popup menu to hide before proceeding with the action
|
||||
await Future.delayed(Durations.popupMenuAnimation * timeDilation);
|
||||
|
||||
switch (action) {
|
||||
case ChipAction.sort:
|
||||
await _showSortDialog(context);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _showSortDialog(BuildContext context) async {
|
||||
final factor = await showDialog<ChipSortFactor>(
|
||||
context: context,
|
||||
builder: (context) => AvesSelectionDialog<ChipSortFactor>(
|
||||
initialValue: sortFactor,
|
||||
options: {
|
||||
ChipSortFactor.date: 'By date',
|
||||
ChipSortFactor.name: 'By name',
|
||||
},
|
||||
title: 'Sort',
|
||||
),
|
||||
);
|
||||
if (factor != null) {
|
||||
sortFactor = factor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AlbumChipActionDelegate extends ChipActionDelegate {
|
||||
@override
|
||||
ChipSortFactor get sortFactor => settings.albumSortFactor;
|
||||
|
||||
@override
|
||||
set sortFactor(ChipSortFactor factor) => settings.albumSortFactor = factor;
|
||||
}
|
||||
|
||||
class CountryChipActionDelegate extends ChipActionDelegate {
|
||||
@override
|
||||
ChipSortFactor get sortFactor => settings.countrySortFactor;
|
||||
|
||||
@override
|
||||
set sortFactor(ChipSortFactor factor) => settings.countrySortFactor = factor;
|
||||
}
|
||||
|
||||
class TagChipActionDelegate extends ChipActionDelegate {
|
||||
@override
|
||||
ChipSortFactor get sortFactor => settings.tagSortFactor;
|
||||
|
||||
@override
|
||||
set sortFactor(ChipSortFactor factor) => settings.tagSortFactor = factor;
|
||||
}
|
3
lib/widgets/filter_grids/chip_actions.dart
Normal file
3
lib/widgets/filter_grids/chip_actions.dart
Normal file
|
@ -0,0 +1,3 @@
|
|||
enum ChipAction {
|
||||
sort,
|
||||
}
|
|
@ -5,8 +5,8 @@ import 'package:aves/model/source/collection_source.dart';
|
|||
import 'package:aves/model/source/enums.dart';
|
||||
import 'package:aves/model/source/location.dart';
|
||||
import 'package:aves/widgets/collection/empty.dart';
|
||||
import 'package:aves/widgets/common/aves_selection_dialog.dart';
|
||||
import 'package:aves/widgets/common/icons.dart';
|
||||
import 'package:aves/widgets/filter_grids/chip_action_delegate.dart';
|
||||
import 'package:aves/widgets/filter_grids/filter_grid_page.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
@ -16,6 +16,8 @@ class CountryListPage extends StatelessWidget {
|
|||
|
||||
final CollectionSource source;
|
||||
|
||||
static final ChipActionDelegate actionDelegate = CountryChipActionDelegate();
|
||||
|
||||
const CountryListPage({@required this.source});
|
||||
|
||||
@override
|
||||
|
@ -28,7 +30,7 @@ class CountryListPage extends StatelessWidget {
|
|||
builder: (context, snapshot) => FilterNavigationPage(
|
||||
source: source,
|
||||
title: 'Countries',
|
||||
onChipActionSelected: _onChipActionSelected,
|
||||
actionDelegate: actionDelegate,
|
||||
filterEntries: _getCountryEntries(),
|
||||
filterBuilder: (s) => LocationFilter(LocationLevel.country, s),
|
||||
emptyBuilder: () => EmptyContent(
|
||||
|
@ -41,27 +43,6 @@ class CountryListPage extends StatelessWidget {
|
|||
);
|
||||
}
|
||||
|
||||
void _onChipActionSelected(BuildContext context, ChipAction action) async {
|
||||
switch (action) {
|
||||
case ChipAction.sort:
|
||||
final factor = await showDialog<ChipSortFactor>(
|
||||
context: context,
|
||||
builder: (context) => AvesSelectionDialog<ChipSortFactor>(
|
||||
initialValue: settings.countrySortFactor,
|
||||
options: {
|
||||
ChipSortFactor.date: 'By date',
|
||||
ChipSortFactor.name: 'By name',
|
||||
},
|
||||
title: 'Sort',
|
||||
),
|
||||
);
|
||||
if (factor != null) {
|
||||
settings.countrySortFactor = factor;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, ImageEntry> _getCountryEntries() {
|
||||
final entriesByDate = source.sortedEntriesForFilterList;
|
||||
final locatedEntries = entriesByDate.where((entry) => entry.isLocated);
|
||||
|
|
|
@ -16,18 +16,19 @@ import 'package:aves/widgets/common/double_back_pop.dart';
|
|||
import 'package:aves/widgets/common/icons.dart';
|
||||
import 'package:aves/widgets/common/menu_row.dart';
|
||||
import 'package:aves/widgets/drawer/app_drawer.dart';
|
||||
import 'package:aves/widgets/filter_grids/chip_action_delegate.dart';
|
||||
import 'package:aves/widgets/filter_grids/chip_actions.dart';
|
||||
import 'package:aves/widgets/filter_grids/decorated_filter_chip.dart';
|
||||
import 'package:aves/widgets/filter_grids/search_button.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter_staggered_animations/flutter_staggered_animations.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class FilterNavigationPage extends StatelessWidget {
|
||||
final CollectionSource source;
|
||||
final String title;
|
||||
final void Function(BuildContext context, ChipAction action) onChipActionSelected;
|
||||
final ChipActionDelegate actionDelegate;
|
||||
final Map<String, ImageEntry> filterEntries;
|
||||
final CollectionFilter Function(String key) filterBuilder;
|
||||
final Widget Function() emptyBuilder;
|
||||
|
@ -35,7 +36,7 @@ class FilterNavigationPage extends StatelessWidget {
|
|||
const FilterNavigationPage({
|
||||
@required this.source,
|
||||
@required this.title,
|
||||
@required this.onChipActionSelected,
|
||||
@required this.actionDelegate,
|
||||
@required this.filterEntries,
|
||||
@required this.filterBuilder,
|
||||
@required this.emptyBuilder,
|
||||
|
@ -95,11 +96,7 @@ class FilterNavigationPage extends StatelessWidget {
|
|||
),
|
||||
];
|
||||
},
|
||||
onSelected: (action) async {
|
||||
// wait for the popup menu to hide before proceeding with the action
|
||||
await Future.delayed(Durations.popupMenuAnimation * timeDilation);
|
||||
onChipActionSelected(context, action);
|
||||
},
|
||||
onSelected: (action) => actionDelegate.onChipActionSelected(context, action),
|
||||
),
|
||||
];
|
||||
}
|
||||
|
@ -219,7 +216,3 @@ class FilterGridPage extends StatelessWidget {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum ChipAction {
|
||||
sort,
|
||||
}
|
||||
|
|
|
@ -5,8 +5,8 @@ import 'package:aves/model/source/collection_source.dart';
|
|||
import 'package:aves/model/source/enums.dart';
|
||||
import 'package:aves/model/source/tag.dart';
|
||||
import 'package:aves/widgets/collection/empty.dart';
|
||||
import 'package:aves/widgets/common/aves_selection_dialog.dart';
|
||||
import 'package:aves/widgets/common/icons.dart';
|
||||
import 'package:aves/widgets/filter_grids/chip_action_delegate.dart';
|
||||
import 'package:aves/widgets/filter_grids/filter_grid_page.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
@ -16,6 +16,8 @@ class TagListPage extends StatelessWidget {
|
|||
|
||||
final CollectionSource source;
|
||||
|
||||
static final ChipActionDelegate actionDelegate = TagChipActionDelegate();
|
||||
|
||||
const TagListPage({@required this.source});
|
||||
|
||||
@override
|
||||
|
@ -28,7 +30,7 @@ class TagListPage extends StatelessWidget {
|
|||
builder: (context, snapshot) => FilterNavigationPage(
|
||||
source: source,
|
||||
title: 'Tags',
|
||||
onChipActionSelected: _onChipActionSelected,
|
||||
actionDelegate: actionDelegate,
|
||||
filterEntries: _getTagEntries(),
|
||||
filterBuilder: (s) => TagFilter(s),
|
||||
emptyBuilder: () => EmptyContent(
|
||||
|
@ -41,27 +43,6 @@ class TagListPage extends StatelessWidget {
|
|||
);
|
||||
}
|
||||
|
||||
void _onChipActionSelected(BuildContext context, ChipAction action) async {
|
||||
switch (action) {
|
||||
case ChipAction.sort:
|
||||
final factor = await showDialog<ChipSortFactor>(
|
||||
context: context,
|
||||
builder: (context) => AvesSelectionDialog<ChipSortFactor>(
|
||||
initialValue: settings.tagSortFactor,
|
||||
options: {
|
||||
ChipSortFactor.date: 'By date',
|
||||
ChipSortFactor.name: 'By name',
|
||||
},
|
||||
title: 'Sort',
|
||||
),
|
||||
);
|
||||
if (factor != null) {
|
||||
settings.tagSortFactor = factor;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, ImageEntry> _getTagEntries() {
|
||||
final entriesByDate = source.sortedEntriesForFilterList;
|
||||
final tags = source.sortedTags
|
||||
|
|
Loading…
Reference in a new issue