Compare commits

...

4 Commits
v1.6 ... v1.7

Author SHA1 Message Date
8c5aa820ef Update README.md
Added version information for 1.7
2023-12-13 08:53:00 +00:00
a13f04fa6c Merge pull request #28 from j-a-n/confirm_timeout
Auto close confirmation dialog after timeout
2023-12-11 08:22:10 +00:00
143bcf08a7 Add application property "confirm_timeout"
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.
2023-12-10 22:52:09 +01:00
ee3b2abed2 Auto close confirmation dialog after timeout 2023-12-10 12:16:01 +01:00
4 changed files with 33 additions and 1 deletions

View File

@ -223,3 +223,4 @@ When you change the JSON file defining your dashboard, you must exit the applica
| 1.4 | New lean user Interface with thanks to [SomeoneOnEarth](https://github.com/Someone0nEarth) for their contribution which is now the default. If you prefer the old style you can still select it in the settings. The provision of a 'service' tag is now not just heavily suggested by the JSON schema, it is enforced in code. With apologies to anyone suffering a breakage as a result. |
| 1.5 | <img src="images/confirmation_view.jpg" width="200" title="Confirmation View" style="float:right"/> Added an optional confirmation dialogue view to prevent accidental execution of actions on mistaken tap. This also brings a change in the JSON schema to allow an optional field to specify that the confirmation should be used for a menu item. As we are now maturing and adding features we have decided to mitigate breaking changes to the JSON schema by being more careful to adopt the Home Assistant schema (noting there is a 1:1 mapping between YAML and JSON). This change does deprecate the top level `service` tag in favour of `tag_action` containing multiple fields including `service` & `confirm`. Users should migrate to the new format for the new functionality, but the timescale for actual deprecation are long and undecided. |
| 1.6 | Added a user configurable 'timeout' in seconds so that when no action is taken the application automatically closes, stopping the continuous polling for changes of status and hence saving the drain on the battery. This can be disabled with timeout=0. |
| 1.7 | Added timeout to confirmation views so that when used for security devices it does not linger when left unconfirmed. Thanks to [Jan Schneider](https://github.com/j-a-n) for the contribution. Known bug for devices not supporting [`WatchUi.getCurrentView()`](https://developer.garmin.com/connect-iq/api-docs/Toybox/WatchUi.html#getCurrentView-instance_function) API call which is only available on API Level 3.4.0, e.g. Vivoactive 4S. |

View File

@ -30,6 +30,12 @@
-->
<property id="app_timeout" type="number">0</property>
<!--
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.
-->
<property id="confirm_timeout" type="number">3</property>
<property id="types_representation" type="boolean"></property>
<property id="menu_alignment" type="boolean"></property>

View File

@ -53,6 +53,16 @@
/>
</setting>
<setting
propertyKey="@Properties.confirm_timeout"
title="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."
>
<settingConfig
type="numeric"
min="0"
/>
</setting>
<setting
propertyKey="@Properties.types_representation"
title="Representing types with icons (off) or with labels (on)"

View File

@ -22,9 +22,10 @@ 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));
}
@ -33,17 +34,31 @@ class HomeAssistantConfirmation extends WatchUi.Confirmation {
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);
}
}