d200437813
Hopefully PreferencesPreferenceDataStore gets to go away sometime down the line. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
34 lines
1.1 KiB
Kotlin
34 lines
1.1 KiB
Kotlin
/*
|
|
* Copyright © 2017-2019 WireGuard LLC. All Rights Reserved.
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
package com.wireguard.android.activity
|
|
|
|
import android.os.Build
|
|
import android.os.Bundle
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
import androidx.appcompat.app.AppCompatDelegate
|
|
import androidx.lifecycle.lifecycleScope
|
|
import com.wireguard.android.util.UserKnobs
|
|
import kotlinx.coroutines.flow.launchIn
|
|
import kotlinx.coroutines.flow.onEach
|
|
|
|
abstract class ThemeChangeAwareActivity : AppCompatActivity() {
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
super.onCreate(savedInstanceState)
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
|
|
UserKnobs.darkTheme.onEach {
|
|
val newMode = if (it) {
|
|
AppCompatDelegate.MODE_NIGHT_YES
|
|
} else {
|
|
AppCompatDelegate.MODE_NIGHT_NO
|
|
}
|
|
if (AppCompatDelegate.getDefaultNightMode() != newMode) {
|
|
AppCompatDelegate.setDefaultNightMode(newMode)
|
|
recreate()
|
|
}
|
|
}.launchIn(lifecycleScope)
|
|
}
|
|
}
|
|
}
|