Use correct color for reader loading indicator (#5645)

Night theme color will be used when black or gray background color is used.
This commit is contained in:
Ivan Iskandar
2021-08-07 01:22:04 +07:00
committed by GitHub
parent 478256d766
commit 7a1b6142df
7 changed files with 63 additions and 19 deletions

View File

@@ -284,3 +284,24 @@ fun Context.isTablet(): Boolean {
fun Context.isNightMode(): Boolean {
return resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES
}
/**
* Creates night mode Context depending on reader theme/background
*/
fun Context.createReaderThemeContext(readerThemeSelected: Int): Context {
val isDarkBackground = when (readerThemeSelected) {
1, 2 -> true // Black, Gray
3 -> isNightMode() // Automatic bg uses activity background by default
else -> false // White
}
val expected = if (isDarkBackground) Configuration.UI_MODE_NIGHT_YES else Configuration.UI_MODE_NIGHT_NO
if (resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK != expected) {
val overrideConfig = Configuration(resources.configuration).apply {
uiMode = (uiMode and Configuration.UI_MODE_NIGHT_MASK.inv()) or expected
}
return createConfigurationContext(overrideConfig).also {
it.theme.setTo(theme)
}
}
return this
}