mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-16 14:07:28 +01:00
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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user