From b57253c2510573d03b1fe213521560f142f2d229 Mon Sep 17 00:00:00 2001 From: Thibault Deckers Date: Sat, 30 Dec 2023 14:33:35 +0100 Subject: [PATCH] #861 strip `unlocated` filter from context collection when editing location via map --- CHANGELOG.md | 4 ++++ lib/model/filters/location.dart | 11 ++++++++--- .../dialogs/entry_editors/edit_location_dialog.dart | 8 ++++++-- lib/widgets/search/search_delegate.dart | 2 +- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index de1d2eb8b..b1e80ba11 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ All notable changes to this project will be documented in this file. - Collection: allow hiding thumbnail overlay HDR icon +### Changed + +- Info: strip `unlocated` filter from context collection when editing location via map + ## [v1.10.2] - 2023-12-24 ### Changed diff --git a/lib/model/filters/location.dart b/lib/model/filters/location.dart index f66bf26ea..cad7074e7 100644 --- a/lib/model/filters/location.dart +++ b/lib/model/filters/location.dart @@ -15,6 +15,11 @@ class LocationFilter extends CoveredCollectionFilter { late final String? _code; late final EntryFilter _test; + static final unlocated = LocationFilter(LocationLevel.place, ''); + static final located = unlocated.reverse(); + + bool get _isUnlocated => _location.isEmpty; + @override List get props => [level, _location, _code, reversed]; @@ -23,7 +28,7 @@ class LocationFilter extends CoveredCollectionFilter { _location = split.isNotEmpty ? split[0] : location; _code = split.length > 1 ? split[1] : null; - if (_location.isEmpty) { + if (_isUnlocated) { _test = (entry) => !entry.hasGps; } else { switch (level) { @@ -81,11 +86,11 @@ class LocationFilter extends CoveredCollectionFilter { String get universalLabel => _location; @override - String getLabel(BuildContext context) => _location.isEmpty ? context.l10n.filterNoLocationLabel : _location; + String getLabel(BuildContext context) => _isUnlocated ? context.l10n.filterNoLocationLabel : _location; @override Widget iconBuilder(BuildContext context, double size, {bool showGenericIcon = true}) { - if (_location.isEmpty) { + if (_isUnlocated) { return Icon(AIcons.locationUnlocated, size: size); } switch (level) { diff --git a/lib/widgets/dialogs/entry_editors/edit_location_dialog.dart b/lib/widgets/dialogs/entry_editors/edit_location_dialog.dart index a9fae07d1..d9c946760 100644 --- a/lib/widgets/dialogs/entry_editors/edit_location_dialog.dart +++ b/lib/widgets/dialogs/entry_editors/edit_location_dialog.dart @@ -1,6 +1,7 @@ import 'package:aves/model/entry/entry.dart'; import 'package:aves/model/entry/extensions/location.dart'; import 'package:aves/model/entry/extensions/metadata_edition.dart'; +import 'package:aves/model/filters/location.dart'; import 'package:aves/model/settings/enums/coordinate_format.dart'; import 'package:aves/model/settings/settings.dart'; import 'package:aves/model/source/collection_lens.dart'; @@ -18,6 +19,7 @@ import 'package:aves/widgets/dialogs/item_picker.dart'; import 'package:aves/widgets/dialogs/pick_dialogs/item_pick_page.dart'; import 'package:aves/widgets/dialogs/pick_dialogs/location_pick_page.dart'; import 'package:aves_model/aves_model.dart'; +import 'package:collection/collection.dart'; import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; import 'package:latlong2/latlong.dart'; @@ -172,8 +174,10 @@ class _EditEntryLocationDialogState extends State { final mapCollection = baseCollection != null ? CollectionLens( source: baseCollection.source, - filters: baseCollection.filters, - fixedSelection: baseCollection.sortedEntries.where((entry) => entry.hasGps).toList(), + filters: { + ...baseCollection.filters.whereNot((filter) => filter == LocationFilter.unlocated), + LocationFilter.located, + }, ) : null; final latLng = await Navigator.maybeOf(context)?.push( diff --git a/lib/widgets/search/search_delegate.dart b/lib/widgets/search/search_delegate.dart index 955a55904..60ab56c67 100644 --- a/lib/widgets/search/search_delegate.dart +++ b/lib/widgets/search/search_delegate.dart @@ -279,7 +279,7 @@ class CollectionSearchDelegate extends AvesSearchDelegate with FeedbackMixin, Va title: context.l10n.searchMetadataSectionTitle, filters: [ MissingFilter.date, - LocationFilter(LocationLevel.place, ''), + LocationFilter.unlocated, MissingFilter.fineAddress, TagFilter(''), RatingFilter(0),