Skip to content

Commit

Permalink
Fix notification trampoline
Browse files Browse the repository at this point in the history
  • Loading branch information
mueller-ma committed Jul 9, 2024
1 parent 8180992 commit 3cc2d45
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
}
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions mobile/src/main/java/org/openhab/habdroid/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 3cc2d45

Please sign in to comment.