mirror of
https://github.com/house-of-abbey/GarminHomeAssistant.git
synced 2025-07-31 08:58:31 +00:00
HomeAssistantConfirmationDelegate and HomeAssistantPinConfirmationDelegate undo toggles on timeout and reject
This commit is contained in:
@ -38,13 +38,25 @@ class HomeAssistantConfirmationDelegate extends WatchUi.ConfirmationDelegate {
|
|||||||
private var mConfirmMethod as Method(state as Lang.Boolean) as Void;
|
private var mConfirmMethod as Method(state as Lang.Boolean) as Void;
|
||||||
private var mTimer as Timer.Timer or Null;
|
private var mTimer as Timer.Timer or Null;
|
||||||
private var mState as Lang.Boolean;
|
private var mState as Lang.Boolean;
|
||||||
|
private var mToggleMethod as Method(state as Lang.Boolean) as Void or Null;
|
||||||
|
|
||||||
//! Class Constructor
|
//! Class Constructor
|
||||||
|
//!
|
||||||
|
//! @param options A dictionary describing the following options:
|
||||||
|
//! - callback Method to call on confirmation.
|
||||||
|
//! - state Wanted state of a toggle button.
|
||||||
|
//! - toggle Optional setEnabled method to untoggle ToggleItem.
|
||||||
//
|
//
|
||||||
function initialize(callback as Method(state as Lang.Boolean) as Void, state as Lang.Boolean) {
|
function initialize(options as {
|
||||||
|
:callback as Method(state as Lang.Boolean) as Void,
|
||||||
|
:state as Lang.Boolean,
|
||||||
|
:toggleMethod as Method(state as Lang.Boolean) or Null,
|
||||||
|
}) {
|
||||||
WatchUi.ConfirmationDelegate.initialize();
|
WatchUi.ConfirmationDelegate.initialize();
|
||||||
mConfirmMethod = callback;
|
mConfirmMethod = options[:callback];
|
||||||
mState = state;
|
mState = options[:state];
|
||||||
|
mToggleMethod = options[:toggleMethod];
|
||||||
|
|
||||||
var timeout = Settings.getConfirmTimeout(); // ms
|
var timeout = Settings.getConfirmTimeout(); // ms
|
||||||
if (timeout > 0) {
|
if (timeout > 0) {
|
||||||
mTimer = new Timer.Timer();
|
mTimer = new Timer.Timer();
|
||||||
@ -64,6 +76,11 @@ class HomeAssistantConfirmationDelegate extends WatchUi.ConfirmationDelegate {
|
|||||||
}
|
}
|
||||||
if (response == WatchUi.CONFIRM_YES) {
|
if (response == WatchUi.CONFIRM_YES) {
|
||||||
mConfirmMethod.invoke(mState);
|
mConfirmMethod.invoke(mState);
|
||||||
|
} else {
|
||||||
|
// Undo the toggle, if we have one
|
||||||
|
if (mToggleMethod != null) {
|
||||||
|
mToggleMethod.invoke(!mState);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -71,6 +88,10 @@ class HomeAssistantConfirmationDelegate extends WatchUi.ConfirmationDelegate {
|
|||||||
//! Function supplied to a timer in order to limit the time for which the confirmation can be provided.
|
//! Function supplied to a timer in order to limit the time for which the confirmation can be provided.
|
||||||
function onTimeout() as Void {
|
function onTimeout() as Void {
|
||||||
mTimer.stop();
|
mTimer.stop();
|
||||||
|
// Undo the toggle, if we have one
|
||||||
|
if (mToggleMethod != null) {
|
||||||
|
mToggleMethod.invoke(!mState);
|
||||||
|
}
|
||||||
WatchUi.popView(WatchUi.SLIDE_RIGHT);
|
WatchUi.popView(WatchUi.SLIDE_RIGHT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -185,21 +185,25 @@ class HomeAssistantPinConfirmationDelegate extends WatchUi.BehaviorDelegate {
|
|||||||
private var mTimer as Timer.Timer or Null;
|
private var mTimer as Timer.Timer or Null;
|
||||||
private var mState as Lang.Boolean;
|
private var mState as Lang.Boolean;
|
||||||
private var mFailures as PinFailures;
|
private var mFailures as PinFailures;
|
||||||
|
private var mToggleMethod as Method(state as Lang.Boolean) as Void or Null;
|
||||||
private var mView as HomeAssistantPinConfirmationView;
|
private var mView as HomeAssistantPinConfirmationView;
|
||||||
|
|
||||||
//! Class Constructor
|
//! Class Constructor
|
||||||
//!
|
//!
|
||||||
//! @param callback Method to call on confirmation.
|
//! @param options A dictionary describing the following options:
|
||||||
//! @param state Current state of a toggle button.
|
//! - callback Method to call on confirmation.
|
||||||
//! @param pin PIN to be matched.
|
//! - pin PIN to be matched.
|
||||||
//! @param view PIN confirmation view.
|
//! - state Wanted state of a toggle button.
|
||||||
|
//! - toggle Optional setEnabled method to untoggle ToggleItem.
|
||||||
|
//! - view PIN confirmation view.
|
||||||
//
|
//
|
||||||
function initialize(
|
function initialize(options as {
|
||||||
callback as Method(state as Lang.Boolean) as Void,
|
:callback as Method(state as Lang.Boolean) as Void,
|
||||||
state as Lang.Boolean,
|
:pin as Lang.String,
|
||||||
pin as Lang.String,
|
:state as Lang.Boolean,
|
||||||
view as HomeAssistantPinConfirmationView
|
:view as HomeAssistantPinConfirmationView,
|
||||||
) {
|
:toggleMethod as (Method(state as Lang.Boolean) as Void) or Null,
|
||||||
|
}) {
|
||||||
BehaviorDelegate.initialize();
|
BehaviorDelegate.initialize();
|
||||||
mFailures = new PinFailures();
|
mFailures = new PinFailures();
|
||||||
if (mFailures.isLocked()) {
|
if (mFailures.isLocked()) {
|
||||||
@ -208,11 +212,13 @@ class HomeAssistantPinConfirmationDelegate extends WatchUi.BehaviorDelegate {
|
|||||||
WatchUi.loadResource($.Rez.Strings.Seconds);
|
WatchUi.loadResource($.Rez.Strings.Seconds);
|
||||||
WatchUi.showToast(msg, {});
|
WatchUi.showToast(msg, {});
|
||||||
}
|
}
|
||||||
mPin = pin;
|
mPin = options[:pin];
|
||||||
mEnteredPin = "";
|
mEnteredPin = "";
|
||||||
mConfirmMethod = callback;
|
mConfirmMethod = options[:callback];
|
||||||
mState = state;
|
mState = options[:state];
|
||||||
mView = view;
|
mToggleMethod = options[:toggleMethod];
|
||||||
|
mView = options[:view];
|
||||||
|
|
||||||
resetTimer();
|
resetTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,6 +285,10 @@ class HomeAssistantPinConfirmationDelegate extends WatchUi.BehaviorDelegate {
|
|||||||
if (mTimer != null) {
|
if (mTimer != null) {
|
||||||
mTimer.stop();
|
mTimer.stop();
|
||||||
}
|
}
|
||||||
|
// Undo the toggle, if we have one
|
||||||
|
if (mToggleMethod != null) {
|
||||||
|
mToggleMethod.invoke(!mState);
|
||||||
|
}
|
||||||
WatchUi.popView(WatchUi.SLIDE_RIGHT);
|
WatchUi.popView(WatchUi.SLIDE_RIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,14 +82,22 @@ class HomeAssistantTapMenuItem extends HomeAssistantMenuItem {
|
|||||||
var pinConfirmationView = new HomeAssistantPinConfirmationView();
|
var pinConfirmationView = new HomeAssistantPinConfirmationView();
|
||||||
WatchUi.pushView(
|
WatchUi.pushView(
|
||||||
pinConfirmationView,
|
pinConfirmationView,
|
||||||
new HomeAssistantPinConfirmationDelegate(method(:onConfirm), false, pin, pinConfirmationView),
|
new HomeAssistantPinConfirmationDelegate({
|
||||||
|
:callback => method(:onConfirm),
|
||||||
|
:pin => pin,
|
||||||
|
:state => false,
|
||||||
|
:view => pinConfirmationView,
|
||||||
|
}),
|
||||||
WatchUi.SLIDE_IMMEDIATE
|
WatchUi.SLIDE_IMMEDIATE
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else if (mConfirm) {
|
} else if (mConfirm) {
|
||||||
WatchUi.pushView(
|
WatchUi.pushView(
|
||||||
new HomeAssistantConfirmation(),
|
new HomeAssistantConfirmation(),
|
||||||
new HomeAssistantConfirmationDelegate(method(:onConfirm), false),
|
new HomeAssistantConfirmationDelegate({
|
||||||
|
:callback => method(:onConfirm),
|
||||||
|
:state => false,
|
||||||
|
}),
|
||||||
WatchUi.SLIDE_IMMEDIATE
|
WatchUi.SLIDE_IMMEDIATE
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
@ -316,14 +316,24 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
|
|||||||
var pinConfirmationView = new HomeAssistantPinConfirmationView();
|
var pinConfirmationView = new HomeAssistantPinConfirmationView();
|
||||||
WatchUi.pushView(
|
WatchUi.pushView(
|
||||||
pinConfirmationView,
|
pinConfirmationView,
|
||||||
new HomeAssistantPinConfirmationDelegate(method(:onConfirm), b, pin, pinConfirmationView),
|
new HomeAssistantPinConfirmationDelegate({
|
||||||
|
:callback => method(:onConfirm),
|
||||||
|
:pin => pin,
|
||||||
|
:state => b,
|
||||||
|
:toggleMethod => method(:setEnabled),
|
||||||
|
:view => pinConfirmationView,
|
||||||
|
}),
|
||||||
WatchUi.SLIDE_IMMEDIATE
|
WatchUi.SLIDE_IMMEDIATE
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else if (mConfirm) {
|
} else if (mConfirm) {
|
||||||
WatchUi.pushView(
|
WatchUi.pushView(
|
||||||
new HomeAssistantConfirmation(),
|
new HomeAssistantConfirmation(),
|
||||||
new HomeAssistantConfirmationDelegate(method(:onConfirm), b),
|
new HomeAssistantConfirmationDelegate({
|
||||||
|
:callback => method(:onConfirm),
|
||||||
|
:state => b,
|
||||||
|
:toggleMethod => method(:setEnabled),
|
||||||
|
}),
|
||||||
WatchUi.SLIDE_IMMEDIATE
|
WatchUi.SLIDE_IMMEDIATE
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
@ -43,12 +43,12 @@ class WifiLteExecutionConfirmDelegate extends WatchUi.ConfirmationDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mCommandData = {
|
mCommandData = {
|
||||||
:type => cOptions[:type],
|
:type => cOptions[:type],
|
||||||
:service => cOptions[:service],
|
:service => cOptions[:service],
|
||||||
:data => cOptions[:data],
|
:data => cOptions[:data],
|
||||||
:url => cOptions[:url],
|
:url => cOptions[:url],
|
||||||
:callback => cOptions[:callback],
|
:callback => cOptions[:callback],
|
||||||
:exit => cOptions[:exit]
|
:exit => cOptions[:exit]
|
||||||
};
|
};
|
||||||
|
|
||||||
var timeout = Settings.getConfirmTimeout(); // ms
|
var timeout = Settings.getConfirmTimeout(); // ms
|
||||||
|
Reference in New Issue
Block a user