From 3cc2d45d7fcb5cf20ebbb569402b618e4ba30f2b Mon Sep 17 00:00:00 2001 From: mueller-ma Date: Tue, 9 Jul 2024 17:15:29 +0200 Subject: [PATCH] Fix notification trampoline --- .../core/NotificationHandlingReceiver.kt | 26 ++++++++++--------- .../org/openhab/habdroid/ui/MainActivity.kt | 5 ++-- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/mobile/src/main/java/org/openhab/habdroid/core/NotificationHandlingReceiver.kt b/mobile/src/main/java/org/openhab/habdroid/core/NotificationHandlingReceiver.kt index 4a1455a971f..e04aa65de71 100644 --- a/mobile/src/main/java/org/openhab/habdroid/core/NotificationHandlingReceiver.kt +++ b/mobile/src/main/java/org/openhab/habdroid/core/NotificationHandlingReceiver.kt @@ -47,14 +47,6 @@ class NotificationHandlingReceiver : BroadcastReceiver() { BackgroundTasksManager.enqueueNotificationAction(context, action) is CloudNotificationAction.Action.UrlAction -> action.url.toUri().openInBrowser(context) - is CloudNotificationAction.Action.UiCommandAction -> { - val commandIntent = Intent(context, MainActivity::class.java).apply { - flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP or - Intent.FLAG_ACTIVITY_NEW_TASK - putExtra(MainActivity.EXTRA_UI_COMMAND, action.command) - } - context.startActivity(commandIntent) - } else -> { // TODO Log.e(TAG, "Not yet implemented") @@ -81,10 +73,20 @@ class NotificationHandlingReceiver : BroadcastReceiver() { } fun createActionIntent(context: Context, notificationId: Int, cna: CloudNotificationAction): Intent { - return Intent(context, NotificationHandlingReceiver::class.java).apply { - action = ACTION_NOTIF_ACTION - putExtra(EXTRA_NOTIFICATION_ID, notificationId) - putExtra(EXTRA_NOTIFICATION_ACTION, cna) + val cnaAction = cna.action + return if (cnaAction is CloudNotificationAction.Action.UiCommandAction) { + Intent(context, MainActivity::class.java).apply { + action = Intent.ACTION_VIEW + flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP or + Intent.FLAG_ACTIVITY_NEW_TASK + putExtra(MainActivity.EXTRA_UI_COMMAND, cnaAction.command) + } + } else { + Intent(context, NotificationHandlingReceiver::class.java).apply { + action = ACTION_NOTIF_ACTION + putExtra(EXTRA_NOTIFICATION_ID, notificationId) + putExtra(EXTRA_NOTIFICATION_ACTION, cna) + } } } } diff --git a/mobile/src/main/java/org/openhab/habdroid/ui/MainActivity.kt b/mobile/src/main/java/org/openhab/habdroid/ui/MainActivity.kt index 622e9aa426e..a493c544558 100644 --- a/mobile/src/main/java/org/openhab/habdroid/ui/MainActivity.kt +++ b/mobile/src/main/java/org/openhab/habdroid/ui/MainActivity.kt @@ -140,6 +140,7 @@ import org.openhab.habdroid.util.isDebugModeEnabled import org.openhab.habdroid.util.isEventListenerEnabled import org.openhab.habdroid.util.isScreenTimerDisabled import org.openhab.habdroid.util.openInAppStore +import org.openhab.habdroid.util.orDefaultIfEmpty import org.openhab.habdroid.util.parcelable import org.openhab.habdroid.util.putActiveServerId import org.openhab.habdroid.util.resolveThemedColor @@ -827,8 +828,8 @@ class MainActivity : AbstractBaseActivity(), ConnectionFactory.UpdateListener { // Add a host here to be able to parse as HttpUrl val httpLink = "https://openhab.org$link".toHttpUrlOrNull() ?: return val sitemap = httpLink.queryParameter("sitemap") - ?: prefs.getDefaultSitemap(connection, serverId)?.name - val subpage = httpLink.queryParameter("w") + ?: prefs.getDefaultSitemap(connection, serverId)?.name ?: return + val subpage = httpLink.queryParameter("w").orDefaultIfEmpty(sitemap) executeOrStoreAction(PendingAction.OpenSitemapUrl("/$sitemap/$subpage", serverId)) } else { executeOrStoreAction(PendingAction.OpenWebViewUi(WebViewUi.MAIN_UI, serverId, link))