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:
MajorTanya
2024-02-14 21:35:16 +01:00
committed by GitHub
parent 72f3756a3b
commit 96c236e5c3
2 changed files with 36 additions and 58 deletions

View File

@@ -12,51 +12,10 @@ interface ThemingDelegate {
companion object {
fun getThemeResIds(appTheme: AppTheme, isAmoled: Boolean): List<Int> {
val resIds = mutableListOf<Int>()
when (appTheme) {
AppTheme.MONET -> {
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
}
return buildList(2) {
add(themeResources.getOrDefault(appTheme, R.style.Theme_Tachiyomi))
if (isAmoled) add(R.style.ThemeOverlay_Tachiyomi_Amoled)
}
if (isAmoled) {
resIds += R.style.ThemeOverlay_Tachiyomi_Amoled
}
return resIds
}
}
}
@@ -68,3 +27,17 @@ class ThemingDelegateImpl : ThemingDelegate {
.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,
)