aboutsummaryrefslogtreecommitdiff
path: root/lib/widgets/common/map/map_action_delegate.dart
diff options
context:
space:
mode:
authormirror <mirror@localhost>2026-11-22 08:41:00 +0900
committermirror <mirror@localhost>2026-11-22 08:41:00 +0900
commit449d8b74bd6d9dae98a07254cdfad677b920e7b0 (patch)
treec131c3528c4d517f56e19b854a7453fedb097d40 /lib/widgets/common/map/map_action_delegate.dart
downloadaves-src-master.tar.gz
aves-src-master.zip
snapshot of aves v1.13.12 (secrets removed: android/app/google-services.json)HEADv1.13.12master
Diffstat (limited to 'lib/widgets/common/map/map_action_delegate.dart')
-rw-r--r--lib/widgets/common/map/map_action_delegate.dart92
1 files changed, 92 insertions, 0 deletions
diff --git a/lib/widgets/common/map/map_action_delegate.dart b/lib/widgets/common/map/map_action_delegate.dart
new file mode 100644
index 0000000..d9183d7
--- /dev/null
+++ b/lib/widgets/common/map/map_action_delegate.dart
@@ -0,0 +1,92 @@
+import 'package:aves/geo/uri.dart';
+import 'package:aves/model/device.dart';
+import 'package:aves/model/entry/entry.dart';
+import 'package:aves/model/source/collection_lens.dart';
+import 'package:aves/services/common/services.dart';
+import 'package:aves/widgets/common/action_mixins/feedback.dart';
+import 'package:aves/widgets/common/extensions/build_context.dart';
+import 'package:aves/widgets/dialogs/add_shortcut_dialog.dart';
+import 'package:aves/widgets/dialogs/map/style_selection_dialog.dart';
+import 'package:aves/widgets/map/map_page.dart';
+import 'package:aves_map/aves_map.dart';
+import 'package:aves_model/aves_model.dart';
+import 'package:flutter/material.dart';
+import 'package:provider/provider.dart';
+
+class MapActionDelegate with FeedbackMixin {
+ final AvesMapController controller;
+
+ const MapActionDelegate(this.controller);
+
+ bool isVisible(BuildContext context, MapAction action) {
+ switch (action) {
+ case MapAction.selectStyle:
+ case MapAction.openMapApp:
+ case MapAction.zoomIn:
+ case MapAction.zoomOut:
+ return true;
+ case MapAction.addShortcut:
+ return device.canPinShortcut && context.currentRouteName == MapPage.routeName;
+ }
+ }
+
+ void onActionSelected(BuildContext context, MapAction action) {
+ switch (action) {
+ case MapAction.selectStyle:
+ selectStyle(context);
+ case MapAction.openMapApp:
+ OpenMapAppNotification().dispatch(context);
+ case MapAction.zoomIn:
+ controller.zoomBy(1);
+ case MapAction.zoomOut:
+ controller.zoomBy(-1);
+ case MapAction.addShortcut:
+ _addShortcut(context);
+ }
+ }
+
+ static void selectStyle(BuildContext context) {
+ Navigator.maybeOf(context)?.push<EntryMapStyle>(
+ MaterialPageRoute(
+ settings: const RouteSettings(name: MapStyleSelectionDialog.routeName),
+ builder: (context) => const MapStyleSelectionDialog(),
+ ),
+ );
+ }
+
+ Future<void> _addShortcut(BuildContext context) async {
+ final idleBounds = controller.idleBounds;
+ if (idleBounds == null) {
+ showFeedback(context, FeedbackType.warn, context.l10n.genericFailureFeedback);
+ return;
+ }
+
+ final collection = context.read<CollectionLens>();
+ final result = await showDialog<(AvesEntry?, String)>(
+ context: context,
+ builder: (context) => AddShortcutDialog(
+ defaultName: '',
+ collection: collection,
+ ),
+ routeSettings: const RouteSettings(name: AddShortcutDialog.routeName),
+ );
+ if (result == null) return;
+
+ final (coverEntry, name) = result;
+ if (name.isEmpty) return;
+
+ final geoUri = toGeoUri(idleBounds.projectedCenter, zoom: idleBounds.zoom);
+ await appService.pinToHomeScreen(
+ name,
+ coverEntry,
+ route: MapPage.routeName,
+ filters: collection.filters,
+ geoUri: geoUri,
+ );
+ if (!device.showPinShortcutFeedback) {
+ showFeedback(context, FeedbackType.info, context.l10n.genericSuccessFeedback);
+ }
+ }
+}
+
+class OpenMapAppNotification extends Notification {}