Only attempt to use light system bars at appropriate API level

This commit is contained in:
Moez Bhatti
2018-04-03 16:30:47 -04:00
parent 8d0b8500c4
commit f64365f6eb
6 changed files with 107 additions and 48 deletions
@@ -92,10 +92,25 @@ class Colors @Inject constructor(private val context: Context, private val prefs
}
})
/**
* Returns the flags to be used for the system bars. This is used for tinting the icons
* according to the colour of the system bars (light or dark)
*
* If night mode, or no dark icons supported, use light icons
*
* If night mode and only dark status icons supported, use dark status icons
*
* If night mode and all dark icons supported, use all dark icons
*/
@SuppressLint("InlinedApi")
val systemBarIcons: Observable<Int> = prefs.night.asObservable()
.map { night -> night || Build.VERSION.SDK_INT < Build.VERSION_CODES.M }
.map { lightIcons -> if (lightIcons) 0 else View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR or View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR}
.map { night ->
when {
night || Build.VERSION.SDK_INT < Build.VERSION_CODES.M -> 0
Build.VERSION.SDK_INT < Build.VERSION_CODES.O -> View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
else -> View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR or View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
}
}
.distinctUntilChanged()
val statusBar: Observable<Int> = Observables.combineLatest(prefs.night.asObservable(), prefs.black.asObservable(),
@@ -103,12 +118,25 @@ class Colors @Inject constructor(private val context: Context, private val prefs
when {
night && black -> R.color.black
night && !black -> R.color.statusBarDark
Build.VERSION.SDK_INT < Build.VERSION_CODES.M -> R.color.black
else -> R.color.statusBarLight
}
})
.map { res -> getColor(res) }
.distinctUntilChanged()
val navigationBar: Observable<Int> = Observables.combineLatest(prefs.night.asObservable(), prefs.black.asObservable(),
{ night, black ->
when {
night && black -> R.color.black
night && !black -> R.color.backgroundDark
Build.VERSION.SDK_INT < Build.VERSION_CODES.O -> R.color.black
else -> R.color.white
}
})
.map { res -> getColor(res) }
.distinctUntilChanged()
val toolbarColor: Observable<Int> = Observables.combineLatest(prefs.night.asObservable(), prefs.black.asObservable(),
{ night, black ->
when {