Fixing bottom sheets for notched phones

Starting to turn on bottom sheets now
Also general fixes on notched tablets (if those exists, I think they do?)
This commit is contained in:
Jay 2020-04-23 03:23:36 -04:00
parent 1ffe7511f2
commit e2410fafb8
9 changed files with 49 additions and 38 deletions

View File

@ -65,10 +65,7 @@ class DisplayBottomSheet(private val controller: LibraryController) : BottomShee
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
initGeneralPreferences() initGeneralPreferences()
setBottomEdge(hide_filters, activity) setBottomEdge(hide_filters, activity)
close_button.setOnClickListener { close_button.setOnClickListener { dismiss() }
dismiss()
true
}
settings_scroll_view.viewTreeObserver.addOnGlobalLayoutListener { settings_scroll_view.viewTreeObserver.addOnGlobalLayoutListener {
val isScrollable = val isScrollable =
settings_scroll_view!!.height < display_layout.height + settings_scroll_view!!.height < display_layout.height +

View File

@ -71,7 +71,8 @@ class ChaptersSortBottomSheet(controller: MangaDetailsController) : BottomSheetD
settings_scroll_view!!.height < sort_layout.height + settings_scroll_view!!.height < sort_layout.height +
settings_scroll_view.paddingTop + settings_scroll_view.paddingBottom settings_scroll_view.paddingTop + settings_scroll_view.paddingBottom
close_button.visibleIf(isScrollable) close_button.visibleIf(isScrollable)
pill.visibleIf(!isScrollable) // making the view gone somehow breaks the layout so lets make it invisible
pill.visInvisIf(!isScrollable)
} }
setOnDismissListener { setOnDismissListener {

View File

@ -3,7 +3,7 @@ package eu.kanade.tachiyomi.ui.source.browse
import android.animation.ObjectAnimator import android.animation.ObjectAnimator
import android.animation.ValueAnimator import android.animation.ValueAnimator
import android.app.Activity import android.app.Activity
import android.os.Build import android.view.ActionMode
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
@ -13,9 +13,8 @@ import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.flexibleadapter.items.IFlexible import eu.davidea.flexibleadapter.items.IFlexible
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.system.hasSideNavBar import eu.kanade.tachiyomi.util.view.RecyclerWindowInsetsListener
import eu.kanade.tachiyomi.util.view.setEdgeToEdge import eu.kanade.tachiyomi.util.view.setEdgeToEdge
import kotlinx.android.synthetic.main.source_filter_sheet.* import kotlinx.android.synthetic.main.source_filter_sheet.*
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
@ -50,20 +49,27 @@ class SourceSearchSheet(activity: Activity) :
search_btn.setOnClickListener { dismiss() } search_btn.setOnClickListener { dismiss() }
reset_btn.setOnClickListener { onResetClicked() } reset_btn.setOnClickListener { onResetClicked() }
recycler.layoutManager = androidx.recyclerview.widget.LinearLayoutManager(context)
recycler.clipToPadding = false
recycler.adapter = adapter
recycler.setHasFixedSize(true)
sheetBehavior = BottomSheetBehavior.from(view.parent as ViewGroup) sheetBehavior = BottomSheetBehavior.from(view.parent as ViewGroup)
sheetBehavior.skipCollapsed = true sheetBehavior.skipCollapsed = true
sheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED sheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED
setEdgeToEdge( setEdgeToEdge(
activity, view, 50.dpToPx activity, view, 50.dpToPx
) )
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O &&
preferences.readerTheme().getOrDefault() == 0 && recycler.layoutManager = androidx.recyclerview.widget.LinearLayoutManager(context)
!activity.window.decorView.rootWindowInsets.hasSideNavBar()) recycler.clipToPadding = false
window?.decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR recycler.adapter = adapter
recycler.setHasFixedSize(true)
recycler.setOnApplyWindowInsetsListener(RecyclerWindowInsetsListener)
// the spinner in the recycler can break the sheet's layout on change
// this is to reset it back
source_filter_sheet.post {
(source_filter_sheet.parent as View).fitsSystemWindows = false
source_filter_sheet.viewTreeObserver.addOnDrawListener {
(source_filter_sheet.parent as View).fitsSystemWindows = false
}
}
sheetBehavior.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() { sheetBehavior.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
override fun onSlide(bottomSheet: View, progress: Float) {} override fun onSlide(bottomSheet: View, progress: Float) {}
@ -96,6 +102,14 @@ class SourceSearchSheet(activity: Activity) :
}) })
} }
override fun onWindowStartingActionMode(
callback: ActionMode.Callback?,
type: Int
): ActionMode? {
(source_filter_sheet.parent as View).fitsSystemWindows = false
return super.onWindowStartingActionMode(callback, type)
}
override fun dismiss() { override fun dismiss() {
super.dismiss() super.dismiss()
if (filterChanged) if (filterChanged)

View File

@ -9,10 +9,12 @@ fun WindowInsets.getBottomGestureInsets(): Int {
} }
/** returns if device using gesture nav and supports true edge to edge */ /** returns if device using gesture nav and supports true edge to edge */
fun WindowInsets.isBottomTappable(): Boolean { fun WindowInsets.isBottomTappable() = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q &&
return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && systemWindowInsetBottom != tappableElementInsets.bottom)
systemWindowInsetBottom != tappableElementInsets.bottom)
} fun WindowInsets.hasSideInsets() = systemWindowInsetLeft > 0 || systemWindowInsetRight > 0
/** returns if device is in landscape with 2/3 button mode */ /** returns if device is in landscape with 2/3 button mode */
fun WindowInsets.hasSideNavBar(): Boolean = systemWindowInsetLeft > 0 || systemWindowInsetRight > 0 fun WindowInsets.hasSideNavBar() =
(systemWindowInsetLeft > 0 || systemWindowInsetRight > 0) && !isBottomTappable() &&
systemWindowInsetBottom == 0

View File

@ -29,7 +29,6 @@ import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.util.system.ThemeUtil import eu.kanade.tachiyomi.util.system.ThemeUtil
import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.getResourceColor
import eu.kanade.tachiyomi.util.system.hasSideNavBar
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
import kotlin.math.min import kotlin.math.min
@ -277,8 +276,6 @@ fun BottomSheetDialog.setEdgeToEdge(
setTopMargin: Int = -1 setTopMargin: Int = -1
) { ) {
window?.setBackgroundDrawable(null) window?.setBackgroundDrawable(null)
val currentNightMode =
activity.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
window?.navigationBarColor = activity.window.navigationBarColor window?.navigationBarColor = activity.window.navigationBarColor
val isLight = (activity.window?.decorView?.systemUiVisibility ?: 0) and View val isLight = (activity.window?.decorView?.systemUiVisibility ?: 0) and View
.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR == View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR .SYSTEM_UI_FLAG_LIGHT_STATUS_BAR == View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
@ -286,19 +283,17 @@ fun BottomSheetDialog.setEdgeToEdge(
window?.decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR window?.decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
window?.findViewById<View>(com.google.android.material.R.id.container)?.fitsSystemWindows = window?.findViewById<View>(com.google.android.material.R.id.container)?.fitsSystemWindows =
false false
contentView.systemUiVisibility = contentView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View
View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN // .SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
// or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
if (!activity.window.decorView.rootWindowInsets.hasSideNavBar()) val insets = activity.window.decorView.rootWindowInsets
contentView.systemUiVisibility = contentView.systemUiVisibility (contentView.parent as View).translationX = (insets.systemWindowInsetLeft - insets
.or(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) .systemWindowInsetRight).toFloat() / 2f
if (setTopMargin > 0) (contentView.parent as View).updateLayoutParams<ViewGroup.MarginLayoutParams> { if (setTopMargin > 0) (contentView.parent as View).updateLayoutParams<ViewGroup.MarginLayoutParams> {
height = height = activity.window.decorView.height - insets.systemWindowInsetTop - setTopMargin
activity.window.decorView.height - activity.window.decorView.rootWindowInsets.systemWindowInsetTop - setTopMargin
} }
else if (setTopMargin == 0) contentView.updateLayoutParams<ViewGroup.MarginLayoutParams> { else if (setTopMargin == 0) contentView.updateLayoutParams<ViewGroup.MarginLayoutParams> {
topMargin = activity.window.decorView.rootWindowInsets.systemWindowInsetTop topMargin = insets.systemWindowInsetTop
} }
contentView.requestLayout() contentView.requestLayout()
} }

View File

@ -16,6 +16,7 @@
style="@style/BottomSheetDialogTheme" style="@style/BottomSheetDialogTheme"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:orientation="vertical" android:orientation="vertical"
android:paddingTop="12dp" android:paddingTop="12dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"> app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">

View File

@ -3,6 +3,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/display_bottom_sheet" android:id="@+id/display_bottom_sheet"
android:layout_width="match_parent" android:layout_width="match_parent"
android:background="@drawable/bottom_sheet_rounded_background"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<androidx.core.widget.NestedScrollView <androidx.core.widget.NestedScrollView
@ -15,7 +16,7 @@
style="@style/BottomSheetDialogTheme" style="@style/BottomSheetDialogTheme"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@drawable/bottom_sheet_rounded_background" android:background="@android:color/transparent"
android:orientation="vertical" android:orientation="vertical"
android:paddingTop="12dp" android:paddingTop="12dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"> app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">

View File

@ -2,19 +2,18 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/source_filter_sheet"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@drawable/bottom_sheet_rounded_background" android:background="@drawable/bottom_sheet_rounded_background"
android:backgroundTint="?android:attr/colorBackground" android:backgroundTint="?android:attr/colorBackground">
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler" android:id="@+id/recycler"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize" android:layout_marginTop="?attr/actionBarSize"
android:clipToPadding="false" android:clipToPadding="false" />
android:fitsSystemWindows="true" />
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/title_layout" android:id="@+id/title_layout"

View File

@ -11,5 +11,6 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:paddingTop="5dp" android:paddingTop="5dp"
android:clipToPadding="false"
tools:listitem="@layout/track_item" /> tools:listitem="@layout/track_item" />
</FrameLayout> </FrameLayout>