From e2410fafb8484aa5f3856bac209aebc5f43cd73d Mon Sep 17 00:00:00 2001 From: Jay Date: Thu, 23 Apr 2020 03:23:36 -0400 Subject: [PATCH] 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?) --- .../ui/library/DisplayBottomSheet.kt | 5 +-- .../manga/chapter/ChaptersSortBottomSheet.kt | 3 +- .../ui/source/browse/SourceSearchSheet.kt | 36 +++++++++++++------ .../util/system/WindowInsetsExtensions.kt | 12 ++++--- .../tachiyomi/util/view/ViewExtensions.kt | 19 ++++------ .../res/layout/chapter_sort_bottom_sheet.xml | 1 + .../main/res/layout/display_bottom_sheet.xml | 3 +- .../main/res/layout/source_filter_sheet.xml | 7 ++-- .../main/res/layout/tracking_bottom_sheet.xml | 1 + 9 files changed, 49 insertions(+), 38 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/DisplayBottomSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/DisplayBottomSheet.kt index b8f54d0c3f..5a38e4e917 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/DisplayBottomSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/DisplayBottomSheet.kt @@ -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 + diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersSortBottomSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersSortBottomSheet.kt index 77aa0b415f..05c1fb7c4c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersSortBottomSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersSortBottomSheet.kt @@ -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 { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/SourceSearchSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/SourceSearchSheet.kt index 02e1e3f405..2232a72405 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/SourceSearchSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/SourceSearchSheet.kt @@ -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) diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/WindowInsetsExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/WindowInsetsExtensions.kt index 128999a794..52d582837e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/WindowInsetsExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/WindowInsetsExtensions.kt @@ -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 && - systemWindowInsetBottom != tappableElementInsets.bottom) -} +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 diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt index 4b572a6193..cb5402972a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt @@ -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(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 { - 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 { - topMargin = activity.window.decorView.rootWindowInsets.systemWindowInsetTop + topMargin = insets.systemWindowInsetTop } contentView.requestLayout() } diff --git a/app/src/main/res/layout/chapter_sort_bottom_sheet.xml b/app/src/main/res/layout/chapter_sort_bottom_sheet.xml index 3b49719aea..87e7f31128 100644 --- a/app/src/main/res/layout/chapter_sort_bottom_sheet.xml +++ b/app/src/main/res/layout/chapter_sort_bottom_sheet.xml @@ -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"> diff --git a/app/src/main/res/layout/display_bottom_sheet.xml b/app/src/main/res/layout/display_bottom_sheet.xml index 46272cbba8..4429aa4759 100644 --- a/app/src/main/res/layout/display_bottom_sheet.xml +++ b/app/src/main/res/layout/display_bottom_sheet.xml @@ -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"> diff --git a/app/src/main/res/layout/source_filter_sheet.xml b/app/src/main/res/layout/source_filter_sheet.xml index 28d5b82920..ba55eec5d1 100644 --- a/app/src/main/res/layout/source_filter_sheet.xml +++ b/app/src/main/res/layout/source_filter_sheet.xml @@ -2,19 +2,18 @@ + android:backgroundTint="?android:attr/colorBackground"> + android:clipToPadding="false" /> \ No newline at end of file