mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-07 11:17:25 +01:00
Draw under navbar in Android 9+
This commit is contained in:
parent
2351c1b426
commit
122b2b1a8e
@ -10,6 +10,7 @@ import eu.kanade.tachiyomi.R
|
|||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
import eu.kanade.tachiyomi.ui.security.SecureActivityDelegate
|
import eu.kanade.tachiyomi.ui.security.SecureActivityDelegate
|
||||||
import eu.kanade.tachiyomi.util.system.LocaleHelper
|
import eu.kanade.tachiyomi.util.system.LocaleHelper
|
||||||
|
import eu.kanade.tachiyomi.util.view.edgeToEdge
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferenceValues as Values
|
import eu.kanade.tachiyomi.data.preference.PreferenceValues as Values
|
||||||
|
|
||||||
@ -23,6 +24,15 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
|||||||
@Suppress("LeakingThis")
|
@Suppress("LeakingThis")
|
||||||
private val secureActivityDelegate = SecureActivityDelegate(this)
|
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 {
|
private val lightTheme: Int by lazy {
|
||||||
when (preferences.themeLight().get()) {
|
when (preferences.themeLight().get()) {
|
||||||
Values.LightThemeVariant.blue -> R.style.Theme_Tachiyomi_LightBlue
|
Values.LightThemeVariant.blue -> R.style.Theme_Tachiyomi_LightBlue
|
||||||
@ -60,15 +70,8 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
|||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
setTheme(
|
setTheme(
|
||||||
when (preferences.themeMode().get()) {
|
when {
|
||||||
Values.ThemeMode.system -> {
|
isDarkMode -> darkTheme
|
||||||
if (resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES) {
|
|
||||||
darkTheme
|
|
||||||
} else {
|
|
||||||
lightTheme
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Values.ThemeMode.dark -> darkTheme
|
|
||||||
else -> lightTheme
|
else -> lightTheme
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -76,6 +79,10 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
|||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
secureActivityDelegate.onCreate()
|
secureActivityDelegate.onCreate()
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||||
|
window.edgeToEdge(!isDarkMode && lightTheme != R.style.Theme_Tachiyomi_LightBlue)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
|
@ -3,13 +3,16 @@ package eu.kanade.tachiyomi.ui.main
|
|||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.app.SearchManager
|
import android.app.SearchManager
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
|
import androidx.core.view.marginBottom
|
||||||
import androidx.core.view.updateLayoutParams
|
import androidx.core.view.updateLayoutParams
|
||||||
|
import androidx.core.view.updatePadding
|
||||||
import androidx.preference.PreferenceDialogController
|
import androidx.preference.PreferenceDialogController
|
||||||
import com.bluelinelabs.conductor.Conductor
|
import com.bluelinelabs.conductor.Conductor
|
||||||
import com.bluelinelabs.conductor.Controller
|
import com.bluelinelabs.conductor.Controller
|
||||||
@ -83,9 +86,24 @@ class MainActivity : BaseActivity<MainActivityBinding>() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
|
|
||||||
setSupportActionBar(binding.toolbar)
|
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)
|
tabAnimator = ViewHeightAnimator(binding.tabs, 0L)
|
||||||
bottomNavAnimator = ViewHeightAnimator(binding.bottomNav)
|
bottomNavAnimator = ViewHeightAnimator(binding.bottomNav)
|
||||||
|
|
||||||
|
@ -1,22 +1,42 @@
|
|||||||
package eu.kanade.tachiyomi.util.view
|
package eu.kanade.tachiyomi.util.view
|
||||||
|
|
||||||
|
import android.graphics.Color
|
||||||
|
import android.os.Build
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.Window
|
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() {
|
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_HIDE_NAVIGATION or
|
||||||
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||||
decorView.systemUiVisibility = uiFlags
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Window.hideBar() {
|
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_LAYOUT_HIDE_NAVIGATION or
|
||||||
View.SYSTEM_UI_FLAG_FULLSCREEN or
|
View.SYSTEM_UI_FLAG_FULLSCREEN or
|
||||||
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or
|
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or
|
||||||
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
|
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
|
||||||
decorView.systemUiVisibility = uiFlags
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Window.defaultBar() {
|
fun Window.defaultBar() {
|
||||||
|
@ -10,7 +10,8 @@
|
|||||||
<eu.kanade.tachiyomi.widget.ElevationAppBarLayout
|
<eu.kanade.tachiyomi.widget.ElevationAppBarLayout
|
||||||
android:id="@+id/appbar"
|
android:id="@+id/appbar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content"
|
||||||
|
android:fitsSystemWindows="true">
|
||||||
|
|
||||||
<com.google.android.material.appbar.MaterialToolbar
|
<com.google.android.material.appbar.MaterialToolbar
|
||||||
android:id="@+id/toolbar"
|
android:id="@+id/toolbar"
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
android:fitsSystemWindows="true"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<com.google.android.material.appbar.AppBarLayout
|
<com.google.android.material.appbar.AppBarLayout
|
||||||
|
Loading…
Reference in New Issue
Block a user