Remove text versions of menu items

This commit is contained in:
Joseph Abbey
2024-01-14 13:29:33 +00:00
parent cf2237958d
commit 1f075a8c0f
11 changed files with 84 additions and 271 deletions

View File

@ -1,72 +0,0 @@
//-----------------------------------------------------------------------------------
//
// 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 & Someone0nEarth, 31 October 2023
//
//
// Description:
//
// Menu button that triggers a service.
//
//-----------------------------------------------------------------------------------
using Toybox.Lang;
using Toybox.WatchUi;
using Toybox.Graphics;
class HomeAssistantIconMenuItem extends WatchUi.IconMenuItem {
private var mHomeAssistantService as HomeAssistantService;
private var mService as Lang.String;
private var mConfirm as Lang.Boolean;
function initialize(
label as Lang.String or Lang.Symbol,
subLabel as Lang.String or Lang.Symbol or Null,
identifier as Lang.Object or Null,
service as Lang.String or Null,
confirm as Lang.Boolean,
icon as Graphics.BitmapType or WatchUi.Drawable,
options as {
:alignment as WatchUi.MenuItem.Alignment
} or Null,
haService as HomeAssistantService
) {
WatchUi.IconMenuItem.initialize(
label,
subLabel,
identifier,
icon,
options
);
mHomeAssistantService = haService;
mIdentifier = identifier;
mService = service;
mConfirm = confirm;
}
function callService() as Void {
if (mConfirm) {
WatchUi.pushView(
new HomeAssistantConfirmation(),
new HomeAssistantConfirmationDelegate(method(:onConfirm)),
WatchUi.SLIDE_IMMEDIATE
);
} else {
onConfirm();
}
}
function onConfirm() as Void {
mHomeAssistantService.call(mIdentifier as Lang.String, mService);
}
}

View File

@ -22,7 +22,7 @@ using Toybox.Lang;
using Toybox.WatchUi;
using Toybox.Graphics;
class HomeAssistantMenuItem extends WatchUi.MenuItem {
class HomeAssistantMenuItem extends WatchUi.IconMenuItem {
private var mHomeAssistantService as HomeAssistantService;
private var mService as Lang.String;
private var mConfirm as Lang.Boolean;
@ -33,20 +33,22 @@ class HomeAssistantMenuItem extends WatchUi.MenuItem {
identifier as Lang.Object or Null,
service as Lang.String or Null,
confirm as Lang.Boolean,
icon as Graphics.BitmapType or WatchUi.Drawable,
options as {
:alignment as WatchUi.MenuItem.Alignment,
:icon as Graphics.BitmapType or WatchUi.Drawable or Lang.Symbol
:alignment as WatchUi.MenuItem.Alignment
} or Null,
haService as HomeAssistantService
) {
WatchUi.MenuItem.initialize(
WatchUi.IconMenuItem.initialize(
label,
subLabel,
identifier,
icon,
options
);
mHomeAssistantService = haService;
mIdentifier = identifier;
mService = service;
mConfirm = confirm;
}

View File

@ -60,7 +60,7 @@ class HomeAssistantMenuItemFactory {
function toggle(label as Lang.String or Lang.Symbol, identifier as Lang.Object or Null) as WatchUi.MenuItem {
return new HomeAssistantToggleMenuItem(
label,
Settings.getMenuStyle() == Settings.MENU_STYLE_TEXT ? RezStrings.getLabelToggle() : null,
null,
identifier,
false,
mMenuItemOptions
@ -91,35 +91,19 @@ class HomeAssistantMenuItemFactory {
service as Lang.String or Null,
confirm as Lang.Boolean
) as WatchUi.MenuItem {
if (Settings.getMenuStyle() == Settings.MENU_STYLE_TEXT) {
return new HomeAssistantMenuItem(
label,
RezStrings.getMenuItemTap(),
identifier,
service,
confirm,
mMenuItemOptions,
mHomeAssistantService
);
} else {
return new HomeAssistantIconMenuItem(
label,
null,
identifier,
service,
confirm,
mTapTypeIcon,
mMenuItemOptions,
mHomeAssistantService
);
}
return new HomeAssistantMenuItem(
label,
null,
identifier,
service,
confirm,
mTapTypeIcon,
mMenuItemOptions,
mHomeAssistantService
);
}
function group(definition as Lang.Dictionary) as WatchUi.MenuItem {
if (Settings.getMenuStyle() == Settings.MENU_STYLE_TEXT) {
return new HomeAssistantViewMenuItem(definition);
} else {
return new HomeAssistantViewIconMenuItem(definition, mGroupTypeIcon, mMenuItemOptions);
}
return new HomeAssistantViewMenuItem(definition, mGroupTypeIcon, mMenuItemOptions);
}
}

View File

@ -89,7 +89,7 @@ class HomeAssistantView extends WatchUi.Menu2 {
var lmi = mListMenuItems as Lang.Array<WatchUi.MenuItem>;
for(var i = 0; i < mListMenuItems.size(); i++) {
var item = lmi[i];
if (item instanceof HomeAssistantViewMenuItem || item instanceof HomeAssistantViewIconMenuItem) {
if (item instanceof HomeAssistantViewMenuItem) {
fullList.addAll(item.getMenuView().getItemsToUpdate());
}
}
@ -154,12 +154,6 @@ class HomeAssistantViewDelegate extends WatchUi.Menu2InputDelegate {
System.println(haItem.getLabel() + " " + haItem.getId());
}
haItem.callService();
} else if (item instanceof HomeAssistantIconMenuItem) {
var haItem = item as HomeAssistantIconMenuItem;
if (Globals.scDebug) {
System.println(haItem.getLabel() + " " + haItem.getId());
}
haItem.callService();
} else if (item instanceof HomeAssistantTemplateMenuItem) {
var haItem = item as HomeAssistantTemplateMenuItem;
if (Globals.scDebug) {
@ -168,12 +162,6 @@ class HomeAssistantViewDelegate extends WatchUi.Menu2InputDelegate {
haItem.callService();
} else if (item instanceof HomeAssistantViewMenuItem) {
var haMenuItem = item as HomeAssistantViewMenuItem;
if (Globals.scDebug) {
System.println("Menu: " + haMenuItem.getLabel() + " " + haMenuItem.getId());
}
WatchUi.pushView(haMenuItem.getMenuView(), new HomeAssistantViewDelegate(false), WatchUi.SLIDE_LEFT);
} else if (item instanceof HomeAssistantViewIconMenuItem) {
var haMenuItem = item as HomeAssistantViewIconMenuItem;
if (Globals.scDebug) {
System.println("IconMenu: " + haMenuItem.getLabel() + " " + haMenuItem.getId());
}

View File

@ -1,48 +0,0 @@
//-----------------------------------------------------------------------------------
//
// 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 & Someone0nEarth, 16 November 2023
//
//
// Description:
//
// Menu button with an icon that opens a sub-menu.
//
//-----------------------------------------------------------------------------------
using Toybox.Lang;
using Toybox.WatchUi;
class HomeAssistantViewIconMenuItem extends WatchUi.IconMenuItem {
private var mMenu as HomeAssistantView;
function initialize(definition as Lang.Dictionary, icon as WatchUi.Drawable, options as {
:alignment as WatchUi.MenuItem.Alignment
} or Null) {
var label = definition.get("name") as Lang.String;
var identifier = definition.get("entity") as Lang.String;
WatchUi.IconMenuItem.initialize(
label,
null,
identifier,
icon,
options
);
mMenu = new HomeAssistantView(definition, null);
}
function getMenuView() as HomeAssistantView {
return mMenu;
}
}

View File

@ -9,28 +9,33 @@
// 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 & Someone0nEarth, 31 October 2023
// P A Abbey & J D Abbey & Someone0nEarth, 16 November 2023
//
//
// Description:
//
// Menu button that opens a sub-menu.
// Menu button with an icon that opens a sub-menu.
//
//-----------------------------------------------------------------------------------
using Toybox.Lang;
using Toybox.WatchUi;
class HomeAssistantViewMenuItem extends WatchUi.MenuItem {
class HomeAssistantViewMenuItem extends WatchUi.IconMenuItem {
private var mMenu as HomeAssistantView;
function initialize(definition as Lang.Dictionary) {
// definitions.get(...) are Strings here as they have been checked by HomeAssistantView first
WatchUi.MenuItem.initialize(
definition.get("name") as Lang.String,
RezStrings.getMenuItemMenu(),
definition.get("entity") as Lang.String,
null
function initialize(definition as Lang.Dictionary, icon as WatchUi.Drawable, options as {
:alignment as WatchUi.MenuItem.Alignment
} or Null) {
var label = definition.get("name") as Lang.String;
var identifier = definition.get("entity") as Lang.String;
WatchUi.IconMenuItem.initialize(
label,
null,
identifier,
icon,
options
);
mMenu = new HomeAssistantView(definition, null);

View File

@ -27,8 +27,6 @@ class RezStrings {
(:glance)
private static var strAppName as Lang.String or Null;
private static var strMenuItemTap as Lang.String or Null;
private static var strMenuItemMenu as Lang.String or Null;
private static var strConfirm as Lang.String or Null;
private static var strExecuted as Lang.String or Null;
(:glance)
@ -61,7 +59,6 @@ class RezStrings {
private static var strCached as Lang.String or Null;
(:glance)
private static var strGlanceMenu as Lang.String or Null;
private static var strLabelToggle as Lang.Dictionary or Null;
// Can't initialise a constant directly, have to be initialised via a function
// for 'WatchUi.loadResource' to be available.
@ -84,8 +81,6 @@ class RezStrings {
// for 'WatchUi.loadResource' to be available.
static function update() {
strAppName = WatchUi.loadResource($.Rez.Strings.AppName);
strMenuItemTap = WatchUi.loadResource($.Rez.Strings.MenuItemTap);
strMenuItemMenu = WatchUi.loadResource($.Rez.Strings.MenuItemMenu);
strConfirm = WatchUi.loadResource($.Rez.Strings.Confirm);
strExecuted = WatchUi.loadResource($.Rez.Strings.Executed);
strNoPhone = WatchUi.loadResource($.Rez.Strings.NoPhone);
@ -108,24 +103,12 @@ class RezStrings {
strUnconfigured = WatchUi.loadResource($.Rez.Strings.Unconfigured);
strCached = WatchUi.loadResource($.Rez.Strings.Cached);
strGlanceMenu = WatchUi.loadResource($.Rez.Strings.GlanceMenu);
strLabelToggle = {
:enabled => WatchUi.loadResource($.Rez.Strings.MenuItemOn) as Lang.String,
:disabled => WatchUi.loadResource($.Rez.Strings.MenuItemOff) as Lang.String
};
}
static function getAppName() as Lang.String {
return strAppName;
}
static function getMenuItemTap() as Lang.String {
return strMenuItemTap;
}
static function getMenuItemMenu() as Lang.String {
return strMenuItemMenu;
}
static function getConfirm() as Lang.String {
return strConfirm;
}
@ -214,8 +197,4 @@ class RezStrings {
return strGlanceMenu;
}
static function getLabelToggle() as Lang.Dictionary {
return strLabelToggle;
}
}

View File

@ -28,9 +28,6 @@ using Toybox.Time;
(:glance, :background)
class Settings {
public static const MENU_STYLE_ICONS = 0;
public static const MENU_STYLE_TEXT = 1;
private static var mApiKey as Lang.String = "";
private static var mWebhookId as Lang.String = "";
private static var mApiUrl as Lang.String = "";
@ -39,7 +36,6 @@ class Settings {
private static var mClearCache as Lang.Boolean = false;
private static var mAppTimeout as Lang.Number = 0; // seconds
private static var mConfirmTimeout as Lang.Number = 3; // seconds
private static var mMenuStyle as Lang.Number = MENU_STYLE_ICONS;
private static var mMenuAlignment as Lang.Number = WatchUi.MenuItem.MENU_ITEM_LABEL_ALIGN_LEFT;
private static var mIsWidgetStartNoTap as Lang.Boolean = false;
private static var mIsBatteryLevelEnabled as Lang.Boolean = false;
@ -60,7 +56,6 @@ class Settings {
mClearCache = Properties.getValue("clear_cache");
mAppTimeout = Properties.getValue("app_timeout");
mConfirmTimeout = Properties.getValue("confirm_timeout");
mMenuStyle = Properties.getValue("menu_theme");
mMenuAlignment = Properties.getValue("menu_alignment");
mIsWidgetStartNoTap = Properties.getValue("widget_start_no_tap");
mIsBatteryLevelEnabled = Properties.getValue("enable_battery_level");
@ -143,10 +138,6 @@ class Settings {
return mConfirmTimeout * 1000; // Convert to milliseconds
}
static function getMenuStyle() as Lang.Number {
return mMenuStyle; // Either MENU_STYLE_ICONS or MENU_STYLE_TEXT
}
static function getMenuAlignment() as Lang.Number {
return mMenuAlignment; // Either WatchUi.MenuItem.MENU_ITEM_LABEL_ALIGN_RIGHT or WatchUi.MenuItem.MENU_ITEM_LABEL_ALIGN_LEFT
}