Add theme2 support for K9Mail to catalog app

This commit is contained in:
Wolf-Martell Montwé 2024-03-06 17:39:38 +01:00
parent 5670de0ab2
commit bb1c1012e1
No known key found for this signature in database
GPG key ID: 6D45B21512ACBF72
7 changed files with 50 additions and 14 deletions

View file

@ -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)
}

View file

@ -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

View file

@ -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

View file

@ -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
}
}

View file

@ -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]
}
}

View file

@ -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,
)
}
}

View file

@ -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",
)