Draw under navbar in Android 9+

This commit is contained in:
arkon 2020-11-09 17:39:22 -05:00
parent 2351c1b426
commit 122b2b1a8e
5 changed files with 62 additions and 15 deletions

View File

@ -10,6 +10,7 @@ import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.ui.security.SecureActivityDelegate
import eu.kanade.tachiyomi.util.system.LocaleHelper
import eu.kanade.tachiyomi.util.view.edgeToEdge
import uy.kohesive.injekt.injectLazy
import eu.kanade.tachiyomi.data.preference.PreferenceValues as Values
@ -23,6 +24,15 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
@Suppress("LeakingThis")
private val secureActivityDelegate = SecureActivityDelegate(this)
private val isDarkMode: Boolean by lazy {
val themeMode = preferences.themeMode().get()
(themeMode == Values.ThemeMode.dark) ||
(
themeMode == Values.ThemeMode.system &&
(resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES)
)
}
private val lightTheme: Int by lazy {
when (preferences.themeLight().get()) {
Values.LightThemeVariant.blue -> R.style.Theme_Tachiyomi_LightBlue
@ -60,15 +70,8 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
setTheme(
when (preferences.themeMode().get()) {
Values.ThemeMode.system -> {
if (resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES) {
darkTheme
} else {
lightTheme
}
}
Values.ThemeMode.dark -> darkTheme
when {
isDarkMode -> darkTheme
else -> lightTheme
}
)
@ -76,6 +79,10 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
super.onCreate(savedInstanceState)
secureActivityDelegate.onCreate()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
window.edgeToEdge(!isDarkMode && lightTheme != R.style.Theme_Tachiyomi_LightBlue)
}
}
override fun onResume() {

View File

@ -3,13 +3,16 @@ package eu.kanade.tachiyomi.ui.main
import android.app.Activity
import android.app.SearchManager
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.view.isVisible
import androidx.core.view.marginBottom
import androidx.core.view.updateLayoutParams
import androidx.core.view.updatePadding
import androidx.preference.PreferenceDialogController
import com.bluelinelabs.conductor.Conductor
import com.bluelinelabs.conductor.Controller
@ -83,9 +86,24 @@ class MainActivity : BaseActivity<MainActivityBinding>() {
}
setContentView(binding.root)
setSupportActionBar(binding.toolbar)
// Inset paddings when drawing edge-to-edge in Android 9+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
binding.bottomNav.setOnApplyWindowInsetsListener { view, insets ->
view.updatePadding(bottom = insets.systemWindowInsetBottom)
insets
}
val initialFabBottomMargin = binding.rootFab.marginBottom
binding.rootFab.setOnApplyWindowInsetsListener { view, insets ->
view.updateLayoutParams<ViewGroup.MarginLayoutParams> {
bottomMargin = initialFabBottomMargin + insets.systemWindowInsetBottom
}
insets
}
}
tabAnimator = ViewHeightAnimator(binding.tabs, 0L)
bottomNavAnimator = ViewHeightAnimator(binding.bottomNav)

View File

@ -1,22 +1,42 @@
package eu.kanade.tachiyomi.util.view
import android.graphics.Color
import android.os.Build
import android.view.View
import android.view.Window
import androidx.annotation.RequiresApi
@RequiresApi(Build.VERSION_CODES.P)
fun Window.edgeToEdge(lightSystemUi: Boolean = false) {
decorView.systemUiVisibility = when {
// Handle light status and navigation bars programmatically to avoid duplicate themes
lightSystemUi -> {
View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR or
View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
}
else -> {
View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
}
}
navigationBarColor = Color.TRANSPARENT
}
fun Window.showBar() {
val uiFlags = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
decorView.systemUiVisibility = uiFlags
}
fun Window.hideBar() {
val uiFlags = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
View.SYSTEM_UI_FLAG_FULLSCREEN or
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
decorView.systemUiVisibility = uiFlags
}
fun Window.defaultBar() {

View File

@ -10,7 +10,8 @@
<eu.kanade.tachiyomi.widget.ElevationAppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:fitsSystemWindows="true">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"

View File

@ -3,6 +3,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical">
<com.google.android.material.appbar.AppBarLayout