Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
mueller-ma committed Mar 12, 2024
1 parent bf596dd commit f9c85be
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,21 @@

package org.openhab.habdroid.core

import android.content.Intent
import android.util.Log
import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage
import kotlinx.coroutines.runBlocking
import org.openhab.habdroid.model.CloudNotification
import org.openhab.habdroid.model.toOH2IconResource

class FcmMessageListenerService : FirebaseMessagingService() {
class FcmMessageListenerService : FirebaseMessagingService(), NotificationHelper.NotificationDeletedCallback {
private lateinit var notifHelper: NotificationHelper

override fun onCreate() {
Log.d(TAG, "onCreate()")
super.onCreate()
notifHelper = NotificationHelper(this)
notifHelper = NotificationHelper(this, this)
}

override fun onNewToken(token: String) {
Expand Down Expand Up @@ -73,6 +74,14 @@ class FcmMessageListenerService : FirebaseMessagingService() {
}
}

override fun onNotificationDeleted(notificationId: Int) {
val intent = Intent(this, FcmRegistrationWorker::class.java)
.setAction(FcmRegistrationWorker.ACTION_HIDE_NOTIFICATION)
.putExtra(FcmRegistrationWorker.KEY_NOTIFICATION_ID, notificationId)

return FcmRegistrationWorker.ProxyReceiver.wrap(this, intent, notificationId)
}

companion object {
private val TAG = FcmMessageListenerService::class.java.simpleName
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,12 @@ import org.openhab.habdroid.util.getNotificationTone
import org.openhab.habdroid.util.getNotificationVibrationPattern
import org.openhab.habdroid.util.getPrefs

class NotificationHelper(private val context: Context) {
class NotificationHelper(private val context: Context, private val callback: NotificationDeletedCallback) {
private val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager

suspend fun showNotification(
notificationId: Int,
message: CloudNotification,
deleteIntent: PendingIntent?,
summaryDeleteIntent: PendingIntent?
message: CloudNotification
) {
createChannelForSeverity(message.severity)

Expand Down Expand Up @@ -263,4 +261,8 @@ class NotificationHelper(private val context: Context) {
// https://developer.android.com/guide/topics/ui/notifiers/notifications#bundle
private val HAS_GROUPING_SUPPORT = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
}

interface NotificationDeletedCallback {
fun onNotificationDeleted(notificationId: Int)
}
}

0 comments on commit f9c85be

Please sign in to comment.