Add system theme setting for Android 10 (#554)

This commit is contained in:
Rafał Borcz 2019-10-16 22:27:16 +02:00 committed by Mikołaj Pich
parent b602657d55
commit ce9b12eb93
6 changed files with 40 additions and 7 deletions

View File

@ -3,6 +3,7 @@ package io.github.wulkanowy.ui.base
import android.content.pm.PackageManager.GET_ACTIVITIES import android.content.pm.PackageManager.GET_ACTIVITIES
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate import androidx.appcompat.app.AppCompatDelegate
import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO
import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES
import io.github.wulkanowy.R import io.github.wulkanowy.R
@ -22,8 +23,12 @@ class ThemeManager @Inject constructor(private val preferencesRepository: Prefer
fun applyDefaultTheme() { fun applyDefaultTheme() {
AppCompatDelegate.setDefaultNightMode( AppCompatDelegate.setDefaultNightMode(
if (preferencesRepository.appTheme == "light") MODE_NIGHT_NO when (val theme = preferencesRepository.appTheme) {
else MODE_NIGHT_YES "light" -> MODE_NIGHT_NO
"dark", "black" -> MODE_NIGHT_YES
"system" -> MODE_NIGHT_FOLLOW_SYSTEM
else -> throw IllegalArgumentException("Wrong theme: $theme")
}
) )
} }

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
<string-array name="app_theme_entries" tools:ignore="InconsistentArrays">
<item>Motyw systemu</item>
<item>Jasny</item>
<item>Ciemny</item>
<item>Czarny (AMOLED)</item>
</string-array>
</resources>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources xmlns:tools="http://schemas.android.com/tools">
<string-array name="services_interval_entries"> <string-array name="services_interval_entries">
<item>15 minut</item> <item>15 minut</item>
<item>30 minut</item> <item>30 minut</item>
@ -10,7 +10,7 @@
<item>24 godziny</item> <item>24 godziny</item>
</string-array> </string-array>
<string-array name="app_theme_entries"> <string-array name="app_theme_entries" tools:ignore="InconsistentArrays">
<item>Jasny</item> <item>Jasny</item>
<item>Ciemny</item> <item>Ciemny</item>
<item>Czarny (AMOLED)</item> <item>Czarny (AMOLED)</item>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="MissingTranslation">
<string name="pref_default_app_theme">system</string>
</resources>

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
<string-array name="app_theme_entries" tools:ignore="InconsistentArrays">
<item>System theme</item>
<item>Light</item>
<item>Dark</item>
<item>Black (AMOLED)</item>
</string-array>
<string-array name="app_theme_values" translatable="false" tools:ignore="InconsistentArrays">
<item>system</item>
<item>light</item>
<item>dark</item>
<item>black</item>
</string-array>
</resources>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources xmlns:tools="http://schemas.android.com/tools">
<string-array name="startup_tab_entries" translatable="false"> <string-array name="startup_tab_entries" translatable="false">
<item>@string/grade_title</item> <item>@string/grade_title</item>
<item>@string/attendance_title</item> <item>@string/attendance_title</item>
@ -13,12 +13,12 @@
<item>3</item> <item>3</item>
</string-array> </string-array>
<string-array name="app_theme_entries"> <string-array name="app_theme_entries" tools:ignore="InconsistentArrays">
<item>Light</item> <item>Light</item>
<item>Dark</item> <item>Dark</item>
<item>Black (AMOLED)</item> <item>Black (AMOLED)</item>
</string-array> </string-array>
<string-array name="app_theme_values" translatable="false"> <string-array name="app_theme_values" translatable="false" tools:ignore="InconsistentArrays">
<item>light</item> <item>light</item>
<item>dark</item> <item>dark</item>
<item>black</item> <item>black</item>