diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 4c19a371057..932c48cbe17 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -195,6 +195,9 @@ dependencies { implementation("androidx.activity:activity-compose:1.3.1") implementation("com.google.android.material:compose-theme-adapter:1.0.4") implementation("com.google.accompanist:accompanist-appcompat-theme:0.20.0") + + implementation("com.mikepenz:iconics-core:5.3.2") + implementation("com.mikepenz:community-material-typeface:5.8.55.0-kotlin@aar") } // Disable to fix memory leak and be compatible with the configuration cache. diff --git a/app/src/full/java/io/homeassistant/companion/android/notifications/MessagingService.kt b/app/src/full/java/io/homeassistant/companion/android/notifications/MessagingService.kt index a7ebefd1cb8..d888b58f83b 100644 --- a/app/src/full/java/io/homeassistant/companion/android/notifications/MessagingService.kt +++ b/app/src/full/java/io/homeassistant/companion/android/notifications/MessagingService.kt @@ -38,6 +38,8 @@ import androidx.core.text.HtmlCompat import androidx.core.text.isDigitsOnly import com.google.firebase.messaging.FirebaseMessagingService import com.google.firebase.messaging.RemoteMessage +import com.mikepenz.iconics.IconicsDrawable +import com.mikepenz.iconics.utils.toAndroidIconCompat import com.vdurmont.emoji.EmojiParser import io.homeassistant.companion.android.R import io.homeassistant.companion.android.common.dagger.GraphComponentAccessor @@ -85,6 +87,7 @@ class MessagingService : FirebaseMessagingService() { const val KEY_TEXT_REPLY = "key_text_reply" const val ALERT_ONCE = "alert_once" const val INTENT_CLASS_NAME = "intent_class_name" + const val NOTIFICATION_ICON = "notification_icon" // special action constants const val REQUEST_LOCATION_UPDATE = "request_location_update" @@ -617,7 +620,8 @@ class MessagingService : FirebaseMessagingService() { val channelId = handleChannel(notificationManagerCompat, data) val notificationBuilder = NotificationCompat.Builder(this, channelId) - .setSmallIcon(R.drawable.ic_stat_ic_notification) + + handleSmallIcon(notificationBuilder, data) handleSound(notificationBuilder, data) @@ -691,6 +695,18 @@ class MessagingService : FirebaseMessagingService() { } } + private fun handleSmallIcon( + builder: NotificationCompat.Builder, + data: Map + ) { + if (data[NOTIFICATION_ICON]?.startsWith("mdi") == true && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + val iconName = data[NOTIFICATION_ICON]!!.split(":")[1] + val iconDrawable = IconicsDrawable(applicationContext, "cmd-$iconName").toAndroidIconCompat() + builder.setSmallIcon(iconDrawable) + } else + builder.setSmallIcon(R.drawable.ic_stat_ic_notification) + } + private fun handleContentIntent( builder: NotificationCompat.Builder, messageId: Int, @@ -756,7 +772,6 @@ class MessagingService : FirebaseMessagingService() { ): NotificationCompat.Builder { val groupNotificationBuilder = NotificationCompat.Builder(this, channelId) - .setSmallIcon(R.drawable.ic_stat_ic_notification) .setStyle( NotificationCompat.BigTextStyle() .setSummaryText( @@ -769,6 +784,7 @@ class MessagingService : FirebaseMessagingService() { if (data[ALERT_ONCE].toBoolean()) groupNotificationBuilder.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_CHILDREN) handleColor(groupNotificationBuilder, data) + handleSmallIcon(groupNotificationBuilder, data) return groupNotificationBuilder }