einsatzprotokoll/source/MenuDelegate.mc
EiSiMo 21a62d79c3 Fix tap-to-rotate and GPS cancel crash
- Tap on non-selected icon rotates instead of opening, flag
  prevents onSelect from double-firing
- GpsService.stop() for clean cancellation
- LoadingView stops GPS on hide (BACK button)
- LoadingDelegate allows BACK to cancel GPS acquisition

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 19:41:57 +02:00

71 lines
2.1 KiB
MonkeyC

import Toybox.Lang;
import Toybox.WatchUi;
// Routes menu input. UP/DOWN rotate the ring. START/STOP opens
// the selected item. Tap on an icon rotates to it; tap on the
// already-selected icon opens it.
class MenuDelegate extends WatchUi.BehaviorDelegate {
private var _view as MenuView;
private var _tapHandled as Boolean = false;
function initialize(view as MenuView) {
BehaviorDelegate.initialize();
_view = view;
}
function onNextPage() as Boolean {
_view.rotateNext();
return true;
}
function onPreviousPage() as Boolean {
_view.rotatePrev();
return true;
}
function onTap(evt as WatchUi.ClickEvent) as Boolean {
var coords = evt.getCoordinates();
var tapX = coords[0] as Number;
var tapY = coords[1] as Number;
var idx = _view.itemIndexAt(tapX, tapY);
if (idx >= 0 && idx != _view.selectedIndex()) {
// Tap on non-selected icon → rotate to it, block onSelect.
_view.rotateTo(idx);
_tapHandled = true;
return true;
}
// Tap on selected icon or empty area → let onSelect handle it.
return false;
}
function onSelect() as Boolean {
// If a tap already handled this event, skip.
if (_tapHandled) {
_tapHandled = false;
return true;
}
return _openSelected();
}
private function _openSelected() as Boolean {
var item = _view.selectedItem();
var key = item[:key] as String;
if (key.equals(Config.ACTION_HISTORY)) {
var view = new HistoryView();
WatchUi.pushView(view, new HistoryDelegate(view), WatchUi.SLIDE_LEFT);
return true;
}
if (key.equals(Config.ACTION_DELETE)) {
var view = new DeleteView();
WatchUi.pushView(view, new DeleteDelegate(view), WatchUi.SLIDE_LEFT);
return true;
}
WatchUi.pushView(new LoadingView(key), new LoadingDelegate(), WatchUi.SLIDE_IMMEDIATE);
return true;
}
}