mirror of
https://github.com/house-of-abbey/GarminHomeAssistant.git
synced 2025-08-03 02:18:34 +00:00
validate pin after full length of pin has been entered
This commit is contained in:
@ -98,8 +98,8 @@ class HomeAssistantPinConfirmationView extends WatchUi.View {
|
|||||||
|
|
||||||
class HomeAssistantPinConfirmationDelegate extends WatchUi.BehaviorDelegate {
|
class HomeAssistantPinConfirmationDelegate extends WatchUi.BehaviorDelegate {
|
||||||
|
|
||||||
private var mPin as Array<Char>;
|
private var mPin as String;
|
||||||
private var mCurrentIndex as Number;
|
private var mEnteredPin as String;
|
||||||
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;
|
||||||
@ -114,8 +114,8 @@ class HomeAssistantPinConfirmationDelegate extends WatchUi.BehaviorDelegate {
|
|||||||
WatchUi.loadResource($.Rez.Strings.Seconds);
|
WatchUi.loadResource($.Rez.Strings.Seconds);
|
||||||
WatchUi.showToast(msg, {});
|
WatchUi.showToast(msg, {});
|
||||||
}
|
}
|
||||||
mPin = pin.toCharArray();
|
mPin = pin;
|
||||||
mCurrentIndex = 0;
|
mEnteredPin = "";
|
||||||
mConfirmMethod = callback;
|
mConfirmMethod = callback;
|
||||||
mState = state;
|
mState = state;
|
||||||
resetTimer();
|
resetTimer();
|
||||||
@ -130,10 +130,10 @@ class HomeAssistantPinConfirmationDelegate extends WatchUi.BehaviorDelegate {
|
|||||||
if (Attention has :vibrate && Settings.getVibrate()) {
|
if (Attention has :vibrate && Settings.getVibrate()) {
|
||||||
Attention.vibrate([new Attention.VibeProfile(25, 25)]);
|
Attention.vibrate([new Attention.VibeProfile(25, 25)]);
|
||||||
}
|
}
|
||||||
var currentDigit = mPin[mCurrentIndex].toString().toNumber(); // this is ugly, but apparently the only way for char<->number conversions
|
mEnteredPin += instance.getDigit();
|
||||||
if (currentDigit != null && currentDigit == instance.getDigit()) {
|
// System.println("HomeAssitantPinConfirmationDelegate onSelectable() mEnteredPin = " + mEnteredPin);
|
||||||
// System.println("Pin digit " + (mCurrentIndex+1) + " matches");
|
if (mEnteredPin.length() == mPin.length()) {
|
||||||
if (mCurrentIndex == mPin.size()-1) {
|
if (mEnteredPin.equals(mPin)) {
|
||||||
mFailures.reset();
|
mFailures.reset();
|
||||||
getApp().getQuitTimer().reset();
|
getApp().getQuitTimer().reset();
|
||||||
if (mTimer != null) {
|
if (mTimer != null) {
|
||||||
@ -142,12 +142,10 @@ class HomeAssistantPinConfirmationDelegate extends WatchUi.BehaviorDelegate {
|
|||||||
mConfirmMethod.invoke(mState);
|
mConfirmMethod.invoke(mState);
|
||||||
WatchUi.popView(WatchUi.SLIDE_RIGHT);
|
WatchUi.popView(WatchUi.SLIDE_RIGHT);
|
||||||
} else {
|
} else {
|
||||||
mCurrentIndex++;
|
error();
|
||||||
resetTimer();
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// System.println("Pin digit " + (mCurrentIndex+1) + " doesn't match");
|
resetTimer();
|
||||||
error();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -173,6 +171,7 @@ class HomeAssistantPinConfirmationDelegate extends WatchUi.BehaviorDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function error() as Void {
|
function error() as Void {
|
||||||
|
// System.println("HomeAssistantPinConfirmationDelegate error()");
|
||||||
mFailures.addFailure();
|
mFailures.addFailure();
|
||||||
if (Attention has :vibrate && Settings.getVibrate()) {
|
if (Attention has :vibrate && Settings.getVibrate()) {
|
||||||
Attention.vibrate([
|
Attention.vibrate([
|
||||||
|
@ -87,7 +87,6 @@ class HomeAssistantTapMenuItem extends WatchUi.IconMenuItem {
|
|||||||
if (mConfirm) {
|
if (mConfirm) {
|
||||||
var hasTouchScreen = System.getDeviceSettings().isTouchScreen;
|
var hasTouchScreen = System.getDeviceSettings().isTouchScreen;
|
||||||
var pin = Settings.getPin();
|
var pin = Settings.getPin();
|
||||||
System.println("HomeAsistantTemplateMenuItem callService() pin = '" + pin + "'");
|
|
||||||
if (!hasTouchScreen || "".equals(pin)) {
|
if (!hasTouchScreen || "".equals(pin)) {
|
||||||
WatchUi.pushView(
|
WatchUi.pushView(
|
||||||
new HomeAssistantConfirmation(),
|
new HomeAssistantConfirmation(),
|
||||||
|
Reference in New Issue
Block a user