fix theme preference defaults (#4061)
closes #4060 Also I noticed that we had the theme defaults twice in the code so I refactored a bit so only one are still in there.
This commit is contained in:
parent
8935b554d7
commit
ff1c4a4b27
7 changed files with 21 additions and 25 deletions
|
|
@ -25,20 +25,13 @@ import androidx.annotation.AttrRes
|
|||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.core.content.res.use
|
||||
import com.google.android.material.color.MaterialColors
|
||||
import com.keylesspalace.tusky.settings.AppTheme
|
||||
|
||||
/**
|
||||
* Provides runtime compatibility to obtain theme information and re-theme views, especially where
|
||||
* the ability to do so is not supported in resource files.
|
||||
*/
|
||||
|
||||
const val THEME_NIGHT = "night"
|
||||
const val THEME_DAY = "day"
|
||||
const val THEME_BLACK = "black"
|
||||
const val THEME_AUTO = "auto"
|
||||
const val THEME_SYSTEM = "auto_system"
|
||||
const val THEME_SYSTEM_BLACK = "auto_system_black"
|
||||
const val APP_THEME_DEFAULT = THEME_SYSTEM
|
||||
|
||||
fun getDimension(context: Context, @AttrRes attribute: Int): Int {
|
||||
return context.obtainStyledAttributes(intArrayOf(attribute)).use { array ->
|
||||
array.getDimensionPixelSize(0, -1)
|
||||
|
|
@ -54,24 +47,24 @@ fun setDrawableTint(context: Context, drawable: Drawable, @AttrRes attribute: In
|
|||
|
||||
fun setAppNightMode(flavor: String?) {
|
||||
when (flavor) {
|
||||
THEME_NIGHT, THEME_BLACK -> AppCompatDelegate.setDefaultNightMode(
|
||||
AppTheme.NIGHT.value, AppTheme.BLACK.value -> AppCompatDelegate.setDefaultNightMode(
|
||||
AppCompatDelegate.MODE_NIGHT_YES
|
||||
)
|
||||
THEME_DAY -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
|
||||
THEME_AUTO -> AppCompatDelegate.setDefaultNightMode(
|
||||
AppTheme.DAY.value -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
|
||||
AppTheme.AUTO.value -> AppCompatDelegate.setDefaultNightMode(
|
||||
AppCompatDelegate.MODE_NIGHT_AUTO_TIME
|
||||
)
|
||||
THEME_SYSTEM, THEME_SYSTEM_BLACK -> AppCompatDelegate.setDefaultNightMode(
|
||||
AppTheme.AUTO_SYSTEM.value, AppTheme.AUTO_SYSTEM_BLACK.value -> AppCompatDelegate.setDefaultNightMode(
|
||||
AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
|
||||
)
|
||||
else -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
|
||||
else -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
|
||||
}
|
||||
}
|
||||
|
||||
fun isBlack(config: Configuration, theme: String?): Boolean {
|
||||
return when (theme) {
|
||||
THEME_BLACK -> true
|
||||
THEME_SYSTEM_BLACK -> when (config.uiMode and Configuration.UI_MODE_NIGHT_MASK) {
|
||||
AppTheme.BLACK.value -> true
|
||||
AppTheme.AUTO_SYSTEM_BLACK.value -> when (config.uiMode and Configuration.UI_MODE_NIGHT_MASK) {
|
||||
Configuration.UI_MODE_NIGHT_NO -> false
|
||||
Configuration.UI_MODE_NIGHT_YES -> true
|
||||
else -> false
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue