File tree Expand file tree Collapse file tree
tachiyomi/ui/base/delegate Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import tachiyomi.i18n.aniyomi.AYMR
66
77enum class AppTheme (val titleRes : StringResource ? ) {
88 DEFAULT (MR .strings.label_default),
9+ CUSTOM (null ),
910 MONET (MR .strings.theme_monet),
1011 CLOUDFLARE (AYMR .strings.theme_cloudflare),
1112 COTTONCANDY (AYMR .strings.theme_cottoncandy),
Original file line number Diff line number Diff line change @@ -6,14 +6,15 @@ enum class ThemeMode {
66 LIGHT ,
77 DARK ,
88 SYSTEM ,
9+ CUSTOM ,
910}
1011
1112fun setAppCompatDelegateThemeMode (themeMode : ThemeMode ) {
12- AppCompatDelegate .setDefaultNightMode(
13- when (themeMode) {
14- ThemeMode . LIGHT -> AppCompatDelegate . MODE_NIGHT_NO
15- ThemeMode . DARK -> AppCompatDelegate . MODE_NIGHT_YES
16- ThemeMode .SYSTEM -> AppCompatDelegate .MODE_NIGHT_FOLLOW_SYSTEM
17- },
18- )
13+ AppCompatDelegate .setDefaultNightMode(themeMode.toAppCompatDelegateMode())
14+ }
15+
16+ fun ThemeMode. toAppCompatDelegateMode (): Int = when ( this ) {
17+ ThemeMode .LIGHT -> AppCompatDelegate .MODE_NIGHT_NO
18+ ThemeMode . DARK -> AppCompatDelegate . MODE_NIGHT_YES
19+ ThemeMode . SYSTEM , ThemeMode . CUSTOM -> AppCompatDelegate . MODE_NIGHT_FOLLOW_SYSTEM
1920}
Original file line number Diff line number Diff line change @@ -103,6 +103,7 @@ val playerRippleConfiguration
103103
104104private val colorSchemes: Map <AppTheme , BaseColorScheme > = mapOf (
105105 AppTheme .DEFAULT to TachiyomiColorScheme ,
106+ AppTheme .CUSTOM to TachiyomiColorScheme ,
106107 AppTheme .CLOUDFLARE to CloudflareColorScheme ,
107108 AppTheme .COTTONCANDY to CottoncandyColorScheme ,
108109 AppTheme .DOOM to DoomColorScheme ,
Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ class ThemingDelegateImpl : ThemingDelegate {
3232}
3333
3434private val themeResources: Map <AppTheme , Int > = mapOf (
35+ AppTheme .CUSTOM to R .style.Theme_Tachiyomi ,
3536 AppTheme .MONET to R .style.Theme_Tachiyomi_Monet ,
3637 AppTheme .COTTONCANDY to R .style.Theme_Tachiyomi_CottonCandy ,
3738 AppTheme .GREEN_APPLE to R .style.Theme_Tachiyomi_GreenApple ,
Original file line number Diff line number Diff line change @@ -123,7 +123,7 @@ fun Context.createReaderThemeContext(): Context {
123123 val isDarkBackground = when (readerPreferences.readerTheme().get()) {
124124 1 , 2 -> true // Black, Gray
125125 3 -> when (themeMode) { // Automatic bg uses activity background by default
126- ThemeMode .SYSTEM -> applicationContext.isNightMode()
126+ ThemeMode .SYSTEM , ThemeMode . CUSTOM -> applicationContext.isNightMode()
127127 else -> themeMode == ThemeMode .DARK
128128 }
129129 else -> false // White
Original file line number Diff line number Diff line change 1+ package eu.kanade.domain.ui.model
2+
3+ import androidx.appcompat.app.AppCompatDelegate
4+ import org.junit.jupiter.api.Assertions.assertEquals
5+ import org.junit.jupiter.api.Test
6+
7+ class ThemeModeTest {
8+
9+ @Test
10+ fun `light mode maps to MODE_NIGHT_NO` () {
11+ assertEquals(AppCompatDelegate .MODE_NIGHT_NO , ThemeMode .LIGHT .toAppCompatDelegateMode())
12+ }
13+
14+ @Test
15+ fun `dark mode maps to MODE_NIGHT_YES` () {
16+ assertEquals(AppCompatDelegate .MODE_NIGHT_YES , ThemeMode .DARK .toAppCompatDelegateMode())
17+ }
18+
19+ @Test
20+ fun `system mode maps to MODE_NIGHT_FOLLOW_SYSTEM` () {
21+ assertEquals(AppCompatDelegate .MODE_NIGHT_FOLLOW_SYSTEM , ThemeMode .SYSTEM .toAppCompatDelegateMode())
22+ }
23+
24+ @Test
25+ fun `custom mode maps to MODE_NIGHT_FOLLOW_SYSTEM` () {
26+ assertEquals(AppCompatDelegate .MODE_NIGHT_FOLLOW_SYSTEM , ThemeMode .CUSTOM .toAppCompatDelegateMode())
27+ }
28+ }
Original file line number Diff line number Diff line change 1+ package eu.kanade.tachiyomi.ui.base.delegate
2+
3+ import eu.kanade.domain.ui.model.AppTheme
4+ import eu.kanade.tachiyomi.R
5+ import org.junit.jupiter.api.Assertions.assertEquals
6+ import org.junit.jupiter.api.Test
7+
8+ class ThemingDelegateTest {
9+
10+ @Test
11+ fun `custom app theme resolves to base tachiyomi style` () {
12+ val resIds = ThemingDelegate .getThemeResIds(
13+ appTheme = AppTheme .CUSTOM ,
14+ isAmoled = false ,
15+ )
16+
17+ assertEquals(listOf (R .style.Theme_Tachiyomi ), resIds)
18+ }
19+ }
You can’t perform that action at this time.
0 commit comments