From e8c2902aa0a09c59354e7be50dc98d1b297de746 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 19 Jun 2024 16:40:33 +0200 Subject: [PATCH] Move `notification_accent_color` from resource file to `NotificationConfig` --- appconfig/build.gradle.kts | 1 + .../android/appconfig/NotificationConfig.kt | 6 ++++++ .../channels/NotificationChannels.kt | 4 ++-- .../factories/NotificationCreator.kt | 10 +++------ .../push/impl/src/main/res/values/colors.xml | 21 ------------------- 5 files changed, 12 insertions(+), 30 deletions(-) delete mode 100644 libraries/push/impl/src/main/res/values/colors.xml diff --git a/appconfig/build.gradle.kts b/appconfig/build.gradle.kts index e59799d685..17a78cdd3b 100644 --- a/appconfig/build.gradle.kts +++ b/appconfig/build.gradle.kts @@ -28,6 +28,7 @@ anvil { } dependencies { + implementation(libs.androidx.annotationjvm) implementation(libs.dagger) implementation(projects.libraries.di) implementation(projects.libraries.matrix.api) diff --git a/appconfig/src/main/kotlin/io/element/android/appconfig/NotificationConfig.kt b/appconfig/src/main/kotlin/io/element/android/appconfig/NotificationConfig.kt index 9ca4f73314..fa7e57ec8c 100644 --- a/appconfig/src/main/kotlin/io/element/android/appconfig/NotificationConfig.kt +++ b/appconfig/src/main/kotlin/io/element/android/appconfig/NotificationConfig.kt @@ -16,6 +16,9 @@ package io.element.android.appconfig +import android.graphics.Color +import androidx.annotation.ColorInt + object NotificationConfig { // TODO EAx Implement and set to true at some point const val SUPPORT_MARK_AS_READ_ACTION = false @@ -25,4 +28,7 @@ object NotificationConfig { // TODO EAx Implement and set to true at some point const val SUPPORT_QUICK_REPLY_ACTION = false + + @ColorInt + val NOTIFICATION_ACCENT_COLOR: Int = Color.parseColor("#FF368BD6") } diff --git a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/channels/NotificationChannels.kt b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/channels/NotificationChannels.kt index 6cfff8b9e3..080bacc453 100644 --- a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/channels/NotificationChannels.kt +++ b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/channels/NotificationChannels.kt @@ -24,8 +24,8 @@ import android.os.Build import androidx.annotation.ChecksSdkIntAtLeast import androidx.core.app.NotificationChannelCompat import androidx.core.app.NotificationManagerCompat -import androidx.core.content.ContextCompat import com.squareup.anvil.annotations.ContributesBinding +import io.element.android.appconfig.NotificationConfig import io.element.android.libraries.di.AppScope import io.element.android.libraries.di.ApplicationContext import io.element.android.libraries.di.SingleIn @@ -89,7 +89,7 @@ class DefaultNotificationChannels @Inject constructor( return } - val accentColor = ContextCompat.getColor(context, R.color.notification_accent_color) + val accentColor = NotificationConfig.NOTIFICATION_ACCENT_COLOR // Migration - the noisy channel was deleted and recreated when sound preference was changed (id was DEFAULT_NOISY_NOTIFICATION_CHANNEL_ID_BASE // + currentTimeMillis). diff --git a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/factories/NotificationCreator.kt b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/factories/NotificationCreator.kt index 5c8dd1dc77..67dbda63a4 100755 --- a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/factories/NotificationCreator.kt +++ b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/factories/NotificationCreator.kt @@ -24,7 +24,6 @@ import androidx.annotation.DrawableRes import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat.MessagingStyle import androidx.core.app.Person -import androidx.core.content.ContextCompat import androidx.core.content.res.ResourcesCompat import coil.ImageLoader import com.squareup.anvil.annotations.ContributesBinding @@ -107,6 +106,8 @@ class DefaultNotificationCreator @Inject constructor( private val acceptInvitationActionFactory: AcceptInvitationActionFactory, private val rejectInvitationActionFactory: RejectInvitationActionFactory ) : NotificationCreator { + private val accentColor = NotificationConfig.NOTIFICATION_ACCENT_COLOR + /** * Create a notification for a Room. */ @@ -121,7 +122,6 @@ class DefaultNotificationCreator @Inject constructor( imageLoader: ImageLoader, events: List, ): Notification { - val accentColor = ContextCompat.getColor(context, R.color.notification_accent_color) // Build the pending intent for when the notification is clicked val openIntent = when { threadId != null -> pendingIntentFactory.createOpenThreadPendingIntent(roomInfo, threadId) @@ -228,7 +228,6 @@ class DefaultNotificationCreator @Inject constructor( override fun createRoomInvitationNotification( inviteNotifiableEvent: InviteNotifiableEvent ): Notification { - val accentColor = ContextCompat.getColor(context, R.color.notification_accent_color) val smallIcon = CommonDrawables.ic_notification_small val channelId = notificationChannels.getChannelIdForMessage(inviteNotifiableEvent.noisy) return NotificationCompat.Builder(context, channelId) @@ -273,7 +272,6 @@ class DefaultNotificationCreator @Inject constructor( override fun createSimpleEventNotification( simpleNotifiableEvent: SimpleNotifiableEvent, ): Notification { - val accentColor = ContextCompat.getColor(context, R.color.notification_accent_color) val smallIcon = CommonDrawables.ic_notification_small val channelId = notificationChannels.getChannelIdForMessage(simpleNotifiableEvent.noisy) @@ -307,7 +305,6 @@ class DefaultNotificationCreator @Inject constructor( override fun createFallbackNotification( fallbackNotifiableEvent: FallbackNotifiableEvent, ): Notification { - val accentColor = ContextCompat.getColor(context, R.color.notification_accent_color) val smallIcon = CommonDrawables.ic_notification_small val channelId = notificationChannels.getChannelIdForMessage(false) @@ -344,7 +341,6 @@ class DefaultNotificationCreator @Inject constructor( noisy: Boolean, lastMessageTimestamp: Long ): Notification { - val accentColor = ContextCompat.getColor(context, R.color.notification_accent_color) val smallIcon = CommonDrawables.ic_notification_small val channelId = notificationChannels.getChannelIdForMessage(noisy) return NotificationCompat.Builder(context, channelId) @@ -384,7 +380,7 @@ class DefaultNotificationCreator @Inject constructor( .setContentText(stringProvider.getString(R.string.notification_test_push_notification_content)) .setSmallIcon(CommonDrawables.ic_notification_small) .setLargeIcon(getBitmap(R.drawable.element_logo_green)) - .setColor(ContextCompat.getColor(context, R.color.notification_accent_color)) + .setColor(accentColor) .setPriority(NotificationCompat.PRIORITY_MAX) .setCategory(NotificationCompat.CATEGORY_STATUS) .setAutoCancel(true) diff --git a/libraries/push/impl/src/main/res/values/colors.xml b/libraries/push/impl/src/main/res/values/colors.xml deleted file mode 100644 index 64a9d928fb..0000000000 --- a/libraries/push/impl/src/main/res/values/colors.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - #368BD6 - -