Fix AMOLED theme
This commit is contained in:
committed by
Koitharu
parent
f9cee7a8f5
commit
71f205ca8b
@@ -1,5 +1,6 @@
|
||||
package org.koitharu.kotatsu.base.ui
|
||||
|
||||
import android.graphics.Color
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.view.KeyEvent
|
||||
@@ -57,6 +58,9 @@ abstract class BaseActivity<B : ViewBinding> : AppCompatActivity(), OnApplyWindo
|
||||
this.binding = binding
|
||||
super.setContentView(binding.root)
|
||||
val toolbar = (binding.root.findViewById<View>(R.id.toolbar) as? Toolbar)
|
||||
if (get<AppSettings>().isAmoledTheme) {
|
||||
toolbar?.setBackgroundColor(Color.BLACK)
|
||||
}
|
||||
toolbar?.let(this::setSupportActionBar)
|
||||
ViewCompat.setOnApplyWindowInsetsListener(binding.root, this)
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.ViewGroup.MarginLayoutParams
|
||||
import androidx.appcompat.app.ActionBarDrawerToggle
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.core.content.ContextCompat
|
||||
@@ -30,6 +30,7 @@ import org.koitharu.kotatsu.base.ui.BaseActivity
|
||||
import org.koitharu.kotatsu.core.model.Manga
|
||||
import org.koitharu.kotatsu.core.model.MangaSource
|
||||
import org.koitharu.kotatsu.core.prefs.AppSection
|
||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||
import org.koitharu.kotatsu.databinding.ActivityMainBinding
|
||||
import org.koitharu.kotatsu.databinding.NavigationHeaderBinding
|
||||
import org.koitharu.kotatsu.details.ui.DetailsActivity
|
||||
@@ -86,6 +87,13 @@ class MainActivity : BaseActivity<ActivityMainBinding>(),
|
||||
binding.drawer.addDrawerListener(drawerToggle)
|
||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
|
||||
if (get<AppSettings>().isAmoledTheme) {
|
||||
binding.appbar.setBackgroundColor(Color.BLACK)
|
||||
binding.toolbar.setBackgroundColor(ContextCompat.getColor(this, R.color.color_background))
|
||||
} else {
|
||||
binding.toolbar.setBackgroundColor(ContextCompat.getColor(this, R.color.color_surface))
|
||||
}
|
||||
|
||||
with(binding.searchView) {
|
||||
onFocusChangeListener = this@MainActivity
|
||||
searchSuggestionListener = this@MainActivity
|
||||
@@ -205,17 +213,15 @@ class MainActivity : BaseActivity<ActivityMainBinding>(),
|
||||
}
|
||||
|
||||
override fun onWindowInsetsChanged(insets: Insets) {
|
||||
binding.toolbarCard.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
binding.toolbarCard.updateLayoutParams<MarginLayoutParams> {
|
||||
topMargin = insets.top + resources.resolveDp(8)
|
||||
leftMargin = insets.left + resources.resolveDp(16)
|
||||
rightMargin = insets.right + resources.resolveDp(16)
|
||||
}
|
||||
binding.fab.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
binding.fab.updateLayoutParams<MarginLayoutParams> {
|
||||
bottomMargin = insets.bottom + topMargin
|
||||
leftMargin = insets.left + topMargin
|
||||
rightMargin = insets.right + topMargin
|
||||
}
|
||||
binding.container.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
binding.container.updateLayoutParams<MarginLayoutParams> {
|
||||
topMargin = -(binding.appbar.measureHeight())
|
||||
}
|
||||
}
|
||||
@@ -337,19 +343,40 @@ class MainActivity : BaseActivity<ActivityMainBinding>(),
|
||||
private fun onSearchOpened() {
|
||||
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/dark
|
||||
binding.appbar.setBackgroundColor(ContextCompat.getColor(this, R.color.color_on_secondary))
|
||||
binding.toolbarCard.cardElevation = 0f
|
||||
// Avoiding shadows on the sides if the color is transparent, so we make the AppBarLayout white/grey/black
|
||||
if (get<AppSettings>().isAmoledTheme) {
|
||||
binding.toolbar.setBackgroundColor(Color.BLACK)
|
||||
} else {
|
||||
binding.appbar.setBackgroundColor(ContextCompat.getColor(this, R.color.color_surface))
|
||||
}
|
||||
binding.toolbarCard.apply {
|
||||
cardElevation = 0f
|
||||
// Remove margin
|
||||
updateLayoutParams<MarginLayoutParams> {
|
||||
leftMargin = 0
|
||||
rightMargin = 0
|
||||
}
|
||||
|
||||
}
|
||||
binding.appbar.elevation = searchViewElevation
|
||||
}
|
||||
|
||||
private fun onSearchClosed() {
|
||||
binding.drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED)
|
||||
drawerToggle.isDrawerIndicatorEnabled = true
|
||||
if (get<AppSettings>().isAmoledTheme) {
|
||||
binding.toolbar.setBackgroundColor(ContextCompat.getColor(this, R.color.color_background))
|
||||
}
|
||||
// Returning transparent color
|
||||
binding.appbar.setBackgroundColor(Color.TRANSPARENT)
|
||||
binding.appbar.elevation = 0f
|
||||
binding.toolbarCard.cardElevation = searchViewElevation
|
||||
binding.toolbarCard.apply {
|
||||
cardElevation = searchViewElevation
|
||||
updateLayoutParams<MarginLayoutParams> {
|
||||
leftMargin = resources.resolveDp(16)
|
||||
rightMargin = resources.resolveDp(16)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun onFirstStart() {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item>
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="?colorSurface" />
|
||||
<solid android:color="?android:attr/colorBackground" />
|
||||
</shape>
|
||||
</item>
|
||||
<item
|
||||
|
||||
@@ -6,13 +6,13 @@
|
||||
<color name="color_on_secondary">@android:color/black</color>
|
||||
|
||||
<color name="color_control_light">#2EFFFFFF</color> <!-- 18% white -->
|
||||
<color name="color_surface_secondary">#2a2b2e</color>
|
||||
<color name="color_surface">#272727</color>
|
||||
<color name="color_background">#121212</color>
|
||||
|
||||
<!-- Scrim colors -->
|
||||
<color name="system_ui_scrim_light">#2EFFFFFF</color> <!-- 18% white -->
|
||||
<color name="system_ui_scrim_black">#B3000000</color> <!-- 70% black -->
|
||||
|
||||
<!-- In dark mode without light status bar we can use transparent -->
|
||||
<color name="system_ui_scrim_dark">#B3121212</color> <!-- 70% grey -->
|
||||
<color name="status_bar_scrim">@color/system_ui_scrim_dark</color>
|
||||
|
||||
<!-- Other colors with light mode alternatives -->
|
||||
<color name="list_divider">#1fffffff</color>
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
<resources>
|
||||
|
||||
<style name="AppTheme.AMOLED">
|
||||
<item name="android:windowBackground">@android:color/black</item>
|
||||
<item name="android:colorBackground">@android:color/black</item>
|
||||
<item name="colorSurface">@android:color/black</item>
|
||||
<item name="android:statusBarColor">@color/system_ui_scrim_amoled</item>
|
||||
</style>
|
||||
|
||||
<style name="ThemeOverlay.Kotatsu" parent="ThemeOverlay.MaterialComponents.Dark">
|
||||
|
||||
5
app/src/main/res/values-notnight-v23/colors.xml
Normal file
5
app/src/main/res/values-notnight-v23/colors.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<!-- We use a light scrim on API 23+ since we use a light status bar -->
|
||||
<color name="status_bar_scrim">@color/system_ui_scrim_light</color>
|
||||
</resources>
|
||||
@@ -6,17 +6,25 @@
|
||||
<color name="color_on_secondary">@android:color/white</color>
|
||||
|
||||
<color name="color_control_light">#39000000</color>
|
||||
<color name="color_surface_secondary">#FFFFFF</color>
|
||||
<color name="color_surface">#FFFFFF</color>
|
||||
<color name="color_background">#FFFFFF</color>
|
||||
|
||||
<!-- Scrim colors -->
|
||||
<color name="system_ui_scrim_light">#B3FFFFFF</color> <!-- 70% white -->
|
||||
<color name="system_ui_scrim_black">#40000000</color> <!-- 25% black -->
|
||||
<color name="nav_bar_scrim">@color/system_ui_scrim_black</color>
|
||||
<color name="system_ui_scrim_dark">#40272727</color> <!-- 25% grey -->
|
||||
|
||||
<!-- We use a dark scrim by default since light status is API 23+ -->
|
||||
<color name="status_bar_scrim">@color/system_ui_scrim_dark</color>
|
||||
<!-- We use a dark scrim by default since light nav bar is API 27+ -->
|
||||
<color name="nav_bar_scrim">@color/system_ui_scrim_dark</color>
|
||||
|
||||
<!-- Other colors with dark mode alternatives -->
|
||||
<color name="list_divider">#1f000000</color>
|
||||
<color name="error">#B00020</color>
|
||||
|
||||
<!-- AMOLED colors -->
|
||||
<color name="system_ui_scrim_amoled">#B3000000</color>
|
||||
|
||||
<!-- Other Colors -->
|
||||
|
||||
<color name="blue_primary">#1976D2</color>
|
||||
@@ -26,5 +34,6 @@
|
||||
<color name="grey_dark">#212121</color>
|
||||
<color name="dim">#99000000</color>
|
||||
<color name="shadow">#99000000</color>
|
||||
<color name="transparent">#00FFFFFF</color>
|
||||
|
||||
</resources>
|
||||
@@ -9,11 +9,10 @@
|
||||
<item name="colorSecondary">?attr/colorPrimary</item>
|
||||
<item name="colorOnSecondary">@color/color_on_secondary</item>
|
||||
<item name="colorControlLight">@color/color_control_light</item>
|
||||
<item name="colorSurfaceSecondary">@color/color_surface_secondary</item>
|
||||
|
||||
<!-- Window decor -->
|
||||
<item name="android:windowLightStatusBar" tools:targetApi="m">@bool/use_light_status</item>
|
||||
<item name="android:statusBarColor">@color/nav_bar_scrim</item>
|
||||
<item name="android:statusBarColor">@color/status_bar_scrim</item>
|
||||
<item name="android:windowLightNavigationBar" tools:targetApi="o_mr1">@bool/use_light_navigation</item>
|
||||
<item name="android:navigationBarColor">@color/nav_bar_scrim</item>
|
||||
<item name="popupTheme">@style/ThemeOverlay.Kotatsu</item>
|
||||
@@ -29,9 +28,6 @@
|
||||
<item name="textAppearanceButton">@style/TextAppearance.Kotatsu.Button</item>
|
||||
<item name="textAppearanceListItem">@style/TextAppearance.Kotatsu.ListPrimary</item>
|
||||
|
||||
<!-- Custom theme attrs -->
|
||||
<item name="navigationBarDividerColor">?attr/colorControlLight</item>
|
||||
|
||||
<!-- ActionMode attrs -->
|
||||
<item name="android:windowActionModeOverlay">true</item>
|
||||
<item name="windowActionModeOverlay">true</item>
|
||||
|
||||
Reference in New Issue
Block a user