From 02c376b9bf8b884a6bd6f2337ee9ff46b4f22d1c Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 19 Jun 2024 10:37:33 +0200 Subject: [PATCH 01/12] Notification channels: small iteration on old channel deletion. --- .../notifications/channels/NotificationChannels.kt | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) 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 a40871be4c..ddf12ebafb 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 @@ -41,10 +41,6 @@ import javax.inject.Inject private const val LISTENING_FOR_EVENTS_NOTIFICATION_CHANNEL_ID = "LISTEN_FOR_EVENTS_NOTIFICATION_CHANNEL_ID" internal const val SILENT_NOTIFICATION_CHANNEL_ID = "DEFAULT_SILENT_NOTIFICATION_CHANNEL_ID_V2" internal const val NOISY_NOTIFICATION_CHANNEL_ID = "DEFAULT_NOISY_NOTIFICATION_CHANNEL_ID" - -// Legacy channel -private const val CALL_NOTIFICATION_CHANNEL_ID_V2 = "CALL_NOTIFICATION_CHANNEL_ID_V2" - internal const val CALL_NOTIFICATION_CHANNEL_ID_V3 = "CALL_NOTIFICATION_CHANNEL_ID_V3" internal const val RINGING_CALL_NOTIFICATION_CHANNEL_ID = "RINGING_CALL_NOTIFICATION_CHANNEL_ID" @@ -110,15 +106,16 @@ class DefaultNotificationChannels @Inject constructor( } } // Migration - Remove deprecated channels - for (channelId in listOf("DEFAULT_SILENT_NOTIFICATION_CHANNEL_ID", "CALL_NOTIFICATION_CHANNEL_ID")) { + for (channelId in listOf( + "DEFAULT_SILENT_NOTIFICATION_CHANNEL_ID", + "CALL_NOTIFICATION_CHANNEL_ID", + "CALL_NOTIFICATION_CHANNEL_ID_V2", + )) { notificationManager.getNotificationChannel(channelId)?.let { notificationManager.deleteNotificationChannel(channelId) } } - // Migration - Create new call channel - notificationManager.deleteNotificationChannel(CALL_NOTIFICATION_CHANNEL_ID_V2) - /** * Default notification importance: shows everywhere, makes noise, but does not visually * intrude. From e66a725f301c5c6c549120adda8032063bab7d62 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 19 Jun 2024 10:39:03 +0200 Subject: [PATCH 02/12] Notification channels: Remove unused `LISTEN_FOR_EVENTS_NOTIFICATION_CHANNEL_ID` --- .../channels/NotificationChannels.kt | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) 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 ddf12ebafb..4421dd3d3d 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 @@ -38,7 +38,6 @@ import javax.inject.Inject /* ========================================================================================== * IDs for channels * ========================================================================================== */ -private const val LISTENING_FOR_EVENTS_NOTIFICATION_CHANNEL_ID = "LISTEN_FOR_EVENTS_NOTIFICATION_CHANNEL_ID" internal const val SILENT_NOTIFICATION_CHANNEL_ID = "DEFAULT_SILENT_NOTIFICATION_CHANNEL_ID_V2" internal const val NOISY_NOTIFICATION_CHANNEL_ID = "DEFAULT_NOISY_NOTIFICATION_CHANNEL_ID" internal const val CALL_NOTIFICATION_CHANNEL_ID_V3 = "CALL_NOTIFICATION_CHANNEL_ID_V3" @@ -110,6 +109,7 @@ class DefaultNotificationChannels @Inject constructor( "DEFAULT_SILENT_NOTIFICATION_CHANNEL_ID", "CALL_NOTIFICATION_CHANNEL_ID", "CALL_NOTIFICATION_CHANNEL_ID_V2", + "LISTEN_FOR_EVENTS_NOTIFICATION_CHANNEL_ID", )) { notificationManager.getNotificationChannel(channelId)?.let { notificationManager.deleteNotificationChannel(channelId) @@ -151,19 +151,6 @@ class DefaultNotificationChannels @Inject constructor( } ) - notificationManager.createNotificationChannel( - NotificationChannel( - LISTENING_FOR_EVENTS_NOTIFICATION_CHANNEL_ID, - stringProvider.getString(R.string.notification_channel_listening_for_events).ifEmpty { "Listening for events" }, - NotificationManager.IMPORTANCE_MIN - ) - .apply { - description = stringProvider.getString(R.string.notification_channel_listening_for_events) - setSound(null, null) - setShowBadge(false) - } - ) - // Register a channel for incoming and in progress call notifications with no ringing notificationManager.createNotificationChannel( NotificationChannel( From ed5eb481593bd780d5df20cf99909183fd92602d Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 19 Jun 2024 10:40:10 +0200 Subject: [PATCH 03/12] Notification channels: No need to include the version in the constant name. --- .../impl/notifications/channels/NotificationChannels.kt | 6 +++--- .../impl/notifications/channels/NotificationChannelsTest.kt | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) 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 4421dd3d3d..cb3a59cb1a 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 @@ -40,7 +40,7 @@ import javax.inject.Inject * ========================================================================================== */ internal const val SILENT_NOTIFICATION_CHANNEL_ID = "DEFAULT_SILENT_NOTIFICATION_CHANNEL_ID_V2" internal const val NOISY_NOTIFICATION_CHANNEL_ID = "DEFAULT_NOISY_NOTIFICATION_CHANNEL_ID" -internal const val CALL_NOTIFICATION_CHANNEL_ID_V3 = "CALL_NOTIFICATION_CHANNEL_ID_V3" +internal const val CALL_NOTIFICATION_CHANNEL_ID = "CALL_NOTIFICATION_CHANNEL_ID_V3" internal const val RINGING_CALL_NOTIFICATION_CHANNEL_ID = "RINGING_CALL_NOTIFICATION_CHANNEL_ID" /** @@ -154,7 +154,7 @@ class DefaultNotificationChannels @Inject constructor( // Register a channel for incoming and in progress call notifications with no ringing notificationManager.createNotificationChannel( NotificationChannel( - CALL_NOTIFICATION_CHANNEL_ID_V3, + CALL_NOTIFICATION_CHANNEL_ID, stringProvider.getString(R.string.notification_channel_call).ifEmpty { "Call" }, NotificationManager.IMPORTANCE_HIGH ) @@ -191,7 +191,7 @@ class DefaultNotificationChannels @Inject constructor( } override fun getChannelForIncomingCall(ring: Boolean): String { - return if (ring) RINGING_CALL_NOTIFICATION_CHANNEL_ID else CALL_NOTIFICATION_CHANNEL_ID_V3 + return if (ring) RINGING_CALL_NOTIFICATION_CHANNEL_ID else CALL_NOTIFICATION_CHANNEL_ID } override fun getChannelIdForMessage(noisy: Boolean): String { diff --git a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/channels/NotificationChannelsTest.kt b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/channels/NotificationChannelsTest.kt index ec87069cd2..cc6a9f0225 100644 --- a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/channels/NotificationChannelsTest.kt +++ b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/channels/NotificationChannelsTest.kt @@ -55,7 +55,7 @@ class NotificationChannelsTest { assertThat(ringingChannel).isEqualTo(RINGING_CALL_NOTIFICATION_CHANNEL_ID) val normalChannel = notificationChannels.getChannelForIncomingCall(ring = false) - assertThat(normalChannel).isEqualTo(CALL_NOTIFICATION_CHANNEL_ID_V3) + assertThat(normalChannel).isEqualTo(CALL_NOTIFICATION_CHANNEL_ID) } @Test From bebd344e72f859d1e17b5b9090a71f75972bf904 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 19 Jun 2024 10:53:20 +0200 Subject: [PATCH 04/12] Notification channels: Use `NotificationChannelCompat.Builder`. --- .../channels/NotificationChannels.kt | 53 +++++++++---------- .../channels/NotificationChannelsTest.kt | 1 - 2 files changed, 24 insertions(+), 30 deletions(-) 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 cb3a59cb1a..6cfff8b9e3 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 @@ -16,8 +16,6 @@ package io.element.android.libraries.push.impl.notifications.channels -import android.app.NotificationChannel -import android.app.NotificationManager import android.content.Context import android.media.AudioAttributes import android.media.AudioManager @@ -121,49 +119,46 @@ class DefaultNotificationChannels @Inject constructor( * intrude. */ notificationManager.createNotificationChannel( - NotificationChannel( + NotificationChannelCompat.Builder( NOISY_NOTIFICATION_CHANNEL_ID, - stringProvider.getString(R.string.notification_channel_noisy).ifEmpty { "Noisy notifications" }, - NotificationManager.IMPORTANCE_DEFAULT + NotificationManagerCompat.IMPORTANCE_DEFAULT ) - .apply { - description = stringProvider.getString(R.string.notification_channel_noisy) - enableVibration(true) - enableLights(true) - lightColor = accentColor - } + .setName(stringProvider.getString(R.string.notification_channel_noisy).ifEmpty { "Noisy notifications" }) + .setDescription(stringProvider.getString(R.string.notification_channel_noisy)) + .setVibrationEnabled(true) + .setLightsEnabled(true) + .setLightColor(accentColor) + .build() ) /** * Low notification importance: shows everywhere, but is not intrusive. */ notificationManager.createNotificationChannel( - NotificationChannel( + NotificationChannelCompat.Builder( SILENT_NOTIFICATION_CHANNEL_ID, - stringProvider.getString(R.string.notification_channel_silent).ifEmpty { "Silent notifications" }, - NotificationManager.IMPORTANCE_LOW + NotificationManagerCompat.IMPORTANCE_LOW ) - .apply { - description = stringProvider.getString(R.string.notification_channel_silent) - setSound(null, null) - enableLights(true) - lightColor = accentColor - } + .setName(stringProvider.getString(R.string.notification_channel_silent).ifEmpty { "Silent notifications" }) + .setDescription(stringProvider.getString(R.string.notification_channel_silent)) + .setSound(null, null) + .setLightsEnabled(true) + .setLightColor(accentColor) + .build() ) // Register a channel for incoming and in progress call notifications with no ringing notificationManager.createNotificationChannel( - NotificationChannel( + NotificationChannelCompat.Builder( CALL_NOTIFICATION_CHANNEL_ID, - stringProvider.getString(R.string.notification_channel_call).ifEmpty { "Call" }, - NotificationManager.IMPORTANCE_HIGH + NotificationManagerCompat.IMPORTANCE_HIGH ) - .apply { - description = stringProvider.getString(R.string.notification_channel_call) - enableVibration(true) - enableLights(true) - lightColor = accentColor - } + .setName(stringProvider.getString(R.string.notification_channel_call).ifEmpty { "Call" }) + .setDescription(stringProvider.getString(R.string.notification_channel_call)) + .setVibrationEnabled(true) + .setLightsEnabled(true) + .setLightColor(accentColor) + .build() ) // Register a channel for incoming call notifications which will ring the device when received diff --git a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/channels/NotificationChannelsTest.kt b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/channels/NotificationChannelsTest.kt index cc6a9f0225..c100170f07 100644 --- a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/channels/NotificationChannelsTest.kt +++ b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/channels/NotificationChannelsTest.kt @@ -43,7 +43,6 @@ class NotificationChannelsTest { createNotificationChannels(notificationManager = notificationManager) verify { notificationManager.createNotificationChannel(any()) } - verify { notificationManager.createNotificationChannel(any()) } verify { notificationManager.deleteNotificationChannel(any()) } } From 7d571443841823a7d9291d286c000f7d591293bd Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 19 Jun 2024 11:09:57 +0200 Subject: [PATCH 05/12] Add preview for disabled notifications. --- .../impl/notifications/NotificationSettingsStateProvider.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsStateProvider.kt b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsStateProvider.kt index 0aace5ea43..a669126e34 100644 --- a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsStateProvider.kt +++ b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsStateProvider.kt @@ -42,6 +42,7 @@ open class NotificationSettingsStateProvider : PreviewParameterProvider Date: Wed, 19 Jun 2024 11:15:49 +0200 Subject: [PATCH 06/12] Always notify for incoming calls, even if notifications are disabled. --- .../push/impl/push/DefaultPushHandler.kt | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/push/DefaultPushHandler.kt b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/push/DefaultPushHandler.kt index fda14f294f..a553c14952 100644 --- a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/push/DefaultPushHandler.kt +++ b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/push/DefaultPushHandler.kt @@ -96,17 +96,19 @@ class DefaultPushHandler @Inject constructor( Timber.w("Unable to get a session") return } - val userPushStore = userPushStoreFactory.getOrCreate(userId) - val areNotificationsEnabled = userPushStore.getNotificationEnabledForDevice().first() - if (areNotificationsEnabled) { - val notifiableEvent = notifiableEventResolver.resolveEvent(userId, pushData.roomId, pushData.eventId) - when (notifiableEvent) { - null -> Timber.tag(loggerTag.value).w("Unable to get a notification data") - is NotifiableRingingCallEvent -> handleRingingCallEvent(notifiableEvent) - else -> onNotifiableEventReceived.onNotifiableEventReceived(notifiableEvent) + val notifiableEvent = notifiableEventResolver.resolveEvent(userId, pushData.roomId, pushData.eventId) + when (notifiableEvent) { + null -> Timber.tag(loggerTag.value).w("Unable to get a notification data") + is NotifiableRingingCallEvent -> handleRingingCallEvent(notifiableEvent) + else -> { + val userPushStore = userPushStoreFactory.getOrCreate(userId) + val areNotificationsEnabled = userPushStore.getNotificationEnabledForDevice().first() + if (areNotificationsEnabled) { + onNotifiableEventReceived.onNotifiableEventReceived(notifiableEvent) + } else { + Timber.tag(loggerTag.value).i("Notification are disabled for this device, ignore push.") + } } - } else { - Timber.tag(loggerTag.value).i("Notification are disabled for this device, ignore push.") } } catch (e: Exception) { Timber.tag(loggerTag.value).e(e, "## handleInternal() failed") From 416cbb679b2445ea53e1c80e816a318a4c7c8c75 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 19 Jun 2024 11:44:08 +0200 Subject: [PATCH 07/12] Update test and add test for incoming call when notifications are disabled. --- .../push/impl/push/DefaultPushHandlerTest.kt | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/push/DefaultPushHandlerTest.kt b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/push/DefaultPushHandlerTest.kt index 9e37aae29d..4953e4d7b4 100644 --- a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/push/DefaultPushHandlerTest.kt +++ b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/push/DefaultPushHandlerTest.kt @@ -118,7 +118,7 @@ class DefaultPushHandlerTest { incrementPushCounterResult.assertions() .isCalledOnce() notifiableEventResult.assertions() - .isNeverCalled() + .isCalledOnce() onNotifiableEventReceived.assertions() .isNeverCalled() } @@ -277,6 +277,34 @@ class DefaultPushHandlerTest { onNotifiableEventReceived.assertions().isCalledOnce() } + @Test + fun `when notify call PushData is received, the incoming call will be treated as a normal notification even if notification are disabled`() = runTest { + val aPushData = PushData( + eventId = AN_EVENT_ID, + roomId = A_ROOM_ID, + unread = 0, + clientSecret = A_SECRET, + ) + val onNotifiableEventReceived = lambdaRecorder {} + val handleIncomingCallLambda = lambdaRecorder { _, _, _, _, _, _, _ -> } + val elementCallEntryPoint = FakeElementCallEntryPoint(handleIncomingCallResult = handleIncomingCallLambda) + val defaultPushHandler = createDefaultPushHandler( + elementCallEntryPoint = elementCallEntryPoint, + onNotifiableEventReceived = onNotifiableEventReceived, + notifiableEventResult = { _, _, _ -> aNotifiableCallEvent() }, + incrementPushCounterResult = {}, + userPushStore = FakeUserPushStore().apply { + setNotificationEnabledForDevice(false) + }, + pushClientSecret = FakePushClientSecret( + getUserIdFromSecretResult = { A_USER_ID } + ), + ) + defaultPushHandler.handle(aPushData) + handleIncomingCallLambda.assertions().isCalledOnce() + onNotifiableEventReceived.assertions().isNeverCalled() + } + @Test fun `when diagnostic PushData is received, the diagnostic push handler is informed `() = runTest { From 67caae492d4b8b7ca2c4665e0472d994842252ca Mon Sep 17 00:00:00 2001 From: ElementBot Date: Wed, 19 Jun 2024 11:52:27 +0000 Subject: [PATCH 08/12] Update screenshots --- ...otificationSettingsView-Day-6_7_null_12,NEXUS_5,1.0,en].png | 3 +++ ...ificationSettingsView-Night-6_8_null_12,NEXUS_5,1.0,en].png | 3 +++ 2 files changed, 6 insertions(+) create mode 100644 tests/uitests/src/test/snapshots/images/ui_S_t[f.preferences.impl.notifications_NotificationSettingsView_null_NotificationSettingsView-Day-6_7_null_12,NEXUS_5,1.0,en].png create mode 100644 tests/uitests/src/test/snapshots/images/ui_S_t[f.preferences.impl.notifications_NotificationSettingsView_null_NotificationSettingsView-Night-6_8_null_12,NEXUS_5,1.0,en].png diff --git a/tests/uitests/src/test/snapshots/images/ui_S_t[f.preferences.impl.notifications_NotificationSettingsView_null_NotificationSettingsView-Day-6_7_null_12,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/ui_S_t[f.preferences.impl.notifications_NotificationSettingsView_null_NotificationSettingsView-Day-6_7_null_12,NEXUS_5,1.0,en].png new file mode 100644 index 0000000000..c4783027f4 --- /dev/null +++ b/tests/uitests/src/test/snapshots/images/ui_S_t[f.preferences.impl.notifications_NotificationSettingsView_null_NotificationSettingsView-Day-6_7_null_12,NEXUS_5,1.0,en].png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b97743618b94a6f0e9f3e9d1e776f818deafb8e1bfb9671e85497359b2d45a95 +size 15210 diff --git a/tests/uitests/src/test/snapshots/images/ui_S_t[f.preferences.impl.notifications_NotificationSettingsView_null_NotificationSettingsView-Night-6_8_null_12,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/ui_S_t[f.preferences.impl.notifications_NotificationSettingsView_null_NotificationSettingsView-Night-6_8_null_12,NEXUS_5,1.0,en].png new file mode 100644 index 0000000000..612f5af55b --- /dev/null +++ b/tests/uitests/src/test/snapshots/images/ui_S_t[f.preferences.impl.notifications_NotificationSettingsView_null_NotificationSettingsView-Night-6_8_null_12,NEXUS_5,1.0,en].png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ea1f406cdc673d242f6a8920da2f15316961f9765ddb43e189ef1c057417658a +size 14762 From 2c181e376b319f9759b7abe2d06f16e271d4cc4d Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 19 Jun 2024 13:47:26 +0200 Subject: [PATCH 09/12] Remove unused import. --- .../push/impl/notifications/channels/NotificationChannelsTest.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/channels/NotificationChannelsTest.kt b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/channels/NotificationChannelsTest.kt index c100170f07..07eadc099e 100644 --- a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/channels/NotificationChannelsTest.kt +++ b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/channels/NotificationChannelsTest.kt @@ -16,7 +16,6 @@ package io.element.android.libraries.push.impl.notifications.channels -import android.app.NotificationChannel import android.os.Build import androidx.core.app.NotificationChannelCompat import androidx.core.app.NotificationManagerCompat From faa40dbb195bb1abdb88f97cefaa0b32c420ea7c Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 19 Jun 2024 16:40:33 +0200 Subject: [PATCH 10/12] 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 - - From 8a91ec7254e1a3a6442ef17e45a3f3cb9697ca9f Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 19 Jun 2024 17:32:49 +0200 Subject: [PATCH 11/12] Change color use in notification to FF0DBD8B --- .../kotlin/io/element/android/appconfig/NotificationConfig.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 fa7e57ec8c..cca9f8df12 100644 --- a/appconfig/src/main/kotlin/io/element/android/appconfig/NotificationConfig.kt +++ b/appconfig/src/main/kotlin/io/element/android/appconfig/NotificationConfig.kt @@ -30,5 +30,5 @@ object NotificationConfig { const val SUPPORT_QUICK_REPLY_ACTION = false @ColorInt - val NOTIFICATION_ACCENT_COLOR: Int = Color.parseColor("#FF368BD6") + val NOTIFICATION_ACCENT_COLOR: Int = Color.parseColor("#FF0DBD8B") } From 5ef27c2cde9c009205941b319f10b6861533ca34 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 19 Jun 2024 17:38:17 +0200 Subject: [PATCH 12/12] changelog --- changelog.d/3053.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/3053.misc diff --git a/changelog.d/3053.misc b/changelog.d/3053.misc new file mode 100644 index 0000000000..6a22cc363a --- /dev/null +++ b/changelog.d/3053.misc @@ -0,0 +1 @@ +Alert for incoming call even if notifications are disabled