From 7edc47f24e7808844232d32c71910f1d3b6b056d Mon Sep 17 00:00:00 2001 From: Jay Date: Wed, 8 Jan 2020 23:18:30 -0800 Subject: [PATCH] Fixed dark and light modes mixing on dark theme --- app/build.gradle | 2 +- .../kanade/tachiyomi/ui/main/MainActivity.kt | 16 +++++++++---- .../ui/manga/info/WebViewActivity.kt | 24 ++++++++++++------- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index d34b1850cf..10f57a958f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -185,7 +185,7 @@ dependencies { implementation "com.github.inorichi.injekt:injekt-core:65b0440" // Image library - final glide_version = '4.10.0' + final glide_version = '4.11.0' implementation "com.github.bumptech.glide:glide:$glide_version" implementation "com.github.bumptech.glide:okhttp3-integration:$glide_version" kapt "com.github.bumptech.glide:compiler:$glide_version" diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index 4ec7fbdd99..13e5b49172 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -4,6 +4,7 @@ import android.animation.ObjectAnimator import android.app.SearchManager import android.content.Intent import android.content.res.Configuration +import android.content.res.Resources import android.graphics.Color import android.graphics.Rect import android.os.Build @@ -94,17 +95,22 @@ class MainActivity : BaseActivity() { lateinit var tabAnimator: TabsAnimator + override fun getTheme(): Resources.Theme { + val theme = super.getTheme() + theme.applyStyle(when (preferences.theme()) { + 3, 6 -> R.style.Theme_Tachiyomi_Amoled + 4, 7 -> R.style.Theme_Tachiyomi_DarkBlue + else -> R.style.Theme_Tachiyomi + }, true) + return theme + } + override fun onCreate(savedInstanceState: Bundle?) { setDefaultNightMode(when (preferences.theme()) { 1 -> MODE_NIGHT_NO 2, 3, 4 -> MODE_NIGHT_YES else -> MODE_NIGHT_FOLLOW_SYSTEM }) - setTheme(when (preferences.theme()) { - 3, 6 -> R.style.Theme_Tachiyomi_Amoled - 4, 7 -> R.style.Theme_Tachiyomi_DarkBlue - else -> R.style.Theme_Tachiyomi - }) super.onCreate(savedInstanceState) // Do not let the launcher create a new activity http://stackoverflow.com/questions/16283079 diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/WebViewActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/WebViewActivity.kt index 0d70817881..2adc394afb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/WebViewActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/WebViewActivity.kt @@ -3,16 +3,19 @@ package eu.kanade.tachiyomi.ui.manga.info import android.content.Context import android.content.Intent import android.content.res.Configuration +import android.content.res.Resources import android.graphics.Bitmap import android.graphics.Color import android.os.Build import android.os.Bundle +import android.os.PersistableBundle import android.view.Menu import android.view.MenuItem import android.view.View import android.view.ViewGroup import android.webkit.WebView import android.widget.LinearLayout +import androidx.appcompat.app.AppCompatDelegate import androidx.core.graphics.ColorUtils import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferencesHelper @@ -49,12 +52,17 @@ class WebViewActivity : BaseActivity() { } } - override fun onCreate(savedInstanceState: Bundle?) { - setTheme(when (preferences.theme()) { + override fun getTheme(): Resources.Theme { + val theme = super.getTheme() + theme.applyStyle(when (preferences.theme()) { 3, 6 -> R.style.Theme_Tachiyomi_Amoled 4, 7 -> R.style.Theme_Tachiyomi_DarkBlue else -> R.style.Theme_Tachiyomi - }) + }, true) + return theme + } + + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.webview_activity) title = intent.extras?.getString(TITLE_KEY) @@ -90,9 +98,9 @@ class WebViewActivity : BaseActivity() { 0, insets.systemWindowInsetBottom ) } - window.statusBarColor = getResourceColor(R.attr.colorPrimary) content.setOnApplyWindowInsetsListener { v, insets -> + window.statusBarColor = getResourceColor(R.attr.colorPrimary) window.navigationBarColor = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { v.context.getResourceColor(android.R.attr.colorPrimary) @@ -107,12 +115,12 @@ class WebViewActivity : BaseActivity() { } v.setPadding(insets.systemWindowInsetLeft, insets.systemWindowInsetTop, insets.systemWindowInsetRight, 0) + val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK + if (Build.VERSION.SDK_INT >= 26 && currentNightMode == Configuration.UI_MODE_NIGHT_NO) { + content.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR + } insets } - val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK - if (Build.VERSION.SDK_INT >= 26 && currentNightMode == Configuration.UI_MODE_NIGHT_NO) { - content.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR - } if (bundle == null) { val source = sourceManager.get(intent.extras!!.getLong(SOURCE_KEY)) as? HttpSource ?: return