diff --git a/app-k9mail/src/main/kotlin/app/k9mail/provider/K9AppNotificationIconProvider.kt b/app-k9mail/src/main/kotlin/app/k9mail/provider/K9AppNotificationIconProvider.kt new file mode 100644 index 00000000000..6d53a01af18 --- /dev/null +++ b/app-k9mail/src/main/kotlin/app/k9mail/provider/K9AppNotificationIconProvider.kt @@ -0,0 +1,10 @@ +package app.k9mail.provider + +import app.k9mail.core.android.common.provider.NotificationIconResourceProvider +import app.k9mail.core.ui.legacy.theme2.k9mail.R + +class K9AppNotificationIconProvider : NotificationIconResourceProvider { + override val pushNotificationIcon: Int + + get() = R.drawable.ic_logo_k9_white +} diff --git a/app-k9mail/src/main/kotlin/app/k9mail/provider/ProviderModule.kt b/app-k9mail/src/main/kotlin/app/k9mail/provider/ProviderModule.kt index 07e236989f7..303aca7908b 100644 --- a/app-k9mail/src/main/kotlin/app/k9mail/provider/ProviderModule.kt +++ b/app-k9mail/src/main/kotlin/app/k9mail/provider/ProviderModule.kt @@ -1,5 +1,6 @@ package app.k9mail.provider +import app.k9mail.core.android.common.provider.NotificationIconResourceProvider import com.fsck.k9.preferences.FilePrefixProvider import net.thunderbird.core.common.provider.AppNameProvider import net.thunderbird.core.common.provider.BrandNameProvider @@ -17,4 +18,8 @@ internal val providerModule = module { single { K9ThemeProvider() } single { K9FeatureThemeProvider() } + + single { + K9AppNotificationIconProvider() + } } diff --git a/app-k9mail/src/test/kotlin/app/k9mail/K9AppNotificationIconProviderTest.kt b/app-k9mail/src/test/kotlin/app/k9mail/K9AppNotificationIconProviderTest.kt new file mode 100644 index 00000000000..ab59d1077bb --- /dev/null +++ b/app-k9mail/src/test/kotlin/app/k9mail/K9AppNotificationIconProviderTest.kt @@ -0,0 +1,17 @@ +package app.k9mail + +import app.k9mail.provider.K9AppNotificationIconProvider +import assertk.assertThat +import assertk.assertions.isEqualTo +import kotlin.test.Test + +class K9AppNotificationIconProviderTest { + @Test + fun `provides correct K9 notification icon`() { + val provider = K9AppNotificationIconProvider() + val icon = provider.pushNotificationIcon + + assertThat(icon) + .isEqualTo(app.k9mail.core.ui.legacy.theme2.k9mail.R.drawable.ic_logo_k9_white) + } +} diff --git a/app-thunderbird/src/main/kotlin/net/thunderbird/android/provider/ProviderModule.kt b/app-thunderbird/src/main/kotlin/net/thunderbird/android/provider/ProviderModule.kt index cf7d989eefd..cd46613fe83 100644 --- a/app-thunderbird/src/main/kotlin/net/thunderbird/android/provider/ProviderModule.kt +++ b/app-thunderbird/src/main/kotlin/net/thunderbird/android/provider/ProviderModule.kt @@ -1,5 +1,6 @@ package net.thunderbird.android.provider +import app.k9mail.core.android.common.provider.NotificationIconResourceProvider import com.fsck.k9.preferences.FilePrefixProvider import net.thunderbird.core.common.provider.AppNameProvider import net.thunderbird.core.common.provider.BrandNameProvider @@ -17,4 +18,8 @@ internal val providerModule = module { single { TbThemeProvider() } single { TbFeatureThemeProvider() } + + single { + TbAppIconNotificationProvider() + } } diff --git a/app-thunderbird/src/main/kotlin/net/thunderbird/android/provider/TbAppIconNotificationProvider.kt b/app-thunderbird/src/main/kotlin/net/thunderbird/android/provider/TbAppIconNotificationProvider.kt new file mode 100644 index 00000000000..6cbaba6179e --- /dev/null +++ b/app-thunderbird/src/main/kotlin/net/thunderbird/android/provider/TbAppIconNotificationProvider.kt @@ -0,0 +1,8 @@ +package net.thunderbird.android.provider + +import app.k9mail.core.android.common.provider.NotificationIconResourceProvider + +class TbAppIconNotificationProvider : NotificationIconResourceProvider { + override val pushNotificationIcon: Int + get() = app.k9mail.core.ui.legacy.theme2.thunderbird.R.drawable.ic_logo_thunderbird_white +} diff --git a/app-thunderbird/src/test/kotlin/net/thunderbird/android/TbAppIconNotificationProviderTest.kt b/app-thunderbird/src/test/kotlin/net/thunderbird/android/TbAppIconNotificationProviderTest.kt new file mode 100644 index 00000000000..86dd8c284d0 --- /dev/null +++ b/app-thunderbird/src/test/kotlin/net/thunderbird/android/TbAppIconNotificationProviderTest.kt @@ -0,0 +1,17 @@ +package net.thunderbird.android + +import assertk.assertThat +import assertk.assertions.isEqualTo +import net.thunderbird.android.provider.TbAppIconNotificationProvider +import org.junit.Test + +class TbAppIconNotificationProviderTest { + @Test + fun `provides correct Thunderbird notification icon`() { + val provider = TbAppIconNotificationProvider() + val icon = provider.pushNotificationIcon + + assertThat(icon) + .isEqualTo(app.k9mail.core.ui.legacy.theme2.thunderbird.R.drawable.ic_logo_thunderbird_white) + } +} diff --git a/core/android/common/src/main/kotlin/app/k9mail/core/android/common/provider/NotificationIconResourceProvider.kt b/core/android/common/src/main/kotlin/app/k9mail/core/android/common/provider/NotificationIconResourceProvider.kt new file mode 100644 index 00000000000..014283ae9f0 --- /dev/null +++ b/core/android/common/src/main/kotlin/app/k9mail/core/android/common/provider/NotificationIconResourceProvider.kt @@ -0,0 +1,5 @@ +package app.k9mail.core.android.common.provider + +interface NotificationIconResourceProvider { + val pushNotificationIcon: Int +} diff --git a/core/ui/legacy/theme2/k9mail/src/main/res/drawable/ic_logo_k9_white.xml b/core/ui/legacy/theme2/k9mail/src/main/res/drawable/ic_logo_k9_white.xml new file mode 100644 index 00000000000..a1f0d0b8a8b --- /dev/null +++ b/core/ui/legacy/theme2/k9mail/src/main/res/drawable/ic_logo_k9_white.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/core/ui/legacy/theme2/thunderbird/src/main/res/drawable/ic_logo_thunderbird_white.xml b/core/ui/legacy/theme2/thunderbird/src/main/res/drawable/ic_logo_thunderbird_white.xml new file mode 100644 index 00000000000..a2efb445b2a --- /dev/null +++ b/core/ui/legacy/theme2/thunderbird/src/main/res/drawable/ic_logo_thunderbird_white.xml @@ -0,0 +1,21 @@ + + + + + + + diff --git a/feature/debug-settings/build.gradle.kts b/feature/debug-settings/build.gradle.kts index 98331635e44..cb84a11f9de 100644 --- a/feature/debug-settings/build.gradle.kts +++ b/feature/debug-settings/build.gradle.kts @@ -16,4 +16,5 @@ dependencies { implementation(projects.core.outcome) implementation(projects.feature.mail.account.api) implementation(projects.feature.notification.api) + implementation(projects.core.android.common) } diff --git a/feature/debug-settings/src/debug/kotlin/net/thunderbird/feature/debug/settings/SecretDebugSettingsScreenPreview.kt b/feature/debug-settings/src/debug/kotlin/net/thunderbird/feature/debug/settings/SecretDebugSettingsScreenPreview.kt index 9daad49e3c3..4ed66462d57 100644 --- a/feature/debug-settings/src/debug/kotlin/net/thunderbird/feature/debug/settings/SecretDebugSettingsScreenPreview.kt +++ b/feature/debug-settings/src/debug/kotlin/net/thunderbird/feature/debug/settings/SecretDebugSettingsScreenPreview.kt @@ -4,6 +4,7 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.PreviewLightDark +import app.k9mail.core.android.common.provider.NotificationIconResourceProvider import app.k9mail.core.ui.compose.common.koin.koinPreview import app.k9mail.core.ui.compose.designsystem.PreviewWithThemesLightDark import kotlinx.coroutines.flow.Flow @@ -29,6 +30,11 @@ private fun SecretDebugSettingsScreenPreview() { override val notifications: StateFlow> = MutableStateFlow(emptySet()) } } + single { + object : NotificationIconResourceProvider { + override val pushNotificationIcon: Int = 0 + } + } single { DebugNotificationSectionViewModel( stringsResourceManager = object : StringsResourceManager { @@ -55,6 +61,7 @@ private fun SecretDebugSettingsScreenPreview() { error("not implemented") }, inAppNotificationStream = get(), + notificationIconResourceProvider = get(), ) } } WithContent { diff --git a/feature/debug-settings/src/debug/kotlin/net/thunderbird/feature/debug/settings/inject/FeatureDebugSettingsModule.kt b/feature/debug-settings/src/debug/kotlin/net/thunderbird/feature/debug/settings/inject/FeatureDebugSettingsModule.kt index 3677255c6f2..67e177a19d3 100644 --- a/feature/debug-settings/src/debug/kotlin/net/thunderbird/feature/debug/settings/inject/FeatureDebugSettingsModule.kt +++ b/feature/debug-settings/src/debug/kotlin/net/thunderbird/feature/debug/settings/inject/FeatureDebugSettingsModule.kt @@ -14,6 +14,7 @@ val featureDebugSettingsModule = module { accountManager = get(), notificationSender = get(), inAppNotificationStream = get(), + notificationIconResourceProvider = get(), ) } } diff --git a/feature/debug-settings/src/main/kotlin/net/thunderbird/feature/debug/settings/notification/DebugNotificationSectionViewModel.kt b/feature/debug-settings/src/main/kotlin/net/thunderbird/feature/debug/settings/notification/DebugNotificationSectionViewModel.kt index bad96c42c5f..c1c12202c62 100644 --- a/feature/debug-settings/src/main/kotlin/net/thunderbird/feature/debug/settings/notification/DebugNotificationSectionViewModel.kt +++ b/feature/debug-settings/src/main/kotlin/net/thunderbird/feature/debug/settings/notification/DebugNotificationSectionViewModel.kt @@ -1,6 +1,7 @@ package net.thunderbird.feature.debug.settings.notification import androidx.lifecycle.viewModelScope +import app.k9mail.core.android.common.provider.NotificationIconResourceProvider import app.k9mail.core.ui.compose.common.mvi.BaseViewModel import kotlin.reflect.KClass import kotlinx.collections.immutable.ImmutableList @@ -37,6 +38,7 @@ internal class DebugNotificationSectionViewModel( private val accountManager: AccountManager, private val notificationSender: NotificationSender, private val inAppNotificationStream: InAppNotificationStream, + private val notificationIconResourceProvider: NotificationIconResourceProvider, private val mainDispatcher: CoroutineDispatcher = Dispatchers.Main, ioDispatcher: CoroutineDispatcher = Dispatchers.IO, ) : BaseViewModel(initialState = State()), DebugNotificationSectionContract.ViewModel { @@ -60,6 +62,7 @@ internal class DebugNotificationSectionViewModel( add(PushServiceNotification.Listening::class) add(PushServiceNotification.WaitBackgroundSync::class) add(PushServiceNotification.WaitNetwork::class) + add(PushIconTestNotification::class) }.toPersistentList() val inAppNotificationTypes = buildList { @@ -281,6 +284,10 @@ internal class DebugNotificationSectionViewModel( PushServiceNotification.WaitNetwork::class -> PushServiceNotification.WaitNetwork() + PushIconTestNotification::class -> PushIconTestNotification( + pushIcon = notificationIconResourceProvider.pushNotificationIcon, + ) + else -> null } diff --git a/feature/debug-settings/src/main/kotlin/net/thunderbird/feature/debug/settings/notification/PushIconTestNotification.kt b/feature/debug-settings/src/main/kotlin/net/thunderbird/feature/debug/settings/notification/PushIconTestNotification.kt new file mode 100644 index 00000000000..8a5c53d2f2e --- /dev/null +++ b/feature/debug-settings/src/main/kotlin/net/thunderbird/feature/debug/settings/notification/PushIconTestNotification.kt @@ -0,0 +1,18 @@ +package net.thunderbird.feature.debug.settings.notification + +import net.thunderbird.feature.notification.api.NotificationChannel +import net.thunderbird.feature.notification.api.NotificationSeverity +import net.thunderbird.feature.notification.api.content.AppNotification +import net.thunderbird.feature.notification.api.content.SystemNotification +import net.thunderbird.feature.notification.api.ui.icon.NotificationIcon + +class PushIconTestNotification( + pushIcon: Int, + override val accountUuid: String? = null, +) : AppNotification(), SystemNotification { + override val title: String = "Push Icon Test" + override val contentText: String = "Verifying NotificationIconResourceProvider" + override val severity: NotificationSeverity = NotificationSeverity.Information + override val channel: NotificationChannel = NotificationChannel.PushService + override val icon: NotificationIcon = NotificationIcon(systemNotificationIcon = pushIcon) +} diff --git a/feature/widget/unread/src/test/kotlin/app/k9mail/feature/widget/unread/FakeCoreResourceProvider.kt b/feature/widget/unread/src/test/kotlin/app/k9mail/feature/widget/unread/FakeCoreResourceProvider.kt index ff48f47e69e..1d54aeb30c6 100644 --- a/feature/widget/unread/src/test/kotlin/app/k9mail/feature/widget/unread/FakeCoreResourceProvider.kt +++ b/feature/widget/unread/src/test/kotlin/app/k9mail/feature/widget/unread/FakeCoreResourceProvider.kt @@ -64,9 +64,6 @@ class FakeCoreResourceProvider : CoreResourceProvider { throw UnsupportedOperationException("not implemented") } - override val iconPushNotification: Int - get() = throw UnsupportedOperationException("not implemented") - override fun pushNotificationText(notificationState: PushNotificationState): String { throw UnsupportedOperationException("not implemented") } diff --git a/legacy/common/src/main/java/com/fsck/k9/resources/K9CoreResourceProvider.kt b/legacy/common/src/main/java/com/fsck/k9/resources/K9CoreResourceProvider.kt index 2cef5a35de3..b5e04f0489c 100644 --- a/legacy/common/src/main/java/com/fsck/k9/resources/K9CoreResourceProvider.kt +++ b/legacy/common/src/main/java/com/fsck/k9/resources/K9CoreResourceProvider.kt @@ -1,7 +1,6 @@ package com.fsck.k9.resources import android.content.Context -import app.k9mail.core.ui.legacy.designsystem.atom.icon.Icons import com.fsck.k9.CoreResourceProvider import com.fsck.k9.notification.PushNotificationState import com.fsck.k9.ui.R @@ -35,8 +34,6 @@ class K9CoreResourceProvider( override fun searchUnifiedFoldersTitle(): String = context.getString(R.string.integrated_inbox_title) override fun searchUnifiedFoldersDetail(): String = context.getString(R.string.integrated_inbox_detail) - override val iconPushNotification: Int = Icons.Outlined.Notifications - override fun pushNotificationText(notificationState: PushNotificationState): String { val resId = when (notificationState) { PushNotificationState.INITIALIZING -> R.string.push_notification_state_initializing diff --git a/legacy/core/build.gradle.kts b/legacy/core/build.gradle.kts index 1cf0d9e981e..92c06fc4b7e 100644 --- a/legacy/core/build.gradle.kts +++ b/legacy/core/build.gradle.kts @@ -56,7 +56,7 @@ dependencies { testImplementation(projects.backend.imap) testImplementation(projects.mail.protocols.smtp) testImplementation(projects.legacy.storage) - + testImplementation(projects.core.android.common) testImplementation(libs.kotlin.test) testImplementation(libs.kotlin.reflect) testImplementation(libs.robolectric) diff --git a/legacy/core/src/main/java/com/fsck/k9/CoreResourceProvider.kt b/legacy/core/src/main/java/com/fsck/k9/CoreResourceProvider.kt index 179fcd9a62f..ff2dc5d75e1 100644 --- a/legacy/core/src/main/java/com/fsck/k9/CoreResourceProvider.kt +++ b/legacy/core/src/main/java/com/fsck/k9/CoreResourceProvider.kt @@ -24,8 +24,6 @@ interface CoreResourceProvider { fun searchUnifiedFoldersTitle(): String fun searchUnifiedFoldersDetail(): String - - val iconPushNotification: Int fun pushNotificationText(notificationState: PushNotificationState): String fun pushNotificationInfoText(): String fun pushNotificationGrantAlarmPermissionText(): String diff --git a/legacy/core/src/main/java/com/fsck/k9/notification/CoreNotificationKoinModule.kt b/legacy/core/src/main/java/com/fsck/k9/notification/CoreNotificationKoinModule.kt index a78feeeb0ee..826da8130cb 100644 --- a/legacy/core/src/main/java/com/fsck/k9/notification/CoreNotificationKoinModule.kt +++ b/legacy/core/src/main/java/com/fsck/k9/notification/CoreNotificationKoinModule.kt @@ -58,6 +58,7 @@ val coreNotificationModule = module { actionBuilder = get(), resourceProvider = get(), outboxFolderManager = get(), + iconResourceProvider = get(), ) } single { @@ -127,6 +128,7 @@ val coreNotificationModule = module { resourceProvider = get(), notificationChannelManager = get(), notificationManager = get(), + iconResourceProvider = get(), ) } single { diff --git a/legacy/core/src/main/java/com/fsck/k9/notification/PushNotificationManager.kt b/legacy/core/src/main/java/com/fsck/k9/notification/PushNotificationManager.kt index 7fb2d19629e..78f43e08530 100644 --- a/legacy/core/src/main/java/com/fsck/k9/notification/PushNotificationManager.kt +++ b/legacy/core/src/main/java/com/fsck/k9/notification/PushNotificationManager.kt @@ -1,5 +1,4 @@ package com.fsck.k9.notification - import android.app.Notification import android.app.PendingIntent import android.content.Context @@ -10,6 +9,7 @@ import android.provider.Settings import androidx.core.app.NotificationCompat import androidx.core.app.NotificationManagerCompat import androidx.core.app.PendingIntentCompat +import app.k9mail.core.android.common.provider.NotificationIconResourceProvider import com.fsck.k9.CoreResourceProvider private const val PUSH_INFO_ACTION = "app.k9mail.action.PUSH_INFO" @@ -17,6 +17,7 @@ private const val PUSH_INFO_ACTION = "app.k9mail.action.PUSH_INFO" internal class PushNotificationManager( private val context: Context, private val resourceProvider: CoreResourceProvider, + private val iconResourceProvider: NotificationIconResourceProvider, private val notificationChannelManager: NotificationChannelManager, private val notificationManager: NotificationManagerCompat, ) { @@ -53,7 +54,7 @@ internal class PushNotificationManager( private fun createNotification(): Notification { return NotificationCompat.Builder(context, notificationChannelManager.pushChannelId) - .setSmallIcon(resourceProvider.iconPushNotification) + .setSmallIcon(iconResourceProvider.pushNotificationIcon) .setContentTitle(resourceProvider.pushNotificationText(notificationState)) .setContentText(getContentText()) .setContentIntent(getContentIntent()) diff --git a/legacy/core/src/main/java/com/fsck/k9/notification/SyncNotificationController.kt b/legacy/core/src/main/java/com/fsck/k9/notification/SyncNotificationController.kt index 8ff5835e8bb..b1292421d71 100644 --- a/legacy/core/src/main/java/com/fsck/k9/notification/SyncNotificationController.kt +++ b/legacy/core/src/main/java/com/fsck/k9/notification/SyncNotificationController.kt @@ -3,6 +3,7 @@ package com.fsck.k9.notification import android.app.Notification import androidx.core.app.NotificationCompat import androidx.core.app.NotificationManagerCompat +import app.k9mail.core.android.common.provider.NotificationIconResourceProvider import com.fsck.k9.mailstore.LocalFolder import net.thunderbird.core.android.account.LegacyAccountDto import net.thunderbird.feature.mail.folder.api.OutboxFolderManager @@ -12,6 +13,7 @@ internal class SyncNotificationController( private val actionBuilder: NotificationActionCreator, private val resourceProvider: NotificationResourceProvider, private val outboxFolderManager: OutboxFolderManager, + private val iconResourceProvider: NotificationIconResourceProvider, ) { fun showSendingNotification(account: LegacyAccountDto) { val accountName = account.displayName @@ -60,7 +62,7 @@ internal class SyncNotificationController( val notificationBuilder = notificationHelper .createNotificationBuilder(account, NotificationChannelManager.ChannelType.MISCELLANEOUS) - .setSmallIcon(resourceProvider.iconCheckingMail) + .setSmallIcon(iconResourceProvider.pushNotificationIcon) .setColor(account.chipColor) .setWhen(System.currentTimeMillis()) .setOngoing(true) @@ -70,7 +72,6 @@ internal class SyncNotificationController( .setContentIntent(showMessageListPendingIntent) .setPublicVersion(createFetchingMailLockScreenNotification(account)) .setCategory(NotificationCompat.CATEGORY_SERVICE) - notificationManager.notify(notificationId, notificationBuilder.build()) } @@ -81,7 +82,7 @@ internal class SyncNotificationController( val notificationBuilder = notificationHelper .createNotificationBuilder(account, NotificationChannelManager.ChannelType.MISCELLANEOUS) - .setSmallIcon(resourceProvider.iconCheckingMail) + .setSmallIcon(iconResourceProvider.pushNotificationIcon) .setColor(account.chipColor) .setWhen(System.currentTimeMillis()) .setOngoing(true) diff --git a/legacy/core/src/test/java/com/fsck/k9/TestApp.kt b/legacy/core/src/test/java/com/fsck/k9/TestApp.kt index e0d12e93e5e..57d704a077a 100644 --- a/legacy/core/src/test/java/com/fsck/k9/TestApp.kt +++ b/legacy/core/src/test/java/com/fsck/k9/TestApp.kt @@ -2,6 +2,7 @@ package com.fsck.k9 import android.app.Application import androidx.work.WorkManager +import app.k9mail.core.android.common.provider.NotificationIconResourceProvider import app.k9mail.feature.telemetry.telemetryModule import app.k9mail.legacy.di.DI import com.fsck.k9.backend.BackendManager @@ -10,6 +11,7 @@ import com.fsck.k9.crypto.EncryptionExtractor import com.fsck.k9.notification.NotificationActionCreator import com.fsck.k9.notification.NotificationResourceProvider import com.fsck.k9.notification.NotificationStrategy +import com.fsck.k9.notification.TestNotificationIconResourceProvider import com.fsck.k9.storage.storageModule import net.thunderbird.core.android.account.AccountDefaultsProvider import net.thunderbird.core.android.account.LegacyAccountManager @@ -93,4 +95,5 @@ val testModule = module { } single { FakeOutboxFolderManager() } single { mock() } + single { TestNotificationIconResourceProvider() } } diff --git a/legacy/core/src/test/java/com/fsck/k9/TestCoreResourceProvider.kt b/legacy/core/src/test/java/com/fsck/k9/TestCoreResourceProvider.kt index e48895ac4db..652b607959f 100644 --- a/legacy/core/src/test/java/com/fsck/k9/TestCoreResourceProvider.kt +++ b/legacy/core/src/test/java/com/fsck/k9/TestCoreResourceProvider.kt @@ -26,9 +26,6 @@ class TestCoreResourceProvider : CoreResourceProvider { override fun searchUnifiedFoldersTitle() = "Unified Folders" override fun searchUnifiedFoldersDetail() = "All messages in unified folders" - override val iconPushNotification: Int - get() = throw UnsupportedOperationException("not implemented") - override fun pushNotificationText(notificationState: PushNotificationState): String { throw UnsupportedOperationException("not implemented") } diff --git a/legacy/core/src/test/java/com/fsck/k9/notification/SyncNotificationControllerTest.kt b/legacy/core/src/test/java/com/fsck/k9/notification/SyncNotificationControllerTest.kt index 828052706bb..f8b253be558 100644 --- a/legacy/core/src/test/java/com/fsck/k9/notification/SyncNotificationControllerTest.kt +++ b/legacy/core/src/test/java/com/fsck/k9/notification/SyncNotificationControllerTest.kt @@ -5,6 +5,7 @@ import android.app.PendingIntent import androidx.core.app.NotificationCompat import androidx.core.app.NotificationManagerCompat import androidx.test.core.app.ApplicationProvider +import app.k9mail.core.android.common.provider.NotificationIconResourceProvider import com.fsck.k9.mailstore.LocalFolder import com.fsck.k9.notification.NotificationIds.getFetchingMailNotificationId import net.thunderbird.core.android.account.LegacyAccountDto @@ -25,9 +26,12 @@ private const val ACCOUNT_NUMBER = 1 private const val ACCOUNT_NAME = "TestAccount" private const val FOLDER_SERVER_ID = "INBOX" private const val FOLDER_NAME = "Inbox" +private const val TEST_ICON_ID = 0xCAFE class SyncNotificationControllerTest : RobolectricTest() { private val resourceProvider: NotificationResourceProvider = TestNotificationResourceProvider() + private val iconResourceProvider: NotificationIconResourceProvider = + TestNotificationIconResourceProvider(pushNotificationIcon = TEST_ICON_ID) private val notification = mock() private val lockScreenNotification = mock() private val notificationManager = mock() @@ -40,6 +44,7 @@ class SyncNotificationControllerTest : RobolectricTest() { actionBuilder = createActionBuilder(contentIntent), resourceProvider = resourceProvider, outboxFolderManager = FakeOutboxFolderManager(outboxFolderId = 33L), + iconResourceProvider = iconResourceProvider, ) @Test @@ -77,7 +82,7 @@ class SyncNotificationControllerTest : RobolectricTest() { controller.showFetchingMailNotification(account, localFolder) verify(notificationManager).notify(notificationId, notification) - verify(builder).setSmallIcon(resourceProvider.iconCheckingMail) + verify(builder).setSmallIcon(iconResourceProvider.pushNotificationIcon) verify(builder).setTicker("Checking mail: $ACCOUNT_NAME:$FOLDER_NAME") verify(builder).setContentTitle("Checking mail") verify(builder).setContentText("$ACCOUNT_NAME:$FOLDER_NAME") @@ -95,7 +100,7 @@ class SyncNotificationControllerTest : RobolectricTest() { controller.showEmptyFetchingMailNotification(account) verify(notificationManager).notify(notificationId, notification) - verify(builder).setSmallIcon(resourceProvider.iconCheckingMail) + verify(builder).setSmallIcon(iconResourceProvider.pushNotificationIcon) verify(builder).setContentTitle("Checking mail") verify(builder).setContentText(ACCOUNT_NAME) verify(builder).setPublicVersion(lockScreenNotification) diff --git a/legacy/core/src/test/java/com/fsck/k9/notification/TestNotificationIconResourceProvider.kt b/legacy/core/src/test/java/com/fsck/k9/notification/TestNotificationIconResourceProvider.kt new file mode 100644 index 00000000000..f13b0dc2d0d --- /dev/null +++ b/legacy/core/src/test/java/com/fsck/k9/notification/TestNotificationIconResourceProvider.kt @@ -0,0 +1,7 @@ +package com.fsck.k9.notification + +import app.k9mail.core.android.common.provider.NotificationIconResourceProvider + +class TestNotificationIconResourceProvider( + override val pushNotificationIcon: Int = 9999, +) : NotificationIconResourceProvider diff --git a/legacy/storage/src/test/java/com/fsck/k9/storage/TestApp.kt b/legacy/storage/src/test/java/com/fsck/k9/storage/TestApp.kt index 9b3e0e150e0..f4681413ccb 100644 --- a/legacy/storage/src/test/java/com/fsck/k9/storage/TestApp.kt +++ b/legacy/storage/src/test/java/com/fsck/k9/storage/TestApp.kt @@ -1,6 +1,7 @@ package com.fsck.k9.storage import android.app.Application +import app.k9mail.core.android.common.provider.NotificationIconResourceProvider import app.k9mail.feature.telemetry.telemetryModule import app.k9mail.legacy.di.DI import com.fsck.k9.AppConfig @@ -83,4 +84,9 @@ val testModule = module { ) } single { mock() } + single { + object : NotificationIconResourceProvider { + override val pushNotificationIcon: Int = 0 + } + } } diff --git a/legacy/ui/legacy/src/test/java/com/fsck/k9/TestCoreResourceProvider.kt b/legacy/ui/legacy/src/test/java/com/fsck/k9/TestCoreResourceProvider.kt index 5562a6fd57e..b099f53e7cd 100644 --- a/legacy/ui/legacy/src/test/java/com/fsck/k9/TestCoreResourceProvider.kt +++ b/legacy/ui/legacy/src/test/java/com/fsck/k9/TestCoreResourceProvider.kt @@ -26,9 +26,6 @@ class TestCoreResourceProvider : CoreResourceProvider { override fun searchUnifiedFoldersTitle() = throw UnsupportedOperationException("not implemented") override fun searchUnifiedFoldersDetail() = throw UnsupportedOperationException("not implemented") - override val iconPushNotification: Int - get() = throw UnsupportedOperationException("not implemented") - override fun pushNotificationText(notificationState: PushNotificationState): String { throw UnsupportedOperationException("not implemented") }