Add theme2 support for K9Mail to catalog app
This commit is contained in:
parent
5670de0ab2
commit
bb1c1012e1
7 changed files with 50 additions and 14 deletions
|
@ -15,6 +15,8 @@ android {
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(projects.core.ui.compose.designsystem)
|
implementation(projects.core.ui.compose.designsystem)
|
||||||
|
|
||||||
|
implementation(projects.core.ui.compose.theme2.k9mail)
|
||||||
|
|
||||||
implementation(libs.androidx.compose.material)
|
implementation(libs.androidx.compose.material)
|
||||||
implementation(libs.androidx.compose.material.icons.extended)
|
implementation(libs.androidx.compose.material.icons.extended)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package app.k9mail.ui.catalog
|
package app.k9mail.ui.catalog
|
||||||
|
|
||||||
import android.app.Application
|
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.android.ext.koin.androidContext
|
||||||
import org.koin.core.context.startKoin
|
import org.koin.core.context.startKoin
|
||||||
|
|
||||||
|
|
|
@ -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.androidx.viewmodel.dsl.viewModel
|
||||||
import org.koin.core.module.Module
|
import org.koin.core.module.Module
|
||||||
import org.koin.dsl.module
|
import org.koin.dsl.module
|
|
@ -9,6 +9,9 @@ interface CatalogContract {
|
||||||
) {
|
) {
|
||||||
K9("K-9"),
|
K9("K-9"),
|
||||||
THUNDERBIRD("Thunderbird"),
|
THUNDERBIRD("Thunderbird"),
|
||||||
|
|
||||||
|
// Theme 2
|
||||||
|
THEME_2_K9("K-9 (Material3)"),
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class ThemeVariant(
|
enum class ThemeVariant(
|
||||||
|
@ -26,8 +29,8 @@ interface CatalogContract {
|
||||||
)
|
)
|
||||||
|
|
||||||
sealed interface Event {
|
sealed interface Event {
|
||||||
object OnThemeChanged : Event
|
data object OnThemeChanged : Event
|
||||||
|
|
||||||
object OnThemeVariantChanged : Event
|
data object OnThemeVariantChanged : Event
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.OnThemeChanged
|
||||||
import app.k9mail.ui.catalog.ui.CatalogContract.Event.OnThemeVariantChanged
|
import app.k9mail.ui.catalog.ui.CatalogContract.Event.OnThemeVariantChanged
|
||||||
import app.k9mail.ui.catalog.ui.CatalogContract.State
|
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
|
||||||
import app.k9mail.ui.catalog.ui.CatalogContract.Theme.THUNDERBIRD
|
import app.k9mail.ui.catalog.ui.CatalogContract.ThemeVariant
|
||||||
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.ViewModel
|
import app.k9mail.ui.catalog.ui.CatalogContract.ViewModel
|
||||||
|
|
||||||
class CatalogViewModel(
|
class CatalogViewModel(
|
||||||
|
@ -17,18 +15,22 @@ class CatalogViewModel(
|
||||||
override fun event(event: Event) {
|
override fun event(event: Event) {
|
||||||
when (event) {
|
when (event) {
|
||||||
is OnThemeChanged -> {
|
is OnThemeChanged -> {
|
||||||
when (state.value.theme) {
|
updateState { it.copy(theme = selectNextTheme(it.theme)) }
|
||||||
K9 -> updateState { it.copy(theme = THUNDERBIRD) }
|
|
||||||
THUNDERBIRD -> updateState { it.copy(theme = K9) }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
is OnThemeVariantChanged -> {
|
is OnThemeVariantChanged -> {
|
||||||
when (state.value.themeVariant) {
|
when (state.value.themeVariant) {
|
||||||
LIGHT -> updateState { it.copy(themeVariant = DARK) }
|
ThemeVariant.LIGHT -> updateState { it.copy(themeVariant = ThemeVariant.DARK) }
|
||||||
DARK -> updateState { it.copy(themeVariant = LIGHT) }
|
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]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package app.k9mail.ui.catalog.ui.common.theme
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import app.k9mail.core.ui.compose.theme.K9Theme
|
import app.k9mail.core.ui.compose.theme.K9Theme
|
||||||
import app.k9mail.core.ui.compose.theme.ThunderbirdTheme
|
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.Theme
|
||||||
import app.k9mail.ui.catalog.ui.CatalogContract.ThemeVariant
|
import app.k9mail.ui.catalog.ui.CatalogContract.ThemeVariant
|
||||||
|
|
||||||
|
@ -17,10 +18,16 @@ fun ThemeSwitch(
|
||||||
themeVariant = themeVariant,
|
themeVariant = themeVariant,
|
||||||
content = content,
|
content = content,
|
||||||
)
|
)
|
||||||
|
|
||||||
Theme.THUNDERBIRD -> ThunderbirdThemeSwitch(
|
Theme.THUNDERBIRD -> ThunderbirdThemeSwitch(
|
||||||
themeVariant = themeVariant,
|
themeVariant = themeVariant,
|
||||||
content = content,
|
content = content,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Theme.THEME_2_K9 -> K9Theme2Switch(
|
||||||
|
themeVariant = themeVariant,
|
||||||
|
content = content,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,6 +41,7 @@ private fun K9ThemeSwitch(
|
||||||
darkTheme = false,
|
darkTheme = false,
|
||||||
content = content,
|
content = content,
|
||||||
)
|
)
|
||||||
|
|
||||||
ThemeVariant.DARK -> K9Theme(
|
ThemeVariant.DARK -> K9Theme(
|
||||||
darkTheme = true,
|
darkTheme = true,
|
||||||
content = content,
|
content = content,
|
||||||
|
@ -51,9 +59,28 @@ private fun ThunderbirdThemeSwitch(
|
||||||
darkTheme = false,
|
darkTheme = false,
|
||||||
content = content,
|
content = content,
|
||||||
)
|
)
|
||||||
|
|
||||||
ThemeVariant.DARK -> ThunderbirdTheme(
|
ThemeVariant.DARK -> ThunderbirdTheme(
|
||||||
darkTheme = true,
|
darkTheme = true,
|
||||||
content = content,
|
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,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -77,6 +77,7 @@ include(
|
||||||
":core:ui:compose:designsystem",
|
":core:ui:compose:designsystem",
|
||||||
":core:ui:compose:theme",
|
":core:ui:compose:theme",
|
||||||
":core:ui:compose:theme2:common",
|
":core:ui:compose:theme2:common",
|
||||||
|
":core:ui:compose:theme2:k9mail",
|
||||||
":core:ui:compose:testing",
|
":core:ui:compose:testing",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue