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)
initGeneralPreferences()
setBottomEdge(hide_filters, activity)
close_button.setOnClickListener {
dismiss()
true
}
close_button.setOnClickListener { dismiss() }
settings_scroll_view.viewTreeObserver.addOnGlobalLayoutListener {
val isScrollable =
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.paddingTop + settings_scroll_view.paddingBottom
close_button.visibleIf(isScrollable)
pill.visibleIf(!isScrollable)
// making the view gone somehow breaks the layout so lets make it invisible
pill.visInvisIf(!isScrollable)
}
setOnDismissListener {

View File

@ -3,7 +3,7 @@ package eu.kanade.tachiyomi.ui.source.browse
import android.animation.ObjectAnimator
import android.animation.ValueAnimator
import android.app.Activity
import android.os.Build
import android.view.ActionMode
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
@ -13,9 +13,8 @@ import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.flexibleadapter.items.IFlexible
import eu.kanade.tachiyomi.R
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.hasSideNavBar
import eu.kanade.tachiyomi.util.view.RecyclerWindowInsetsListener
import eu.kanade.tachiyomi.util.view.setEdgeToEdge
import kotlinx.android.synthetic.main.source_filter_sheet.*
import uy.kohesive.injekt.injectLazy
@ -50,20 +49,27 @@ class SourceSearchSheet(activity: Activity) :
search_btn.setOnClickListener { dismiss() }
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.skipCollapsed = true
sheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED
setEdgeToEdge(
activity, view, 50.dpToPx
)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O &&
preferences.readerTheme().getOrDefault() == 0 &&
!activity.window.decorView.rootWindowInsets.hasSideNavBar())
window?.decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
recycler.layoutManager = androidx.recyclerview.widget.LinearLayoutManager(context)
recycler.clipToPadding = false
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() {
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() {
super.dismiss()
if (filterChanged)

View File

@ -9,10 +9,12 @@ fun WindowInsets.getBottomGestureInsets(): Int {
}
/** returns if device using gesture nav and supports true edge to edge */
fun WindowInsets.isBottomTappable(): Boolean {
return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q &&
fun WindowInsets.isBottomTappable() = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q &&
systemWindowInsetBottom != tappableElementInsets.bottom)
}
fun WindowInsets.hasSideInsets() = systemWindowInsetLeft > 0 || systemWindowInsetRight > 0
/** 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.util.system.ThemeUtil
import eu.kanade.tachiyomi.util.system.getResourceColor
import eu.kanade.tachiyomi.util.system.hasSideNavBar
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import kotlin.math.min
@ -277,8 +276,6 @@ fun BottomSheetDialog.setEdgeToEdge(
setTopMargin: Int = -1
) {
window?.setBackgroundDrawable(null)
val currentNightMode =
activity.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
window?.navigationBarColor = activity.window.navigationBarColor
val isLight = (activity.window?.decorView?.systemUiVisibility ?: 0) and View
.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?.findViewById<View>(com.google.android.material.R.id.container)?.fitsSystemWindows =
false
contentView.systemUiVisibility =
View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN //
// or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
contentView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View
.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
if (!activity.window.decorView.rootWindowInsets.hasSideNavBar())
contentView.systemUiVisibility = contentView.systemUiVisibility
.or(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)
val insets = activity.window.decorView.rootWindowInsets
(contentView.parent as View).translationX = (insets.systemWindowInsetLeft - insets
.systemWindowInsetRight).toFloat() / 2f
if (setTopMargin > 0) (contentView.parent as View).updateLayoutParams<ViewGroup.MarginLayoutParams> {
height =
activity.window.decorView.height - activity.window.decorView.rootWindowInsets.systemWindowInsetTop - setTopMargin
height = activity.window.decorView.height - insets.systemWindowInsetTop - setTopMargin
}
else if (setTopMargin == 0) contentView.updateLayoutParams<ViewGroup.MarginLayoutParams> {
topMargin = activity.window.decorView.rootWindowInsets.systemWindowInsetTop
topMargin = insets.systemWindowInsetTop
}
contentView.requestLayout()
}

View File

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

View File

@ -3,6 +3,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/display_bottom_sheet"
android:layout_width="match_parent"
android:background="@drawable/bottom_sheet_rounded_background"
android:layout_height="wrap_content">
<androidx.core.widget.NestedScrollView
@ -15,7 +16,7 @@
style="@style/BottomSheetDialogTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bottom_sheet_rounded_background"
android:background="@android:color/transparent"
android:orientation="vertical"
android:paddingTop="12dp"
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"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/source_filter_sheet"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bottom_sheet_rounded_background"
android:backgroundTint="?android:attr/colorBackground"
android:orientation="vertical">
android:backgroundTint="?android:attr/colorBackground">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"
android:clipToPadding="false"
android:fitsSystemWindows="true" />
android:clipToPadding="false" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/title_layout"

View File

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