Use more correct detection of dark AMOLED theme
This commit is contained in:
committed by
Koitharu
parent
203608e9fd
commit
174c6649e0
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user