Apply default night mode earlier (#5593)

This commit is contained in:
Ivan Iskandar 2021-07-24 22:14:25 +07:00 committed by GitHub
parent 356cd4ef52
commit c42d517f6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 20 deletions

View File

@ -9,6 +9,7 @@ import android.content.Intent
import android.content.IntentFilter
import android.os.Build
import android.webkit.WebView
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.app.NotificationManagerCompat
import androidx.core.content.getSystemService
import androidx.lifecycle.Lifecycle
@ -25,7 +26,9 @@ import eu.kanade.tachiyomi.data.coil.ByteBufferFetcher
import eu.kanade.tachiyomi.data.coil.MangaCoverFetcher
import eu.kanade.tachiyomi.data.coil.TachiyomiImageDecoder
import eu.kanade.tachiyomi.data.notification.Notifications
import eu.kanade.tachiyomi.data.preference.PreferenceValues
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.asImmediateFlow
import eu.kanade.tachiyomi.network.NetworkHelper
import eu.kanade.tachiyomi.ui.security.SecureActivityDelegate
import eu.kanade.tachiyomi.util.system.notification
@ -96,6 +99,17 @@ open class App : Application(), LifecycleObserver, ImageLoaderFactory {
}
}
.launchIn(ProcessLifecycleOwner.get().lifecycleScope)
preferences.themeMode()
.asImmediateFlow {
AppCompatDelegate.setDefaultNightMode(
when (it) {
PreferenceValues.ThemeMode.light -> AppCompatDelegate.MODE_NIGHT_NO
PreferenceValues.ThemeMode.dark -> AppCompatDelegate.MODE_NIGHT_YES
PreferenceValues.ThemeMode.system -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
}
)
}.launchIn(ProcessLifecycleOwner.get().lifecycleScope)
}
override fun attachBaseContext(base: Context) {

View File

@ -3,7 +3,6 @@ package eu.kanade.tachiyomi.ui.base.activity
import android.content.Context
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.lifecycle.lifecycleScope
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferenceValues
@ -25,7 +24,7 @@ abstract class BaseThemedActivity : AppCompatActivity() {
}
override fun onCreate(savedInstanceState: Bundle?) {
applyThemePreferences(preferences)
applyAppTheme(preferences)
Injekt.get<PreferencesHelper>().incognitoMode()
.asImmediateFlow {
@ -37,7 +36,7 @@ abstract class BaseThemedActivity : AppCompatActivity() {
}
companion object {
fun AppCompatActivity.applyThemePreferences(preferences: PreferencesHelper) {
fun AppCompatActivity.applyAppTheme(preferences: PreferencesHelper) {
val resIds = mutableListOf<Int>()
when (preferences.appTheme().get()) {
PreferenceValues.AppTheme.MONET -> {
@ -77,16 +76,6 @@ abstract class BaseThemedActivity : AppCompatActivity() {
resIds.forEach {
setTheme(it)
}
lifecycleScope.launchWhenCreated {
AppCompatDelegate.setDefaultNightMode(
when (preferences.themeMode().get()) {
PreferenceValues.ThemeMode.light -> AppCompatDelegate.MODE_NIGHT_NO
PreferenceValues.ThemeMode.dark -> AppCompatDelegate.MODE_NIGHT_YES
PreferenceValues.ThemeMode.system -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
}
)
}
}
}
}

View File

@ -46,7 +46,7 @@ import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.toggle
import eu.kanade.tachiyomi.databinding.ReaderActivityBinding
import eu.kanade.tachiyomi.ui.base.activity.BaseRxActivity
import eu.kanade.tachiyomi.ui.base.activity.BaseThemedActivity.Companion.applyThemePreferences
import eu.kanade.tachiyomi.ui.base.activity.BaseThemedActivity.Companion.applyAppTheme
import eu.kanade.tachiyomi.ui.main.MainActivity
import eu.kanade.tachiyomi.ui.manga.MangaController
import eu.kanade.tachiyomi.ui.reader.ReaderPresenter.SetAsCoverResult.AddToLibraryFirst
@ -141,7 +141,7 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
* Called when the activity is created. Initializes the presenter and configuration.
*/
override fun onCreate(savedInstanceState: Bundle?) {
applyThemePreferences(preferences)
applyAppTheme(preferences)
super.onCreate(savedInstanceState)
binding = ReaderActivityBinding.inflate(layoutInflater)

View File

@ -112,11 +112,6 @@ class SettingsGeneralController : SettingsController() {
}
summary = "%s"
onChange {
activity?.recreate()
true
}
}
listPreference {
key = Keys.appTheme