-
-
Notifications
You must be signed in to change notification settings - Fork 313
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: mueller-ma <[email protected]>
- Loading branch information
1 parent
f81eff0
commit 325dac6
Showing
9 changed files
with
298 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
mobile/src/main/java/org/openhab/habdroid/core/NotificationActionReceiver.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright (c) 2010-2024 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
|
||
package org.openhab.habdroid.core | ||
|
||
import android.content.BroadcastReceiver | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.util.Log | ||
import androidx.core.net.toUri | ||
import org.openhab.habdroid.background.BackgroundTasksManager | ||
import org.openhab.habdroid.core.NotificationHelper.Companion.NOTIFICATION_ACTION_ACTION | ||
import org.openhab.habdroid.core.NotificationHelper.Companion.NOTIFICATION_ACTION_LABEL | ||
import org.openhab.habdroid.core.NotificationHelper.Companion.NOTIFICATION_ID_EXTRA | ||
import org.openhab.habdroid.model.CloudNotificationAction | ||
import org.openhab.habdroid.util.openInBrowser | ||
|
||
class NotificationActionReceiver : BroadcastReceiver() { | ||
override fun onReceive(context: Context, intent: Intent) { | ||
Log.d(TAG, "onReceive(): $intent") | ||
val notificationId = intent.getIntExtra(NOTIFICATION_ID_EXTRA, 0) | ||
if (notificationId == 0) { | ||
return | ||
} | ||
val rawAction = intent.getStringExtra(NOTIFICATION_ACTION_ACTION) ?: return | ||
val label = intent.getStringExtra(NOTIFICATION_ACTION_LABEL) ?: return | ||
val action = CloudNotificationAction(label, rawAction) | ||
Log.d(TAG, "Received action from $notificationId: $action") | ||
executeAction(context, action) | ||
} | ||
|
||
companion object { | ||
private val TAG = NotificationActionReceiver::class.java.simpleName | ||
|
||
fun executeAction(context: Context, action: CloudNotificationAction) { | ||
when { | ||
action.action.startsWith("command:") -> { | ||
BackgroundTasksManager.enqueueNotificationAction(context, action) | ||
} | ||
action.action.startsWith("http://") || action.action.startsWith("https://") -> { | ||
action.action.toUri().openInBrowser(context) | ||
} else -> { | ||
// TODO | ||
Log.e(TAG, "Not yet implemented") | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.