From bb1c1012e1d5cb7161c59bb8367857aa68a93c66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolf-Martell=20Montw=C3=A9?= Date: Wed, 6 Mar 2024 17:39:38 +0100 Subject: [PATCH] Add theme2 support for K9Mail to catalog app --- app-ui-catalog/build.gradle.kts | 2 ++ .../k9mail/ui/catalog/CatalogApplication.kt | 2 +- .../ui/catalog/{ui => di}/CatalogUiModule.kt | 3 ++- .../k9mail/ui/catalog/ui/CatalogContract.kt | 7 +++-- .../k9mail/ui/catalog/ui/CatalogViewModel.kt | 22 ++++++++------- .../ui/catalog/ui/common/theme/ThemeSwitch.kt | 27 +++++++++++++++++++ settings.gradle.kts | 1 + 7 files changed, 50 insertions(+), 14 deletions(-) rename app-ui-catalog/src/main/java/app/k9mail/ui/catalog/{ui => di}/CatalogUiModule.kt (69%) diff --git a/app-ui-catalog/build.gradle.kts b/app-ui-catalog/build.gradle.kts index 2e2544b48..c7cb5d06e 100644 --- a/app-ui-catalog/build.gradle.kts +++ b/app-ui-catalog/build.gradle.kts @@ -15,6 +15,8 @@ android { dependencies { implementation(projects.core.ui.compose.designsystem) + implementation(projects.core.ui.compose.theme2.k9mail) + implementation(libs.androidx.compose.material) implementation(libs.androidx.compose.material.icons.extended) } diff --git a/app-ui-catalog/src/main/java/app/k9mail/ui/catalog/CatalogApplication.kt b/app-ui-catalog/src/main/java/app/k9mail/ui/catalog/CatalogApplication.kt index f0703f6a7..4e15b85b5 100644 --- a/app-ui-catalog/src/main/java/app/k9mail/ui/catalog/CatalogApplication.kt +++ b/app-ui-catalog/src/main/java/app/k9mail/ui/catalog/CatalogApplication.kt @@ -1,7 +1,7 @@ package app.k9mail.ui.catalog import android.app.Application -import app.k9mail.ui.catalog.ui.catalogUiModule +import app.k9mail.ui.catalog.di.catalogUiModule import org.koin.android.ext.koin.androidContext import org.koin.core.context.startKoin diff --git a/app-ui-catalog/src/main/java/app/k9mail/ui/catalog/ui/CatalogUiModule.kt b/app-ui-catalog/src/main/java/app/k9mail/ui/catalog/di/CatalogUiModule.kt similarity index 69% rename from app-ui-catalog/src/main/java/app/k9mail/ui/catalog/ui/CatalogUiModule.kt rename to app-ui-catalog/src/main/java/app/k9mail/ui/catalog/di/CatalogUiModule.kt index 1df410012..e2245c9b6 100644 --- a/app-ui-catalog/src/main/java/app/k9mail/ui/catalog/ui/CatalogUiModule.kt +++ b/app-ui-catalog/src/main/java/app/k9mail/ui/catalog/di/CatalogUiModule.kt @@ -1,5 +1,6 @@ -package app.k9mail.ui.catalog.ui +package app.k9mail.ui.catalog.di +import app.k9mail.ui.catalog.ui.CatalogViewModel import org.koin.androidx.viewmodel.dsl.viewModel import org.koin.core.module.Module import org.koin.dsl.module diff --git a/app-ui-catalog/src/main/java/app/k9mail/ui/catalog/ui/CatalogContract.kt b/app-ui-catalog/src/main/java/app/k9mail/ui/catalog/ui/CatalogContract.kt index 2d52d4351..7eecd0a23 100644 --- a/app-ui-catalog/src/main/java/app/k9mail/ui/catalog/ui/CatalogContract.kt +++ b/app-ui-catalog/src/main/java/app/k9mail/ui/catalog/ui/CatalogContract.kt @@ -9,6 +9,9 @@ interface CatalogContract { ) { K9("K-9"), THUNDERBIRD("Thunderbird"), + + // Theme 2 + THEME_2_K9("K-9 (Material3)"), } enum class ThemeVariant( @@ -26,8 +29,8 @@ interface CatalogContract { ) sealed interface Event { - object OnThemeChanged : Event + data object OnThemeChanged : Event - object OnThemeVariantChanged : Event + data object OnThemeVariantChanged : Event } } diff --git a/app-ui-catalog/src/main/java/app/k9mail/ui/catalog/ui/CatalogViewModel.kt b/app-ui-catalog/src/main/java/app/k9mail/ui/catalog/ui/CatalogViewModel.kt index 1f528198d..1df977d93 100644 --- a/app-ui-catalog/src/main/java/app/k9mail/ui/catalog/ui/CatalogViewModel.kt +++ b/app-ui-catalog/src/main/java/app/k9mail/ui/catalog/ui/CatalogViewModel.kt @@ -5,10 +5,8 @@ import app.k9mail.ui.catalog.ui.CatalogContract.Event import app.k9mail.ui.catalog.ui.CatalogContract.Event.OnThemeChanged import app.k9mail.ui.catalog.ui.CatalogContract.Event.OnThemeVariantChanged import app.k9mail.ui.catalog.ui.CatalogContract.State -import app.k9mail.ui.catalog.ui.CatalogContract.Theme.K9 -import app.k9mail.ui.catalog.ui.CatalogContract.Theme.THUNDERBIRD -import app.k9mail.ui.catalog.ui.CatalogContract.ThemeVariant.DARK -import app.k9mail.ui.catalog.ui.CatalogContract.ThemeVariant.LIGHT +import app.k9mail.ui.catalog.ui.CatalogContract.Theme +import app.k9mail.ui.catalog.ui.CatalogContract.ThemeVariant import app.k9mail.ui.catalog.ui.CatalogContract.ViewModel class CatalogViewModel( @@ -17,18 +15,22 @@ class CatalogViewModel( override fun event(event: Event) { when (event) { is OnThemeChanged -> { - when (state.value.theme) { - K9 -> updateState { it.copy(theme = THUNDERBIRD) } - THUNDERBIRD -> updateState { it.copy(theme = K9) } - } + updateState { it.copy(theme = selectNextTheme(it.theme)) } } is OnThemeVariantChanged -> { when (state.value.themeVariant) { - LIGHT -> updateState { it.copy(themeVariant = DARK) } - DARK -> updateState { it.copy(themeVariant = LIGHT) } + ThemeVariant.LIGHT -> updateState { it.copy(themeVariant = ThemeVariant.DARK) } + ThemeVariant.DARK -> updateState { it.copy(themeVariant = ThemeVariant.LIGHT) } } } } } + + private fun selectNextTheme(currentTheme: Theme): Theme { + val themes = Theme.entries + val currentThemeIndex = themes.indexOf(currentTheme) + val nextThemeIndex = (currentThemeIndex + 1) % themes.size + return themes[nextThemeIndex] + } } diff --git a/app-ui-catalog/src/main/java/app/k9mail/ui/catalog/ui/common/theme/ThemeSwitch.kt b/app-ui-catalog/src/main/java/app/k9mail/ui/catalog/ui/common/theme/ThemeSwitch.kt index 5d5e8098f..883400634 100644 --- a/app-ui-catalog/src/main/java/app/k9mail/ui/catalog/ui/common/theme/ThemeSwitch.kt +++ b/app-ui-catalog/src/main/java/app/k9mail/ui/catalog/ui/common/theme/ThemeSwitch.kt @@ -3,6 +3,7 @@ package app.k9mail.ui.catalog.ui.common.theme import androidx.compose.runtime.Composable import app.k9mail.core.ui.compose.theme.K9Theme import app.k9mail.core.ui.compose.theme.ThunderbirdTheme +import app.k9mail.core.ui.compose.theme2.k9mail.K9MailTheme2 import app.k9mail.ui.catalog.ui.CatalogContract.Theme import app.k9mail.ui.catalog.ui.CatalogContract.ThemeVariant @@ -17,10 +18,16 @@ fun ThemeSwitch( themeVariant = themeVariant, content = content, ) + Theme.THUNDERBIRD -> ThunderbirdThemeSwitch( themeVariant = themeVariant, content = content, ) + + Theme.THEME_2_K9 -> K9Theme2Switch( + themeVariant = themeVariant, + content = content, + ) } } @@ -34,6 +41,7 @@ private fun K9ThemeSwitch( darkTheme = false, content = content, ) + ThemeVariant.DARK -> K9Theme( darkTheme = true, content = content, @@ -51,9 +59,28 @@ private fun ThunderbirdThemeSwitch( darkTheme = false, content = content, ) + ThemeVariant.DARK -> ThunderbirdTheme( darkTheme = true, content = content, ) } } + +@Composable +private fun K9Theme2Switch( + themeVariant: ThemeVariant, + content: @Composable () -> Unit, +) { + when (themeVariant) { + ThemeVariant.LIGHT -> K9MailTheme2( + darkTheme = false, + content = content, + ) + + ThemeVariant.DARK -> K9MailTheme2( + darkTheme = true, + content = content, + ) + } +} diff --git a/settings.gradle.kts b/settings.gradle.kts index 0d7664363..3f08adb60 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -77,6 +77,7 @@ include( ":core:ui:compose:designsystem", ":core:ui:compose:theme", ":core:ui:compose:theme2:common", + ":core:ui:compose:theme2:k9mail", ":core:ui:compose:testing", )