mirror of
https://github.com/house-of-abbey/GarminHomeAssistant.git
synced 2025-05-02 05:32:27 +00:00
After this time (in seconds), a confirmation dialog for an action is automatically closed and the action is cancelled. Set to 0 to disable the timeout. The default value is 3 seconds.
65 lines
2.0 KiB
MonkeyC
65 lines
2.0 KiB
MonkeyC
//-----------------------------------------------------------------------------------
|
|
//
|
|
// Distributed under MIT Licence
|
|
// See https://github.com/house-of-abbey/GarminHomeAssistant/blob/main/LICENSE.
|
|
//
|
|
//-----------------------------------------------------------------------------------
|
|
//
|
|
// GarminHomeAssistant is a Garmin IQ application written in Monkey C and routinely
|
|
// tested on a Venu 2 device. The source code is provided at:
|
|
// https://github.com/house-of-abbey/GarminHomeAssistant.
|
|
//
|
|
// P A Abbey & J D Abbey & SomeoneOnEarth, 19 November 2023
|
|
//
|
|
//
|
|
// Description:
|
|
//
|
|
// Calling a Home Assistant confirmation dialogue view.
|
|
//
|
|
//-----------------------------------------------------------------------------------
|
|
|
|
using Toybox.Lang;
|
|
// Required for callback method definition
|
|
typedef Method as Toybox.Lang.Method;
|
|
using Toybox.WatchUi;
|
|
using Toybox.Timer;
|
|
using Toybox.Application.Properties;
|
|
|
|
class HomeAssistantConfirmation extends WatchUi.Confirmation {
|
|
function initialize() {
|
|
WatchUi.Confirmation.initialize(WatchUi.loadResource($.Rez.Strings.Confirm));
|
|
}
|
|
|
|
}
|
|
|
|
class HomeAssistantConfirmationDelegate extends WatchUi.ConfirmationDelegate {
|
|
private var confirmMethod;
|
|
private var timeout;
|
|
|
|
function initialize(callback as Method() as Void) {
|
|
WatchUi.ConfirmationDelegate.initialize();
|
|
confirmMethod = callback;
|
|
var timeoutSeconds = Properties.getValue("confirm_timeout") as Lang.Number;
|
|
if (timeoutSeconds > 0) {
|
|
timeout = new Timer.Timer();
|
|
timeout.start(method(:onTimeout), timeoutSeconds * 1000, true);
|
|
}
|
|
}
|
|
|
|
function onResponse(response) as Lang.Boolean {
|
|
getApp().getQuitTimer().reset();
|
|
if (timeout) {
|
|
timeout.stop();
|
|
}
|
|
if (response == WatchUi.CONFIRM_YES) {
|
|
confirmMethod.invoke();
|
|
}
|
|
return true;
|
|
}
|
|
|
|
function onTimeout() as Void {
|
|
timeout.stop();
|
|
WatchUi.popView(WatchUi.SLIDE_RIGHT);
|
|
}
|
|
}
|