forked from upstream-mirrors/quik
#1425 - Add support for system dark mode on Android Q
This commit is contained in:
@@ -23,7 +23,6 @@ import android.app.ActivityManager
|
||||
import android.graphics.BitmapFactory
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.core.view.iterator
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import com.moez.QKSMS.R
|
||||
@@ -33,10 +32,12 @@ import com.moez.QKSMS.util.Preferences
|
||||
import com.uber.autodispose.android.lifecycle.scope
|
||||
import com.uber.autodispose.autoDisposable
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.rxkotlin.Observables
|
||||
import io.reactivex.subjects.BehaviorSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.toolbar.*
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
@@ -65,29 +66,17 @@ abstract class QkThemedActivity : QkActivity() {
|
||||
|
||||
@SuppressLint("InlinedApi")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
|
||||
val night = prefs.night.get()
|
||||
val black = prefs.black.get()
|
||||
setTheme(getActivityThemeRes(night, black))
|
||||
|
||||
setTheme(getActivityThemeRes(prefs.black.get()))
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
// When certain preferences change, we need to recreate the activity
|
||||
Observable.merge(
|
||||
listOf(prefs.night, prefs.black, prefs.textSize, prefs.systemFont).map { it.asObservable().skip(1) })
|
||||
val triggers = listOf(prefs.nightMode, prefs.night, prefs.black, prefs.textSize, prefs.systemFont)
|
||||
Observable.merge(triggers.map { it.asObservable().skip(1) })
|
||||
.debounce(400, TimeUnit.MILLISECONDS)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.autoDisposable(scope())
|
||||
.subscribe { recreate() }
|
||||
|
||||
// Set the color for the status bar icons
|
||||
// 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
|
||||
window.decorView.systemUiVisibility = 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
|
||||
}
|
||||
|
||||
// Some devices don't let you modify android.R.attr.navigationBarColor
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
window.navigationBarColor = resolveThemeColor(android.R.attr.windowBackground)
|
||||
@@ -127,10 +116,9 @@ abstract class QkThemedActivity : QkActivity() {
|
||||
/**
|
||||
* This can be overridden in case an activity does not want to use the default themes
|
||||
*/
|
||||
open fun getActivityThemeRes(night: Boolean, black: Boolean) = when {
|
||||
night && black -> R.style.AppThemeBlack
|
||||
night && !black -> R.style.AppThemeDark
|
||||
else -> R.style.AppThemeLight
|
||||
open fun getActivityThemeRes(black: Boolean) = when {
|
||||
black -> R.style.AppTheme_Black
|
||||
else -> R.style.AppTheme
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user