mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-10 04:37:25 +01:00
Minor refactor of theming when expressions (#396)
* Minor refactor of theming when expressions Avoids triggering detekt's CyclomaticComplexMethod warning because of too many when branches, which would happen with one more theme being added in these two locations. In TachiyomiTheme, the Monet theme is separated because it requires the current Compose context to function. The other themes do not and are delegated to a Map. * Implement requested changes - moved themeResources out of the ThemingDelegate interface - replaced single condition when with if expression
This commit is contained in:
parent
72f3756a3b
commit
96c236e5c3
@ -8,6 +8,7 @@ import androidx.compose.runtime.ReadOnlyComposable
|
|||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import eu.kanade.domain.ui.UiPreferences
|
import eu.kanade.domain.ui.UiPreferences
|
||||||
import eu.kanade.domain.ui.model.AppTheme
|
import eu.kanade.domain.ui.model.AppTheme
|
||||||
|
import eu.kanade.presentation.theme.colorscheme.BaseColorScheme
|
||||||
import eu.kanade.presentation.theme.colorscheme.GreenAppleColorScheme
|
import eu.kanade.presentation.theme.colorscheme.GreenAppleColorScheme
|
||||||
import eu.kanade.presentation.theme.colorscheme.LavenderColorScheme
|
import eu.kanade.presentation.theme.colorscheme.LavenderColorScheme
|
||||||
import eu.kanade.presentation.theme.colorscheme.MidnightDuskColorScheme
|
import eu.kanade.presentation.theme.colorscheme.MidnightDuskColorScheme
|
||||||
@ -62,23 +63,27 @@ private fun getThemeColorScheme(
|
|||||||
appTheme: AppTheme,
|
appTheme: AppTheme,
|
||||||
isAmoled: Boolean,
|
isAmoled: Boolean,
|
||||||
): ColorScheme {
|
): ColorScheme {
|
||||||
val colorScheme = when (appTheme) {
|
val colorScheme = if (appTheme == AppTheme.MONET) {
|
||||||
AppTheme.DEFAULT -> TachiyomiColorScheme
|
MonetColorScheme(LocalContext.current)
|
||||||
AppTheme.MONET -> MonetColorScheme(LocalContext.current)
|
} else {
|
||||||
AppTheme.GREEN_APPLE -> GreenAppleColorScheme
|
colorSchemes.getOrDefault(appTheme, TachiyomiColorScheme)
|
||||||
AppTheme.LAVENDER -> LavenderColorScheme
|
|
||||||
AppTheme.MIDNIGHT_DUSK -> MidnightDuskColorScheme
|
|
||||||
AppTheme.NORD -> NordColorScheme
|
|
||||||
AppTheme.STRAWBERRY_DAIQUIRI -> StrawberryColorScheme
|
|
||||||
AppTheme.TAKO -> TakoColorScheme
|
|
||||||
AppTheme.TEALTURQUOISE -> TealTurqoiseColorScheme
|
|
||||||
AppTheme.TIDAL_WAVE -> TidalWaveColorScheme
|
|
||||||
AppTheme.YINYANG -> YinYangColorScheme
|
|
||||||
AppTheme.YOTSUBA -> YotsubaColorScheme
|
|
||||||
else -> TachiyomiColorScheme
|
|
||||||
}
|
}
|
||||||
return colorScheme.getColorScheme(
|
return colorScheme.getColorScheme(
|
||||||
isSystemInDarkTheme(),
|
isSystemInDarkTheme(),
|
||||||
isAmoled,
|
isAmoled,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val colorSchemes: Map<AppTheme, BaseColorScheme> = mapOf(
|
||||||
|
AppTheme.DEFAULT to TachiyomiColorScheme,
|
||||||
|
AppTheme.GREEN_APPLE to GreenAppleColorScheme,
|
||||||
|
AppTheme.LAVENDER to LavenderColorScheme,
|
||||||
|
AppTheme.MIDNIGHT_DUSK to MidnightDuskColorScheme,
|
||||||
|
AppTheme.NORD to NordColorScheme,
|
||||||
|
AppTheme.STRAWBERRY_DAIQUIRI to StrawberryColorScheme,
|
||||||
|
AppTheme.TAKO to TakoColorScheme,
|
||||||
|
AppTheme.TEALTURQUOISE to TealTurqoiseColorScheme,
|
||||||
|
AppTheme.TIDAL_WAVE to TidalWaveColorScheme,
|
||||||
|
AppTheme.YINYANG to YinYangColorScheme,
|
||||||
|
AppTheme.YOTSUBA to YotsubaColorScheme,
|
||||||
|
)
|
||||||
|
@ -12,51 +12,10 @@ interface ThemingDelegate {
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun getThemeResIds(appTheme: AppTheme, isAmoled: Boolean): List<Int> {
|
fun getThemeResIds(appTheme: AppTheme, isAmoled: Boolean): List<Int> {
|
||||||
val resIds = mutableListOf<Int>()
|
return buildList(2) {
|
||||||
when (appTheme) {
|
add(themeResources.getOrDefault(appTheme, R.style.Theme_Tachiyomi))
|
||||||
AppTheme.MONET -> {
|
if (isAmoled) add(R.style.ThemeOverlay_Tachiyomi_Amoled)
|
||||||
resIds += R.style.Theme_Tachiyomi_Monet
|
|
||||||
}
|
|
||||||
AppTheme.GREEN_APPLE -> {
|
|
||||||
resIds += R.style.Theme_Tachiyomi_GreenApple
|
|
||||||
}
|
|
||||||
AppTheme.LAVENDER -> {
|
|
||||||
resIds += R.style.Theme_Tachiyomi_Lavender
|
|
||||||
}
|
|
||||||
AppTheme.MIDNIGHT_DUSK -> {
|
|
||||||
resIds += R.style.Theme_Tachiyomi_MidnightDusk
|
|
||||||
}
|
|
||||||
AppTheme.NORD -> {
|
|
||||||
resIds += R.style.Theme_Tachiyomi_Nord
|
|
||||||
}
|
|
||||||
AppTheme.STRAWBERRY_DAIQUIRI -> {
|
|
||||||
resIds += R.style.Theme_Tachiyomi_StrawberryDaiquiri
|
|
||||||
}
|
|
||||||
AppTheme.TAKO -> {
|
|
||||||
resIds += R.style.Theme_Tachiyomi_Tako
|
|
||||||
}
|
|
||||||
AppTheme.TEALTURQUOISE -> {
|
|
||||||
resIds += R.style.Theme_Tachiyomi_TealTurquoise
|
|
||||||
}
|
|
||||||
AppTheme.YINYANG -> {
|
|
||||||
resIds += R.style.Theme_Tachiyomi_YinYang
|
|
||||||
}
|
|
||||||
AppTheme.YOTSUBA -> {
|
|
||||||
resIds += R.style.Theme_Tachiyomi_Yotsuba
|
|
||||||
}
|
|
||||||
AppTheme.TIDAL_WAVE -> {
|
|
||||||
resIds += R.style.Theme_Tachiyomi_TidalWave
|
|
||||||
}
|
|
||||||
else -> {
|
|
||||||
resIds += R.style.Theme_Tachiyomi
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isAmoled) {
|
|
||||||
resIds += R.style.ThemeOverlay_Tachiyomi_Amoled
|
|
||||||
}
|
|
||||||
|
|
||||||
return resIds
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -68,3 +27,17 @@ class ThemingDelegateImpl : ThemingDelegate {
|
|||||||
.forEach(activity::setTheme)
|
.forEach(activity::setTheme)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val themeResources: Map<AppTheme, Int> = mapOf(
|
||||||
|
AppTheme.MONET to R.style.Theme_Tachiyomi_Monet,
|
||||||
|
AppTheme.GREEN_APPLE to R.style.Theme_Tachiyomi_GreenApple,
|
||||||
|
AppTheme.LAVENDER to R.style.Theme_Tachiyomi_Lavender,
|
||||||
|
AppTheme.MIDNIGHT_DUSK to R.style.Theme_Tachiyomi_MidnightDusk,
|
||||||
|
AppTheme.NORD to R.style.Theme_Tachiyomi_Nord,
|
||||||
|
AppTheme.STRAWBERRY_DAIQUIRI to R.style.Theme_Tachiyomi_StrawberryDaiquiri,
|
||||||
|
AppTheme.TAKO to R.style.Theme_Tachiyomi_Tako,
|
||||||
|
AppTheme.TEALTURQUOISE to R.style.Theme_Tachiyomi_TealTurquoise,
|
||||||
|
AppTheme.YINYANG to R.style.Theme_Tachiyomi_YinYang,
|
||||||
|
AppTheme.YOTSUBA to R.style.Theme_Tachiyomi_Yotsuba,
|
||||||
|
AppTheme.TIDAL_WAVE to R.style.Theme_Tachiyomi_TidalWave,
|
||||||
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user