Use more correct detection of dark AMOLED theme

This commit is contained in:
Zakhar Timoshenko
2021-09-13 18:28:29 +03:00
committed by Koitharu
parent 203608e9fd
commit 174c6649e0
3 changed files with 9 additions and 3 deletions

View File

@@ -1,5 +1,6 @@
package org.koitharu.kotatsu.base.ui
import android.content.res.Configuration
import android.os.Build
import android.os.Bundle
import android.view.KeyEvent
@@ -101,6 +102,12 @@ abstract class BaseActivity<B : ViewBinding> : AppCompatActivity(), OnApplyWindo
(findViewById<View>(R.id.toolbar) as? Toolbar)?.let(this::setSupportActionBar)
}
protected fun isDarkAmoledTheme(): Boolean {
val uiMode = resources.configuration.uiMode
val isNight = uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES
return isNight && get<AppSettings>().isAmoledTheme
}
override fun onSupportActionModeStarted(mode: ActionMode) {
super.onSupportActionModeStarted(mode)
val insets = ViewCompat.getRootWindowInsets(binding.root)

View File

@@ -345,7 +345,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>(),
binding.drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED)
drawerToggle.isDrawerIndicatorEnabled = false
// Avoiding shadows on the sides if the color is transparent, so we make the AppBarLayout white/grey/black
if (get<AppSettings>().isAmoledTheme && get<AppSettings>().theme == AppCompatDelegate.MODE_NIGHT_YES) {
if (isDarkAmoledTheme()) {
binding.toolbar.setBackgroundColor(Color.BLACK)
} else {
binding.appbar.setBackgroundColor(ContextCompat.getColor(this, R.color.color_surface))
@@ -365,7 +365,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>(),
private fun onSearchClosed() {
binding.drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED)
drawerToggle.isDrawerIndicatorEnabled = true
if (get<AppSettings>().isAmoledTheme) {
if (isDarkAmoledTheme()) {
binding.toolbar.setBackgroundColor(ContextCompat.getColor(this, R.color.color_background))
}
// Returning transparent color

View File

@@ -34,6 +34,5 @@
<color name="grey_dark">#212121</color>
<color name="dim">#99000000</color>
<color name="shadow">#99000000</color>
<color name="transparent">#00FFFFFF</color>
</resources>