diff --git a/documentation/map-and-location.md b/documentation/map-and-location.md index 3cfa7a6f..634235ef 100644 --- a/documentation/map-and-location.md +++ b/documentation/map-and-location.md @@ -103,10 +103,18 @@ Shows node count and pin count. Tappable to expand a legend of all marker types. ## Path Trace Map ### How to Access -- From the main map's radar icon +- From the main map's menu → **Path Trace** (build your own route, see below) - From a contact's long-press menu → "Path Trace / Ping" - From a message's path view → radar icon +### Building a Custom Trace on the Map +1. Open the map menu and choose **Path Trace**. A panel appears at the top of the map. +2. Tap nodes on the map in the order the trace should travel. **Remove Last** and **Clear** edit the list. +3. Choose **Round trip** (the trace comes back along the same hops) or **As entered** (the hops are used exactly as listed, so add the return hops yourself). +4. Tap **Run path trace**. Nothing is sent until you press this button. + +Returning from the result keeps your hops, mode and the last result (**View last result** reopens it without sending again). **Close** or the back button hides the panel without discarding the hops; reopening **Path Trace** during the same session resumes where you left off. The hops are dropped when you connect to a different radio. + ### What the User Sees A map with a polyline showing the route from your node through repeater hops to the target: - **Green circles**: Hops with known GPS coordinates diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 482af3ef..09fec1d5 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -1234,6 +1234,12 @@ "map_runTraceWithReturnPath": "Return back on the same path.", "map_removeLast": "Remove Last", "map_pathTraceCancelled": "Path trace cancelled.", + "map_pathTraceAddMoreHint": "Tap more nodes to add hops, choose how the trace returns, then tap Run path trace.", + "map_pathTraceModeRoundTrip": "Round trip", + "map_pathTraceModeRoundTripHint": "The trace goes out through these hops and comes back the same way.", + "map_pathTraceModeAsEntered": "As entered", + "map_pathTraceModeAsEnteredHint": "The trace follows these hops exactly. Add the hops back to you yourself.", + "map_pathTraceViewLast": "View last result", "mapCache_title": "Offline Map Cache", "mapCache_selectAreaFirst": "Select an area to cache first", "mapCache_noTilesToDownload": "No tiles to download for this area", diff --git a/lib/l10n/app_localizations.dart b/lib/l10n/app_localizations.dart index f80556c8..8faa6c4b 100644 --- a/lib/l10n/app_localizations.dart +++ b/lib/l10n/app_localizations.dart @@ -4246,6 +4246,42 @@ abstract class AppLocalizations { /// **'Path trace cancelled.'** String get map_pathTraceCancelled; + /// No description provided for @map_pathTraceAddMoreHint. + /// + /// In en, this message translates to: + /// **'Tap more nodes to add hops, choose how the trace returns, then tap Run path trace.'** + String get map_pathTraceAddMoreHint; + + /// No description provided for @map_pathTraceModeRoundTrip. + /// + /// In en, this message translates to: + /// **'Round trip'** + String get map_pathTraceModeRoundTrip; + + /// No description provided for @map_pathTraceModeRoundTripHint. + /// + /// In en, this message translates to: + /// **'The trace goes out through these hops and comes back the same way.'** + String get map_pathTraceModeRoundTripHint; + + /// No description provided for @map_pathTraceModeAsEntered. + /// + /// In en, this message translates to: + /// **'As entered'** + String get map_pathTraceModeAsEntered; + + /// No description provided for @map_pathTraceModeAsEnteredHint. + /// + /// In en, this message translates to: + /// **'The trace follows these hops exactly. Add the hops back to you yourself.'** + String get map_pathTraceModeAsEnteredHint; + + /// No description provided for @map_pathTraceViewLast. + /// + /// In en, this message translates to: + /// **'View last result'** + String get map_pathTraceViewLast; + /// No description provided for @mapCache_title. /// /// In en, this message translates to: diff --git a/lib/l10n/app_localizations_bg.dart b/lib/l10n/app_localizations_bg.dart index 8ef318bd..f4a99c6c 100644 --- a/lib/l10n/app_localizations_bg.dart +++ b/lib/l10n/app_localizations_bg.dart @@ -2382,6 +2382,27 @@ class AppLocalizationsBg extends AppLocalizations { @override String get map_pathTraceCancelled => 'Отменен е следването на пътя.'; + @override + String get map_pathTraceAddMoreHint => + 'Tap more nodes to add hops, choose how the trace returns, then tap Run path trace.'; + + @override + String get map_pathTraceModeRoundTrip => 'Round trip'; + + @override + String get map_pathTraceModeRoundTripHint => + 'The trace goes out through these hops and comes back the same way.'; + + @override + String get map_pathTraceModeAsEntered => 'As entered'; + + @override + String get map_pathTraceModeAsEnteredHint => + 'The trace follows these hops exactly. Add the hops back to you yourself.'; + + @override + String get map_pathTraceViewLast => 'View last result'; + @override String get mapCache_title => 'Кеш на офлайн карти'; diff --git a/lib/l10n/app_localizations_de.dart b/lib/l10n/app_localizations_de.dart index 24674318..2d9adabf 100644 --- a/lib/l10n/app_localizations_de.dart +++ b/lib/l10n/app_localizations_de.dart @@ -2380,6 +2380,27 @@ class AppLocalizationsDe extends AppLocalizations { @override String get map_pathTraceCancelled => 'Pfadverfolgung abgebrochen.'; + @override + String get map_pathTraceAddMoreHint => + 'Tap more nodes to add hops, choose how the trace returns, then tap Run path trace.'; + + @override + String get map_pathTraceModeRoundTrip => 'Round trip'; + + @override + String get map_pathTraceModeRoundTripHint => + 'The trace goes out through these hops and comes back the same way.'; + + @override + String get map_pathTraceModeAsEntered => 'As entered'; + + @override + String get map_pathTraceModeAsEnteredHint => + 'The trace follows these hops exactly. Add the hops back to you yourself.'; + + @override + String get map_pathTraceViewLast => 'View last result'; + @override String get mapCache_title => 'Offline-Karten-Cache'; diff --git a/lib/l10n/app_localizations_en.dart b/lib/l10n/app_localizations_en.dart index b0a2a765..1a6076fe 100644 --- a/lib/l10n/app_localizations_en.dart +++ b/lib/l10n/app_localizations_en.dart @@ -2344,6 +2344,27 @@ class AppLocalizationsEn extends AppLocalizations { @override String get map_pathTraceCancelled => 'Path trace cancelled.'; + @override + String get map_pathTraceAddMoreHint => + 'Tap more nodes to add hops, choose how the trace returns, then tap Run path trace.'; + + @override + String get map_pathTraceModeRoundTrip => 'Round trip'; + + @override + String get map_pathTraceModeRoundTripHint => + 'The trace goes out through these hops and comes back the same way.'; + + @override + String get map_pathTraceModeAsEntered => 'As entered'; + + @override + String get map_pathTraceModeAsEnteredHint => + 'The trace follows these hops exactly. Add the hops back to you yourself.'; + + @override + String get map_pathTraceViewLast => 'View last result'; + @override String get mapCache_title => 'Offline Map Cache'; diff --git a/lib/l10n/app_localizations_es.dart b/lib/l10n/app_localizations_es.dart index b98b0ff8..016d6ada 100644 --- a/lib/l10n/app_localizations_es.dart +++ b/lib/l10n/app_localizations_es.dart @@ -2374,6 +2374,27 @@ class AppLocalizationsEs extends AppLocalizations { @override String get map_pathTraceCancelled => 'Traza de ruta cancelada.'; + @override + String get map_pathTraceAddMoreHint => + 'Tap more nodes to add hops, choose how the trace returns, then tap Run path trace.'; + + @override + String get map_pathTraceModeRoundTrip => 'Round trip'; + + @override + String get map_pathTraceModeRoundTripHint => + 'The trace goes out through these hops and comes back the same way.'; + + @override + String get map_pathTraceModeAsEntered => 'As entered'; + + @override + String get map_pathTraceModeAsEnteredHint => + 'The trace follows these hops exactly. Add the hops back to you yourself.'; + + @override + String get map_pathTraceViewLast => 'View last result'; + @override String get mapCache_title => 'Caché de mapa sin conexión'; diff --git a/lib/l10n/app_localizations_fr.dart b/lib/l10n/app_localizations_fr.dart index edbcc624..146b996c 100644 --- a/lib/l10n/app_localizations_fr.dart +++ b/lib/l10n/app_localizations_fr.dart @@ -2382,6 +2382,27 @@ class AppLocalizationsFr extends AppLocalizations { @override String get map_pathTraceCancelled => 'Traçage de chemin annulé'; + @override + String get map_pathTraceAddMoreHint => + 'Tap more nodes to add hops, choose how the trace returns, then tap Run path trace.'; + + @override + String get map_pathTraceModeRoundTrip => 'Round trip'; + + @override + String get map_pathTraceModeRoundTripHint => + 'The trace goes out through these hops and comes back the same way.'; + + @override + String get map_pathTraceModeAsEntered => 'As entered'; + + @override + String get map_pathTraceModeAsEnteredHint => + 'The trace follows these hops exactly. Add the hops back to you yourself.'; + + @override + String get map_pathTraceViewLast => 'View last result'; + @override String get mapCache_title => 'Cache de carte hors ligne'; diff --git a/lib/l10n/app_localizations_hu.dart b/lib/l10n/app_localizations_hu.dart index 3827557e..945d5855 100644 --- a/lib/l10n/app_localizations_hu.dart +++ b/lib/l10n/app_localizations_hu.dart @@ -2371,6 +2371,27 @@ class AppLocalizationsHu extends AppLocalizations { @override String get map_pathTraceCancelled => 'Útvonal nyomkövetés törölve.'; + @override + String get map_pathTraceAddMoreHint => + 'Tap more nodes to add hops, choose how the trace returns, then tap Run path trace.'; + + @override + String get map_pathTraceModeRoundTrip => 'Round trip'; + + @override + String get map_pathTraceModeRoundTripHint => + 'The trace goes out through these hops and comes back the same way.'; + + @override + String get map_pathTraceModeAsEntered => 'As entered'; + + @override + String get map_pathTraceModeAsEnteredHint => + 'The trace follows these hops exactly. Add the hops back to you yourself.'; + + @override + String get map_pathTraceViewLast => 'View last result'; + @override String get mapCache_title => 'Offline térképgyorsítótár'; diff --git a/lib/l10n/app_localizations_it.dart b/lib/l10n/app_localizations_it.dart index c62f86d8..481cb685 100644 --- a/lib/l10n/app_localizations_it.dart +++ b/lib/l10n/app_localizations_it.dart @@ -2380,6 +2380,27 @@ class AppLocalizationsIt extends AppLocalizations { @override String get map_pathTraceCancelled => 'Tracciamento del percorso annullato.'; + @override + String get map_pathTraceAddMoreHint => + 'Tap more nodes to add hops, choose how the trace returns, then tap Run path trace.'; + + @override + String get map_pathTraceModeRoundTrip => 'Round trip'; + + @override + String get map_pathTraceModeRoundTripHint => + 'The trace goes out through these hops and comes back the same way.'; + + @override + String get map_pathTraceModeAsEntered => 'As entered'; + + @override + String get map_pathTraceModeAsEnteredHint => + 'The trace follows these hops exactly. Add the hops back to you yourself.'; + + @override + String get map_pathTraceViewLast => 'View last result'; + @override String get mapCache_title => 'Cache mappa offline'; diff --git a/lib/l10n/app_localizations_ja.dart b/lib/l10n/app_localizations_ja.dart index fe2ec05b..19eb80f1 100644 --- a/lib/l10n/app_localizations_ja.dart +++ b/lib/l10n/app_localizations_ja.dart @@ -2276,6 +2276,27 @@ class AppLocalizationsJa extends AppLocalizations { @override String get map_pathTraceCancelled => '経路トレースはキャンセルされました'; + @override + String get map_pathTraceAddMoreHint => + 'Tap more nodes to add hops, choose how the trace returns, then tap Run path trace.'; + + @override + String get map_pathTraceModeRoundTrip => 'Round trip'; + + @override + String get map_pathTraceModeRoundTripHint => + 'The trace goes out through these hops and comes back the same way.'; + + @override + String get map_pathTraceModeAsEntered => 'As entered'; + + @override + String get map_pathTraceModeAsEnteredHint => + 'The trace follows these hops exactly. Add the hops back to you yourself.'; + + @override + String get map_pathTraceViewLast => 'View last result'; + @override String get mapCache_title => 'オフライン用地図キャッシュ'; diff --git a/lib/l10n/app_localizations_ko.dart b/lib/l10n/app_localizations_ko.dart index 85771a64..21879bb7 100644 --- a/lib/l10n/app_localizations_ko.dart +++ b/lib/l10n/app_localizations_ko.dart @@ -2282,6 +2282,27 @@ class AppLocalizationsKo extends AppLocalizations { @override String get map_pathTraceCancelled => '경로 추적 기능이 취소되었습니다.'; + @override + String get map_pathTraceAddMoreHint => + 'Tap more nodes to add hops, choose how the trace returns, then tap Run path trace.'; + + @override + String get map_pathTraceModeRoundTrip => 'Round trip'; + + @override + String get map_pathTraceModeRoundTripHint => + 'The trace goes out through these hops and comes back the same way.'; + + @override + String get map_pathTraceModeAsEntered => 'As entered'; + + @override + String get map_pathTraceModeAsEnteredHint => + 'The trace follows these hops exactly. Add the hops back to you yourself.'; + + @override + String get map_pathTraceViewLast => 'View last result'; + @override String get mapCache_title => '오프라인 지도 캐시'; diff --git a/lib/l10n/app_localizations_nl.dart b/lib/l10n/app_localizations_nl.dart index 846a16c5..1c2d37c5 100644 --- a/lib/l10n/app_localizations_nl.dart +++ b/lib/l10n/app_localizations_nl.dart @@ -2363,6 +2363,27 @@ class AppLocalizationsNl extends AppLocalizations { @override String get map_pathTraceCancelled => 'Pad traceren geannuleerd'; + @override + String get map_pathTraceAddMoreHint => + 'Tap more nodes to add hops, choose how the trace returns, then tap Run path trace.'; + + @override + String get map_pathTraceModeRoundTrip => 'Round trip'; + + @override + String get map_pathTraceModeRoundTripHint => + 'The trace goes out through these hops and comes back the same way.'; + + @override + String get map_pathTraceModeAsEntered => 'As entered'; + + @override + String get map_pathTraceModeAsEnteredHint => + 'The trace follows these hops exactly. Add the hops back to you yourself.'; + + @override + String get map_pathTraceViewLast => 'View last result'; + @override String get mapCache_title => 'Offline Kaarten Cache'; diff --git a/lib/l10n/app_localizations_pl.dart b/lib/l10n/app_localizations_pl.dart index 4b136469..d979502b 100644 --- a/lib/l10n/app_localizations_pl.dart +++ b/lib/l10n/app_localizations_pl.dart @@ -2399,6 +2399,27 @@ class AppLocalizationsPl extends AppLocalizations { @override String get map_pathTraceCancelled => 'Śledzenie ścieżki anulowano.'; + @override + String get map_pathTraceAddMoreHint => + 'Tap more nodes to add hops, choose how the trace returns, then tap Run path trace.'; + + @override + String get map_pathTraceModeRoundTrip => 'Round trip'; + + @override + String get map_pathTraceModeRoundTripHint => + 'The trace goes out through these hops and comes back the same way.'; + + @override + String get map_pathTraceModeAsEntered => 'As entered'; + + @override + String get map_pathTraceModeAsEnteredHint => + 'The trace follows these hops exactly. Add the hops back to you yourself.'; + + @override + String get map_pathTraceViewLast => 'View last result'; + @override String get mapCache_title => 'Pamięć podręczna map offline'; diff --git a/lib/l10n/app_localizations_pt.dart b/lib/l10n/app_localizations_pt.dart index 83370e83..de0432fa 100644 --- a/lib/l10n/app_localizations_pt.dart +++ b/lib/l10n/app_localizations_pt.dart @@ -2378,6 +2378,27 @@ class AppLocalizationsPt extends AppLocalizations { @override String get map_pathTraceCancelled => 'Rastreamento de caminho cancelado.'; + @override + String get map_pathTraceAddMoreHint => + 'Tap more nodes to add hops, choose how the trace returns, then tap Run path trace.'; + + @override + String get map_pathTraceModeRoundTrip => 'Round trip'; + + @override + String get map_pathTraceModeRoundTripHint => + 'The trace goes out through these hops and comes back the same way.'; + + @override + String get map_pathTraceModeAsEntered => 'As entered'; + + @override + String get map_pathTraceModeAsEnteredHint => + 'The trace follows these hops exactly. Add the hops back to you yourself.'; + + @override + String get map_pathTraceViewLast => 'View last result'; + @override String get mapCache_title => 'Cache de Mapa Offline'; diff --git a/lib/l10n/app_localizations_ru.dart b/lib/l10n/app_localizations_ru.dart index 90ead826..52835bdc 100644 --- a/lib/l10n/app_localizations_ru.dart +++ b/lib/l10n/app_localizations_ru.dart @@ -2384,6 +2384,27 @@ class AppLocalizationsRu extends AppLocalizations { @override String get map_pathTraceCancelled => 'Отмена трассировки пути'; + @override + String get map_pathTraceAddMoreHint => + 'Tap more nodes to add hops, choose how the trace returns, then tap Run path trace.'; + + @override + String get map_pathTraceModeRoundTrip => 'Round trip'; + + @override + String get map_pathTraceModeRoundTripHint => + 'The trace goes out through these hops and comes back the same way.'; + + @override + String get map_pathTraceModeAsEntered => 'As entered'; + + @override + String get map_pathTraceModeAsEnteredHint => + 'The trace follows these hops exactly. Add the hops back to you yourself.'; + + @override + String get map_pathTraceViewLast => 'View last result'; + @override String get mapCache_title => 'Кэш офлайн-карты'; diff --git a/lib/l10n/app_localizations_sk.dart b/lib/l10n/app_localizations_sk.dart index 3fb71532..eb5973af 100644 --- a/lib/l10n/app_localizations_sk.dart +++ b/lib/l10n/app_localizations_sk.dart @@ -2371,6 +2371,27 @@ class AppLocalizationsSk extends AppLocalizations { @override String get map_pathTraceCancelled => 'Zrušenie stopáže cesty bolo zrušené.'; + @override + String get map_pathTraceAddMoreHint => + 'Tap more nodes to add hops, choose how the trace returns, then tap Run path trace.'; + + @override + String get map_pathTraceModeRoundTrip => 'Round trip'; + + @override + String get map_pathTraceModeRoundTripHint => + 'The trace goes out through these hops and comes back the same way.'; + + @override + String get map_pathTraceModeAsEntered => 'As entered'; + + @override + String get map_pathTraceModeAsEnteredHint => + 'The trace follows these hops exactly. Add the hops back to you yourself.'; + + @override + String get map_pathTraceViewLast => 'View last result'; + @override String get mapCache_title => 'Offline Mapa Pamäť'; diff --git a/lib/l10n/app_localizations_sl.dart b/lib/l10n/app_localizations_sl.dart index d62c3ebb..5c248ec8 100644 --- a/lib/l10n/app_localizations_sl.dart +++ b/lib/l10n/app_localizations_sl.dart @@ -2364,6 +2364,27 @@ class AppLocalizationsSl extends AppLocalizations { @override String get map_pathTraceCancelled => 'Spremljanje poti je prekinjeno.'; + @override + String get map_pathTraceAddMoreHint => + 'Tap more nodes to add hops, choose how the trace returns, then tap Run path trace.'; + + @override + String get map_pathTraceModeRoundTrip => 'Round trip'; + + @override + String get map_pathTraceModeRoundTripHint => + 'The trace goes out through these hops and comes back the same way.'; + + @override + String get map_pathTraceModeAsEntered => 'As entered'; + + @override + String get map_pathTraceModeAsEnteredHint => + 'The trace follows these hops exactly. Add the hops back to you yourself.'; + + @override + String get map_pathTraceViewLast => 'View last result'; + @override String get mapCache_title => 'Omrezni predpomnilnik zemljeških zemljejevskih slik'; diff --git a/lib/l10n/app_localizations_sv.dart b/lib/l10n/app_localizations_sv.dart index c978fd21..74f13f7a 100644 --- a/lib/l10n/app_localizations_sv.dart +++ b/lib/l10n/app_localizations_sv.dart @@ -2353,6 +2353,27 @@ class AppLocalizationsSv extends AppLocalizations { @override String get map_pathTraceCancelled => 'Ruttspårningen avbröts.'; + @override + String get map_pathTraceAddMoreHint => + 'Tap more nodes to add hops, choose how the trace returns, then tap Run path trace.'; + + @override + String get map_pathTraceModeRoundTrip => 'Round trip'; + + @override + String get map_pathTraceModeRoundTripHint => + 'The trace goes out through these hops and comes back the same way.'; + + @override + String get map_pathTraceModeAsEntered => 'As entered'; + + @override + String get map_pathTraceModeAsEnteredHint => + 'The trace follows these hops exactly. Add the hops back to you yourself.'; + + @override + String get map_pathTraceViewLast => 'View last result'; + @override String get mapCache_title => 'Offline Kartcache'; diff --git a/lib/l10n/app_localizations_uk.dart b/lib/l10n/app_localizations_uk.dart index 267c2188..f3516a3a 100644 --- a/lib/l10n/app_localizations_uk.dart +++ b/lib/l10n/app_localizations_uk.dart @@ -2374,6 +2374,27 @@ class AppLocalizationsUk extends AppLocalizations { @override String get map_pathTraceCancelled => 'Трасування шляху скасовано.'; + @override + String get map_pathTraceAddMoreHint => + 'Tap more nodes to add hops, choose how the trace returns, then tap Run path trace.'; + + @override + String get map_pathTraceModeRoundTrip => 'Round trip'; + + @override + String get map_pathTraceModeRoundTripHint => + 'The trace goes out through these hops and comes back the same way.'; + + @override + String get map_pathTraceModeAsEntered => 'As entered'; + + @override + String get map_pathTraceModeAsEnteredHint => + 'The trace follows these hops exactly. Add the hops back to you yourself.'; + + @override + String get map_pathTraceViewLast => 'View last result'; + @override String get mapCache_title => 'Офлайн-кеш карти'; diff --git a/lib/l10n/app_localizations_zh.dart b/lib/l10n/app_localizations_zh.dart index 7900ed8b..c6a0c2b7 100644 --- a/lib/l10n/app_localizations_zh.dart +++ b/lib/l10n/app_localizations_zh.dart @@ -2247,6 +2247,27 @@ class AppLocalizationsZh extends AppLocalizations { @override String get map_pathTraceCancelled => '路径追踪已取消'; + @override + String get map_pathTraceAddMoreHint => + 'Tap more nodes to add hops, choose how the trace returns, then tap Run path trace.'; + + @override + String get map_pathTraceModeRoundTrip => 'Round trip'; + + @override + String get map_pathTraceModeRoundTripHint => + 'The trace goes out through these hops and comes back the same way.'; + + @override + String get map_pathTraceModeAsEntered => 'As entered'; + + @override + String get map_pathTraceModeAsEnteredHint => + 'The trace follows these hops exactly. Add the hops back to you yourself.'; + + @override + String get map_pathTraceViewLast => 'View last result'; + @override String get mapCache_title => '离线地图缓存'; diff --git a/lib/models/map_path_trace_draft.dart b/lib/models/map_path_trace_draft.dart new file mode 100644 index 00000000..a1c0bfba --- /dev/null +++ b/lib/models/map_path_trace_draft.dart @@ -0,0 +1,31 @@ +import 'package:flutter/foundation.dart'; +import 'package:latlong2/latlong.dart'; + +import 'contact.dart'; + +/// The map's path-trace builder state: the hops picked so far, the trace +/// mode and the last result. Held by [UiViewStateService] for the app session +/// so leaving the map or opening the result doesn't discard it. +class MapPathTraceDraft { + bool active = false; + Uint8List? radioKey; + final List pathBytes = []; + final List hopWidths = []; + final List contacts = []; + final List points = []; + bool returnPath = true; + Uint8List? lastResultFrame; + + bool get hasHops => pathBytes.isNotEmpty; + + bool belongsTo(Uint8List? selfKey) => + radioKey == null || selfKey == null || listEquals(radioKey, selfKey); + + void clear() { + pathBytes.clear(); + hopWidths.clear(); + contacts.clear(); + points.clear(); + lastResultFrame = null; + } +} diff --git a/lib/screens/map_screen.dart b/lib/screens/map_screen.dart index 99de82dc..2c62f423 100644 --- a/lib/screens/map_screen.dart +++ b/lib/screens/map_screen.dart @@ -16,6 +16,7 @@ import '../connector/meshcore_protocol.dart'; import '../l10n/l10n.dart'; import '../models/app_settings.dart'; import '../models/channel.dart'; +import '../models/map_path_trace_draft.dart'; import '../models/contact.dart'; import '../models/path_history.dart'; import '../l10n/contact_localization.dart'; @@ -86,14 +87,18 @@ class _MapScreenState extends State with DisconnectNavigationMixin { final NetworkMapOnlineController _online = NetworkMapOnlineController(); final Set _hiddenMarkerIds = {}; Set _removedMarkerIds = {}; - bool _isBuildingPathTrace = false; + late final MapPathTraceDraft _traceDraft = context + .read() + .mapPathTrace; + bool get _isBuildingPathTrace => _traceDraft.active; + set _isBuildingPathTrace(bool value) => _traceDraft.active = value; bool _isSelectingPoi = false; bool _hasInitializedMap = false; bool _removedMarkersLoaded = false; - final List _pathTrace = []; - final List _pathTraceHopWidths = []; - final List _pathTraceContacts = []; - final List _points = []; + List get _pathTrace => _traceDraft.pathBytes; + List get _pathTraceHopWidths => _traceDraft.hopWidths; + List get _pathTraceContacts => _traceDraft.contacts; + List get _points => _traceDraft.points; final List _polylines = []; bool _statsExpanded = false; bool _showNodeLabels = true; @@ -719,7 +724,10 @@ class _MapScreenState extends State with DisconnectNavigationMixin { .length; return PopScope( - canPop: allowBack, + canPop: allowBack && !_isBuildingPathTrace, + onPopInvokedWithResult: (didPop, _) { + if (!didPop && _isBuildingPathTrace) _closePathTrace(); + }, child: Scaffold( appBar: AppBar( backgroundColor: scheme.surface, @@ -745,7 +753,8 @@ class _MapScreenState extends State with DisconnectNavigationMixin { Text(context.l10n.contacts_pathTrace), ], ), - onTap: () => _startPath( + onTap: () => _openPathTrace( + connector, LatLng( connector.selfLatitude!, connector.selfLongitude!, @@ -3700,18 +3709,40 @@ class _MapScreenState extends State with DisconnectNavigationMixin { ), ); // Add contact to path trace contacts _points.add(position ?? LatLng(contact.latitude!, contact.longitude!)); + _traceDraft.lastResultFrame = null; }); } - void _startPath(LatLng position) { + /// Opens the path-trace builder, resuming hops picked earlier this session + /// on the same radio. + void _openPathTrace(MeshCoreConnector connector, LatLng position) { setState(() { + final selfKey = connector.selfPublicKey; + if (!_traceDraft.belongsTo(selfKey) || !_traceDraft.hasHops) { + _traceDraft.clear(); + } + _traceDraft.radioKey = selfKey; + if (_points.isEmpty) { + _points.add(position); + } else { + _points[0] = position; + } _isBuildingPathTrace = true; - _pathTrace.clear(); - _pathTraceHopWidths.clear(); - _pathTraceContacts.clear(); - _points.clear(); - _polylines.clear(); - _points.add(position); + }); + } + + /// Hides the builder but keeps the picked hops and last result. + void _closePathTrace() { + setState(() { + _isBuildingPathTrace = false; + }); + } + + void _clearPath() { + setState(() { + final start = _points.isNotEmpty ? _points.first : null; + _traceDraft.clear(); + if (start != null) _points.add(start); }); } @@ -3730,16 +3761,55 @@ class _MapScreenState extends State with DisconnectNavigationMixin { _pathTrace.length - hopByteCount, _pathTrace.length, ); - _points.removeLast(); // Remove last point from points list - _polylines.clear(); // Clear polylines + _points.removeLast(); + _traceDraft.lastResultFrame = null; }); } + void _setTraceReturnPath(bool returnPath) { + if (_traceDraft.returnPath == returnPath) return; + setState(() { + _traceDraft.returnPath = returnPath; + _traceDraft.lastResultFrame = null; + }); + } + + void _openTraceResult({required bool reuseLastResult}) { + final draft = _traceDraft; + final path = Uint8List.fromList(_pathTrace); + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => PathTraceMapScreen( + title: context.l10n.contacts_pathTrace, + path: path, + flipPathAround: draft.returnPath, + pathHashByteWidth: context + .read() + .pathHashByteWidth, + pathContacts: List.of(_pathTraceContacts), + initialTraceFrame: reuseLastResult ? draft.lastResultFrame : null, + onTraceFrame: (frame) { + // Ignore a reply for a selection the user has since changed. + if (!listEquals(draft.pathBytes, path)) return; + draft.lastResultFrame = frame; + if (mounted) setState(() {}); + }, + ), + ), + ); + } + Widget _buildPathTraceOverlay() { final l10n = context.l10n; + final theme = Theme.of(context); final isImperial = context.read().settings.unitSystem == UnitSystem.imperial; + final hasHops = _pathTrace.isNotEmpty; + final returnPath = _traceDraft.returnPath; + const buttonSize = Size(48, 48); + final hopNames = _pathTraceContacts.map((c) => c.name).join(' → '); return Positioned( top: 16, left: 16, @@ -3763,124 +3833,136 @@ class _MapScreenState extends State with DisconnectNavigationMixin { padding: const EdgeInsets.all(12.0), child: Column( mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.stretch, children: [ + Row( + children: [ + Expanded( + child: Text( + l10n.contacts_pathTrace, + style: theme.textTheme.titleMedium?.copyWith( + fontWeight: FontWeight.bold, + color: _overlayPrimaryTextColor, + ), + ), + ), + TextButton.icon( + onPressed: _closePathTrace, + style: TextButton.styleFrom(minimumSize: buttonSize), + icon: const Icon(Icons.close), + label: Text(l10n.common_close), + ), + ], + ), + const SizedBox(height: 4), Text( - l10n.contacts_pathTrace, + hasHops ? l10n.map_pathTraceAddMoreHint : l10n.map_tapToAdd, style: TextStyle( - fontWeight: FontWeight.bold, - color: _overlayPrimaryTextColor, + fontSize: 15, + color: _overlaySecondaryTextColor, ), ), - if (_pathTrace.isEmpty) const SizedBox(height: 8), - if (_pathTrace.isEmpty) + if (hasHops) ...[ + const SizedBox(height: 8), Text( - l10n.map_tapToAdd, + hopNames, style: TextStyle( - fontSize: 12, - color: _overlaySecondaryTextColor, + fontSize: 16, + fontWeight: FontWeight.w600, + color: _overlayPrimaryTextColor, + ), + ), + SelectableText( + PathHelper.splitPathBytes( + _pathTrace, + context.read().pathHashByteWidth, + ).map(PathHelper.formatHopHex).join(','), + style: MeshTheme.mono( + fontSize: 18, + fontWeight: FontWeight.w700, + color: MapPalette.selected, ), ), - const SizedBox(height: 6), - if (_pathTrace.isNotEmpty) Text( "${l10n.path_currentPathLabel} ${formatDistance(getPathDistanceMeters(_points), isImperial: isImperial)}", style: MeshTheme.mono( - fontSize: 12, + fontSize: 14, color: _overlaySecondaryTextColor, ), ), - SelectableText( - PathHelper.splitPathBytes( - _pathTrace, - context.read().pathHashByteWidth, - ).map(PathHelper.formatHopHex).join(','), - style: MeshTheme.mono( - fontSize: 18, - fontWeight: FontWeight.w700, - color: MapPalette.selected, - ), - ), - // const SizedBox(height: 6), - Wrap( - alignment: WrapAlignment.center, - spacing: 1, - runSpacing: 1, - children: [ - if (_pathTrace.isNotEmpty) - IconButton( - onPressed: () { - final hashW = context - .read() - .pathHashByteWidth; - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => PathTraceMapScreen( - title: l10n.contacts_pathTrace, - path: Uint8List.fromList(_pathTrace), - flipPathAround: false, - pathHashByteWidth: hashW, - pathContacts: _pathTraceContacts, - ), - ), - ); - setState(() { - _isBuildingPathTrace = false; - }); - }, - tooltip: l10n.map_runTrace, - icon: const Icon(Icons.arrow_forward_outlined), - ), - if (_pathTrace.isNotEmpty) - IconButton( - onPressed: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => PathTraceMapScreen( - title: l10n.contacts_pathTrace, - path: Uint8List.fromList(_pathTrace), - flipPathAround: true, - pathHashByteWidth: context - .read() - .pathHashByteWidth, - pathContacts: _pathTraceContacts, - ), - ), - ); - setState(() { - _isBuildingPathTrace = false; - }); - }, - tooltip: l10n.map_runTraceWithReturnPath, - icon: const Icon(Icons.replay), - ), - if (_pathTrace.isNotEmpty) - IconButton( + const SizedBox(height: 4), + Wrap( + spacing: 8, + children: [ + TextButton.icon( onPressed: _removePath, - tooltip: l10n.map_removeLast, + style: TextButton.styleFrom(minimumSize: buttonSize), icon: const Icon(Icons.undo), + label: Text(l10n.map_removeLast), ), - if (_pathTrace.isEmpty) - IconButton( - onPressed: () { - setState(() { - _isBuildingPathTrace = false; - _pathTrace.clear(); - _pathTraceHopWidths.clear(); - _points.clear(); - _polylines.clear(); - }); - showDismissibleSnackBar( - context, - content: Text(l10n.map_pathTraceCancelled), - ); - }, - tooltip: l10n.common_cancel, - icon: const Icon(Icons.close), + TextButton.icon( + onPressed: _clearPath, + style: TextButton.styleFrom(minimumSize: buttonSize), + icon: const Icon(Icons.delete_outline), + label: Text(l10n.common_clear), ), - ], - ), + ], + ), + const SizedBox(height: 4), + SegmentedButton( + segments: [ + ButtonSegment( + value: true, + icon: const Icon(Icons.sync_alt), + label: Text(l10n.map_pathTraceModeRoundTrip), + ), + ButtonSegment( + value: false, + icon: const Icon(Icons.arrow_forward), + label: Text(l10n.map_pathTraceModeAsEntered), + ), + ], + selected: {returnPath}, + onSelectionChanged: (selection) => + _setTraceReturnPath(selection.first), + style: SegmentedButton.styleFrom(minimumSize: buttonSize), + ), + const SizedBox(height: 6), + Text( + returnPath + ? l10n.map_pathTraceModeRoundTripHint + : l10n.map_pathTraceModeAsEnteredHint, + style: TextStyle( + fontSize: 14, + color: _overlaySecondaryTextColor, + ), + ), + const SizedBox(height: 10), + Wrap( + spacing: 8, + runSpacing: 8, + alignment: WrapAlignment.end, + children: [ + if (_traceDraft.lastResultFrame != null) + OutlinedButton.icon( + onPressed: () => + _openTraceResult(reuseLastResult: true), + style: OutlinedButton.styleFrom( + minimumSize: buttonSize, + ), + icon: const Icon(Icons.history), + label: Text(l10n.map_pathTraceViewLast), + ), + FilledButton.icon( + onPressed: () => + _openTraceResult(reuseLastResult: false), + style: FilledButton.styleFrom(minimumSize: buttonSize), + icon: const Icon(Icons.radar), + label: Text(l10n.map_runTrace), + ), + ], + ), + ], ], ), ), diff --git a/lib/screens/path_trace_map.dart b/lib/screens/path_trace_map.dart index 43d21d70..bdf78612 100644 --- a/lib/screens/path_trace_map.dart +++ b/lib/screens/path_trace_map.dart @@ -65,6 +65,13 @@ class PathTraceMapScreen extends StatefulWidget { final int pathHashByteWidth; final List? pathContacts; + /// A previous PUSH_CODE_TRACE_DATA frame to show instead of sending a new + /// trace when the screen opens. + final Uint8List? initialTraceFrame; + + /// Called with each trace response frame this screen receives. + final ValueChanged? onTraceFrame; + const PathTraceMapScreen({ super.key, required this.title, @@ -75,6 +82,8 @@ class PathTraceMapScreen extends StatefulWidget { this.targetContact, this.pathHashByteWidth = pathHashSize, this.pathContacts, + this.initialTraceFrame, + this.onTraceFrame, }); @override @@ -220,7 +229,20 @@ class _PathTraceMapScreenState extends State _pathHistory = context.read(); _pathHistory!.addListener(_onPathHistoryChanged); _setupFrameListener(); - _doPathTrace(); + final initialFrame = widget.initialTraceFrame; + if (initialFrame == null) { + _doPathTrace(); + return; + } + final (livePath, hopWidth) = _resolveLivePath( + context.read(), + ); + _tracedPath = livePath; + _tracedPathHashWidth = hopWidth; + _isLoading = true; + WidgetsBinding.instance.addPostFrameCallback((_) { + if (mounted) _handleTraceResponse(initialFrame); + }); } @override @@ -501,6 +523,7 @@ class _PathTraceMapScreenState extends State (listEquals(frame.sublist(4, 8), _sentTagBytes) || listEquals(frame.sublist(4, 8), _sentAckTag))) { _timeoutTimer?.cancel(); + widget.onTraceFrame?.call(frame); if (!mounted) return; _handleTraceResponse(frame); } diff --git a/lib/services/ui_view_state_service.dart b/lib/services/ui_view_state_service.dart index 46ae0a3b..34e31921 100644 --- a/lib/services/ui_view_state_service.dart +++ b/lib/services/ui_view_state_service.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'package:flutter/foundation.dart'; +import '../models/map_path_trace_draft.dart'; import '../storage/prefs_manager.dart'; import '../utils/contact_search.dart'; @@ -33,6 +34,8 @@ class UiViewStateService extends ChangeNotifier { ChannelSortOption _channelsSortOption = ChannelSortOption.manual; MapSourceOption _mapSource = MapSourceOption.local; + final MapPathTraceDraft mapPathTrace = MapPathTraceDraft(); + String get contactsSelectedGroupName => _contactsSelectedGroupName; String get contactsSearchText => _contactsSearchText; bool get contactsSearchExpanded => _contactsSearchExpanded; diff --git a/test/models/map_path_trace_draft_test.dart b/test/models/map_path_trace_draft_test.dart new file mode 100644 index 00000000..d0c39e1f --- /dev/null +++ b/test/models/map_path_trace_draft_test.dart @@ -0,0 +1,46 @@ +import 'dart:typed_data'; + +import 'package:flutter_test/flutter_test.dart'; +import 'package:latlong2/latlong.dart'; +import 'package:meshcore_open/models/map_path_trace_draft.dart'; +import 'package:meshcore_open/services/ui_view_state_service.dart'; + +void main() { + test('draft survives on the shared view state service', () { + final service = UiViewStateService(); + final draft = service.mapPathTrace + ..active = true + ..returnPath = false; + draft.pathBytes.addAll([0xAB, 0xCD]); + draft.points.add(const LatLng(1, 2)); + + expect(identical(service.mapPathTrace, draft), isTrue); + expect(service.mapPathTrace.hasHops, isTrue); + expect(service.mapPathTrace.returnPath, isFalse); + }); + + test('clear drops hops and the last result but keeps the mode', () { + final draft = MapPathTraceDraft() + ..returnPath = false + ..lastResultFrame = Uint8List.fromList([1, 2, 3]); + draft.pathBytes.add(0xAB); + draft.hopWidths.add(1); + draft.points.add(const LatLng(1, 2)); + + draft.clear(); + + expect(draft.hasHops, isFalse); + expect(draft.hopWidths, isEmpty); + expect(draft.points, isEmpty); + expect(draft.lastResultFrame, isNull); + expect(draft.returnPath, isFalse); + }); + + test('belongsTo matches only the radio it was built on', () { + final draft = MapPathTraceDraft(); + expect(draft.belongsTo(Uint8List.fromList([1, 2])), isTrue); + draft.radioKey = Uint8List.fromList([1, 2]); + expect(draft.belongsTo(Uint8List.fromList([1, 2])), isTrue); + expect(draft.belongsTo(Uint8List.fromList([3, 4])), isFalse); + }); +} diff --git a/untranslated.json b/untranslated.json index 9c7f62ad..016981e1 100644 --- a/untranslated.json +++ b/untranslated.json @@ -1,5 +1,11 @@ { "bg": [ + "map_pathTraceAddMoreHint", + "map_pathTraceModeRoundTrip", + "map_pathTraceModeRoundTripHint", + "map_pathTraceModeAsEntered", + "map_pathTraceModeAsEnteredHint", + "map_pathTraceViewLast", "notification_sharedLocation", "notification_sharedLocationNamed", "notification_reacted", @@ -14,6 +20,12 @@ ], "de": [ + "map_pathTraceAddMoreHint", + "map_pathTraceModeRoundTrip", + "map_pathTraceModeRoundTripHint", + "map_pathTraceModeAsEntered", + "map_pathTraceModeAsEnteredHint", + "map_pathTraceViewLast", "notification_sharedLocation", "notification_sharedLocationNamed", "notification_reacted", @@ -28,6 +40,12 @@ ], "es": [ + "map_pathTraceAddMoreHint", + "map_pathTraceModeRoundTrip", + "map_pathTraceModeRoundTripHint", + "map_pathTraceModeAsEntered", + "map_pathTraceModeAsEnteredHint", + "map_pathTraceViewLast", "notification_sharedLocation", "notification_sharedLocationNamed", "notification_reacted", @@ -42,6 +60,12 @@ ], "fr": [ + "map_pathTraceAddMoreHint", + "map_pathTraceModeRoundTrip", + "map_pathTraceModeRoundTripHint", + "map_pathTraceModeAsEntered", + "map_pathTraceModeAsEnteredHint", + "map_pathTraceViewLast", "notification_sharedLocation", "notification_sharedLocationNamed", "notification_reacted", @@ -56,6 +80,12 @@ ], "hu": [ + "map_pathTraceAddMoreHint", + "map_pathTraceModeRoundTrip", + "map_pathTraceModeRoundTripHint", + "map_pathTraceModeAsEntered", + "map_pathTraceModeAsEnteredHint", + "map_pathTraceViewLast", "notification_sharedLocation", "notification_sharedLocationNamed", "notification_reacted", @@ -70,6 +100,12 @@ ], "it": [ + "map_pathTraceAddMoreHint", + "map_pathTraceModeRoundTrip", + "map_pathTraceModeRoundTripHint", + "map_pathTraceModeAsEntered", + "map_pathTraceModeAsEnteredHint", + "map_pathTraceViewLast", "notification_sharedLocation", "notification_sharedLocationNamed", "notification_reacted", @@ -84,6 +120,12 @@ ], "ja": [ + "map_pathTraceAddMoreHint", + "map_pathTraceModeRoundTrip", + "map_pathTraceModeRoundTripHint", + "map_pathTraceModeAsEntered", + "map_pathTraceModeAsEnteredHint", + "map_pathTraceViewLast", "notification_sharedLocation", "notification_sharedLocationNamed", "notification_reacted", @@ -98,6 +140,12 @@ ], "ko": [ + "map_pathTraceAddMoreHint", + "map_pathTraceModeRoundTrip", + "map_pathTraceModeRoundTripHint", + "map_pathTraceModeAsEntered", + "map_pathTraceModeAsEnteredHint", + "map_pathTraceViewLast", "notification_sharedLocation", "notification_sharedLocationNamed", "notification_reacted", @@ -112,6 +160,12 @@ ], "nl": [ + "map_pathTraceAddMoreHint", + "map_pathTraceModeRoundTrip", + "map_pathTraceModeRoundTripHint", + "map_pathTraceModeAsEntered", + "map_pathTraceModeAsEnteredHint", + "map_pathTraceViewLast", "notification_sharedLocation", "notification_sharedLocationNamed", "notification_reacted", @@ -126,6 +180,12 @@ ], "pl": [ + "map_pathTraceAddMoreHint", + "map_pathTraceModeRoundTrip", + "map_pathTraceModeRoundTripHint", + "map_pathTraceModeAsEntered", + "map_pathTraceModeAsEnteredHint", + "map_pathTraceViewLast", "notification_sharedLocation", "notification_sharedLocationNamed", "notification_reacted", @@ -140,6 +200,12 @@ ], "pt": [ + "map_pathTraceAddMoreHint", + "map_pathTraceModeRoundTrip", + "map_pathTraceModeRoundTripHint", + "map_pathTraceModeAsEntered", + "map_pathTraceModeAsEnteredHint", + "map_pathTraceViewLast", "notification_sharedLocation", "notification_sharedLocationNamed", "notification_reacted", @@ -154,6 +220,12 @@ ], "ru": [ + "map_pathTraceAddMoreHint", + "map_pathTraceModeRoundTrip", + "map_pathTraceModeRoundTripHint", + "map_pathTraceModeAsEntered", + "map_pathTraceModeAsEnteredHint", + "map_pathTraceViewLast", "notification_sharedLocation", "notification_sharedLocationNamed", "notification_reacted", @@ -168,6 +240,12 @@ ], "sk": [ + "map_pathTraceAddMoreHint", + "map_pathTraceModeRoundTrip", + "map_pathTraceModeRoundTripHint", + "map_pathTraceModeAsEntered", + "map_pathTraceModeAsEnteredHint", + "map_pathTraceViewLast", "notification_sharedLocation", "notification_sharedLocationNamed", "notification_reacted", @@ -182,6 +260,12 @@ ], "sl": [ + "map_pathTraceAddMoreHint", + "map_pathTraceModeRoundTrip", + "map_pathTraceModeRoundTripHint", + "map_pathTraceModeAsEntered", + "map_pathTraceModeAsEnteredHint", + "map_pathTraceViewLast", "notification_sharedLocation", "notification_sharedLocationNamed", "notification_reacted", @@ -196,6 +280,12 @@ ], "sv": [ + "map_pathTraceAddMoreHint", + "map_pathTraceModeRoundTrip", + "map_pathTraceModeRoundTripHint", + "map_pathTraceModeAsEntered", + "map_pathTraceModeAsEnteredHint", + "map_pathTraceViewLast", "notification_sharedLocation", "notification_sharedLocationNamed", "notification_reacted", @@ -210,6 +300,12 @@ ], "uk": [ + "map_pathTraceAddMoreHint", + "map_pathTraceModeRoundTrip", + "map_pathTraceModeRoundTripHint", + "map_pathTraceModeAsEntered", + "map_pathTraceModeAsEnteredHint", + "map_pathTraceViewLast", "notification_sharedLocation", "notification_sharedLocationNamed", "notification_reacted", @@ -224,6 +320,12 @@ ], "zh": [ + "map_pathTraceAddMoreHint", + "map_pathTraceModeRoundTrip", + "map_pathTraceModeRoundTripHint", + "map_pathTraceModeAsEntered", + "map_pathTraceModeAsEnteredHint", + "map_pathTraceViewLast", "notification_sharedLocation", "notification_sharedLocationNamed", "notification_reacted",