mirror of
				https://github.com/house-of-abbey/GarminHomeAssistant.git
				synced 2025-11-04 00:48:14 +00:00 
			
		
		
		
	move pin validation to settings
This commit is contained in:
		@@ -90,16 +90,14 @@ class HomeAssistantTapMenuItem extends WatchUi.IconMenuItem {
 | 
			
		||||
        var hasTouchScreen = System.getDeviceSettings().isTouchScreen;
 | 
			
		||||
        if (mPin && hasTouchScreen) {
 | 
			
		||||
            var pin = Settings.getPin();
 | 
			
		||||
            if (pin.toNumber() == null || pin.length() != 4) {
 | 
			
		||||
                ErrorView.show(WatchUi.loadResource($.Rez.Strings.SettingsPinError) as Lang.String);
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
            if (pin != null) {
 | 
			
		||||
                var pinConfirmationView = new HomeAssistantPinConfirmationView();
 | 
			
		||||
                WatchUi.pushView(
 | 
			
		||||
                    pinConfirmationView,
 | 
			
		||||
                    new HomeAssistantPinConfirmationDelegate(method(:onConfirm), false, pin, pinConfirmationView),
 | 
			
		||||
                    WatchUi.SLIDE_IMMEDIATE
 | 
			
		||||
                );
 | 
			
		||||
            }
 | 
			
		||||
        } else if (mConfirm) {
 | 
			
		||||
            WatchUi.pushView(
 | 
			
		||||
                new HomeAssistantConfirmation(),
 | 
			
		||||
 
 | 
			
		||||
@@ -219,16 +219,14 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
 | 
			
		||||
        var hasTouchScreen = System.getDeviceSettings().isTouchScreen;
 | 
			
		||||
        if (mPin && hasTouchScreen) {
 | 
			
		||||
            var pin = Settings.getPin();
 | 
			
		||||
            if (pin.toNumber() == null || pin.length() != 4) {
 | 
			
		||||
                ErrorView.show(WatchUi.loadResource($.Rez.Strings.SettingsPinError) as Lang.String);
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
            if (pin != null) {
 | 
			
		||||
                var pinConfirmationView = new HomeAssistantPinConfirmationView();
 | 
			
		||||
                WatchUi.pushView(
 | 
			
		||||
                    pinConfirmationView,
 | 
			
		||||
                    new HomeAssistantPinConfirmationDelegate(method(:onConfirm), b, pin, pinConfirmationView),
 | 
			
		||||
                    WatchUi.SLIDE_IMMEDIATE
 | 
			
		||||
                );
 | 
			
		||||
            }
 | 
			
		||||
        } else if (mConfirm) {
 | 
			
		||||
            WatchUi.pushView(
 | 
			
		||||
                new HomeAssistantConfirmation(),
 | 
			
		||||
 
 | 
			
		||||
@@ -38,7 +38,7 @@ class Settings {
 | 
			
		||||
    private static var mAppTimeout            as Lang.Number  = 0;  // seconds
 | 
			
		||||
    private static var mPollDelay             as Lang.Number  = 0;  // seconds
 | 
			
		||||
    private static var mConfirmTimeout        as Lang.Number  = 3;  // seconds
 | 
			
		||||
    private static var mPin                   as Lang.String  = "0000";
 | 
			
		||||
    private static var mPin                   as Lang.String  or Null = "0000";
 | 
			
		||||
    private static var mMenuAlignment         as Lang.Number  = WatchUi.MenuItem.MENU_ITEM_LABEL_ALIGN_LEFT;
 | 
			
		||||
    private static var mIsSensorsLevelEnabled as Lang.Boolean = false;
 | 
			
		||||
    private static var mBatteryRefreshRate    as Lang.Number  = 15; // minutes
 | 
			
		||||
@@ -60,7 +60,7 @@ class Settings {
 | 
			
		||||
        mAppTimeout            = Properties.getValue("app_timeout");
 | 
			
		||||
        mPollDelay             = Properties.getValue("poll_delay_combined");
 | 
			
		||||
        mConfirmTimeout        = Properties.getValue("confirm_timeout");
 | 
			
		||||
        mPin                   = Properties.getValue("pin");
 | 
			
		||||
        mPin                   = validatePin();
 | 
			
		||||
        mMenuAlignment         = Properties.getValue("menu_alignment");
 | 
			
		||||
        mIsSensorsLevelEnabled = Properties.getValue("enable_battery_level");
 | 
			
		||||
        mBatteryRefreshRate    = Properties.getValue("battery_level_refresh_rate");
 | 
			
		||||
@@ -166,10 +166,21 @@ class Settings {
 | 
			
		||||
        return mConfirmTimeout * 1000; // Convert to milliseconds
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    static function getPin() as Lang.String {
 | 
			
		||||
    static function getPin() as Lang.String or Null {
 | 
			
		||||
        if (mPin == null) {
 | 
			
		||||
            ErrorView.show(WatchUi.loadResource($.Rez.Strings.SettingsPinError) as Lang.String);
 | 
			
		||||
        }
 | 
			
		||||
        return mPin;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static function validatePin() as Lang.String or Null {
 | 
			
		||||
        var pin = Properties.getValue("pin");
 | 
			
		||||
        if (pin.toNumber() == null || pin.length() != 4) {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
        return pin;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    static function getMenuAlignment() as Lang.Number {
 | 
			
		||||
        return mMenuAlignment; // Either WatchUi.MenuItem.MENU_ITEM_LABEL_ALIGN_RIGHT or WatchUi.MenuItem.MENU_ITEM_LABEL_ALIGN_LEFT
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user