From 8902f435a8af6f12abb4beb628f6e1eccfe01ae9 Mon Sep 17 00:00:00 2001 From: mueller-ma Date: Sun, 31 Mar 2024 17:29:42 +0200 Subject: [PATCH] Show charts for all Sitemap widgets Add an entry to the context menu that allows showing a chart on a new screen. It's possible to display charts for all Items in Main UI settings and this is quite useful. The word 'Analyze' is also taken from Main UI. Signed-off-by: mueller-ma --- .../openhab/habdroid/ui/WidgetListFragment.kt | 19 ++++++++++++++++++- mobile/src/main/res/values/strings.xml | 1 + 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/mobile/src/main/java/org/openhab/habdroid/ui/WidgetListFragment.kt b/mobile/src/main/java/org/openhab/habdroid/ui/WidgetListFragment.kt index 626ed597f3..dddb8d8066 100644 --- a/mobile/src/main/java/org/openhab/habdroid/ui/WidgetListFragment.kt +++ b/mobile/src/main/java/org/openhab/habdroid/ui/WidgetListFragment.kt @@ -277,8 +277,24 @@ class WidgetListFragment : // Offer widget for all Items. For read-only Items the "Show state" widget is useful. if (widget.item != null) { + menu.add( + Menu.NONE, + CONTEXT_MENU_ID_SHOW_CHART, + Menu.NONE, + R.string.analyse + ).setOnMenuItemClickListener { + val mainActivity = activity as MainActivity + val intent = Intent(mainActivity, ChartWidgetActivity::class.java) + intent.putExtra(ChartWidgetActivity.EXTRA_WIDGET, widget) + intent.putExtra(ChartWidgetActivity.EXTRA_SERVER_FLAGS, mainActivity.serverProperties?.flags) + mainActivity.startActivity(intent) + return@setOnMenuItemClickListener true + } + + val widgetMenu = menu.addSubMenu( - Menu.NONE, CONTEXT_MENU_ID_CREATE_HOME_SCREEN_WIDGET, + Menu.NONE, + CONTEXT_MENU_ID_CREATE_HOME_SCREEN_WIDGET, Menu.NONE, R.string.create_home_screen_widget_title ) @@ -648,6 +664,7 @@ class WidgetListFragment : private const val CONTEXT_MENU_ID_PIN_HOME_BLACK = 1005 private const val CONTEXT_MENU_ID_OPEN_IN_MAPS = 1006 private const val CONTEXT_MENU_ID_COPY_ITEM_NAME = 1007 + private const val CONTEXT_MENU_ID_SHOW_CHART = 1008 private const val CONTEXT_MENU_ID_WRITE_CUSTOM_TAG = 10000 private const val CONTEXT_MENU_ID_WRITE_DEVICE_ID = 10001 diff --git a/mobile/src/main/res/values/strings.xml b/mobile/src/main/res/values/strings.xml index 47de27e016..4ca9b7b4bb 100644 --- a/mobile/src/main/res/values/strings.xml +++ b/mobile/src/main/res/values/strings.xml @@ -633,6 +633,7 @@ Create widget Show current state Please go to the widget menu on your home screen and create a widget from there + Analyze Data saver