From c020d4d45dfef0d136aa825cf4f80c9b4788a4b3 Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Mon, 10 May 2021 15:06:27 -0400 Subject: [PATCH] Fix filter sheet bottom buttons when keyboard was previously showing --- .../ui/source/browse/SourceFilterSheet.kt | 57 +++++++++++++++---- 1 file changed, 45 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/SourceFilterSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/SourceFilterSheet.kt index a7c3ed34dc..47193d70d4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/SourceFilterSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/SourceFilterSheet.kt @@ -5,6 +5,7 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewTreeObserver.OnGlobalLayoutListener +import android.view.WindowInsets import androidx.constraintlayout.widget.ConstraintLayout import androidx.recyclerview.widget.RecyclerView import com.google.android.material.bottomsheet.BottomSheetBehavior @@ -13,6 +14,7 @@ import eu.davidea.flexibleadapter.items.IFlexible import eu.kanade.tachiyomi.databinding.SourceFilterSheetBinding import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.util.view.collapse +import eu.kanade.tachiyomi.util.view.doOnApplyWindowInsets import eu.kanade.tachiyomi.util.view.updateLayoutParams import eu.kanade.tachiyomi.util.view.updatePaddingRelative import eu.kanade.tachiyomi.widget.E2EBottomSheetDialog @@ -39,20 +41,40 @@ class SourceFilterSheet(val activity: Activity) : sheetBehavior.peekHeight = 450.dpToPx sheetBehavior.collapse() - binding.titleLayout.viewTreeObserver.addOnGlobalLayoutListener(object : OnGlobalLayoutListener { - override fun onGlobalLayout() { - binding.cardView.updateLayoutParams { - val fullHeight = activity.window.decorView.height - val insets = activity.window.decorView.rootWindowInsets - matchConstraintMaxHeight = - fullHeight - (insets?.systemWindowInsetTop ?: 0) - - binding.titleLayout.height - 75.dpToPx - } - if (binding.titleLayout.height > 0) { - binding.titleLayout.viewTreeObserver.removeOnGlobalLayoutListener(this) + binding.titleLayout.viewTreeObserver.addOnGlobalLayoutListener(object : + OnGlobalLayoutListener { + override fun onGlobalLayout() { + activity.window.decorView.rootWindowInsets?.let { + setCardViewMax(it) + } + if (binding.titleLayout.height > 0) { + binding.titleLayout.viewTreeObserver.removeOnGlobalLayoutListener(this) + } } + }) + + binding.cardView.doOnApplyWindowInsets { _, insets, _ -> + binding.cardView.updateLayoutParams { + val fullHeight = activity.window.decorView.height + matchConstraintMaxHeight = + fullHeight - insets.systemWindowInsetTop - + binding.titleLayout.height - 75.dpToPx } - }) + } + + val attrsArray = intArrayOf(android.R.attr.actionBarSize) + val array = context.obtainStyledAttributes(attrsArray) + val headerHeight = array.getDimensionPixelSize(0, 0) + array.recycle() + binding.root.doOnApplyWindowInsets { _, insets, _ -> + binding.titleLayout.updatePaddingRelative( + bottom = insets.systemWindowInsetBottom + ) + binding.titleLayout.updateLayoutParams { + height = headerHeight + binding.titleLayout.paddingBottom + } + setCardViewMax(insets) + } (binding.root.parent.parent as? View)?.viewTreeObserver?.addOnGlobalLayoutListener(object : OnGlobalLayoutListener { override fun onGlobalLayout() { @@ -85,6 +107,17 @@ class SourceFilterSheet(val activity: Activity) : ) } + fun setCardViewMax(insets: WindowInsets) { + val fullHeight = activity.window.decorView.height + val newHeight = fullHeight - insets.systemWindowInsetTop - + binding.titleLayout.height - 75.dpToPx + if ((binding.cardView.layoutParams as ConstraintLayout.LayoutParams).matchConstraintMaxHeight != newHeight) { + binding.cardView.updateLayoutParams { + matchConstraintMaxHeight = newHeight + } + } + } + override fun onStart() { super.onStart() sheetBehavior.collapse()