mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-20 06:29:17 +01:00
Fix filter sheet bottom buttons when keyboard was previously showing
This commit is contained in:
parent
8ead904def
commit
c020d4d45d
@ -5,6 +5,7 @@ import android.os.Bundle
|
|||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewTreeObserver.OnGlobalLayoutListener
|
import android.view.ViewTreeObserver.OnGlobalLayoutListener
|
||||||
|
import android.view.WindowInsets
|
||||||
import androidx.constraintlayout.widget.ConstraintLayout
|
import androidx.constraintlayout.widget.ConstraintLayout
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
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.databinding.SourceFilterSheetBinding
|
||||||
import eu.kanade.tachiyomi.util.system.dpToPx
|
import eu.kanade.tachiyomi.util.system.dpToPx
|
||||||
import eu.kanade.tachiyomi.util.view.collapse
|
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.updateLayoutParams
|
||||||
import eu.kanade.tachiyomi.util.view.updatePaddingRelative
|
import eu.kanade.tachiyomi.util.view.updatePaddingRelative
|
||||||
import eu.kanade.tachiyomi.widget.E2EBottomSheetDialog
|
import eu.kanade.tachiyomi.widget.E2EBottomSheetDialog
|
||||||
@ -39,20 +41,40 @@ class SourceFilterSheet(val activity: Activity) :
|
|||||||
sheetBehavior.peekHeight = 450.dpToPx
|
sheetBehavior.peekHeight = 450.dpToPx
|
||||||
sheetBehavior.collapse()
|
sheetBehavior.collapse()
|
||||||
|
|
||||||
binding.titleLayout.viewTreeObserver.addOnGlobalLayoutListener(object : OnGlobalLayoutListener {
|
binding.titleLayout.viewTreeObserver.addOnGlobalLayoutListener(object :
|
||||||
override fun onGlobalLayout() {
|
OnGlobalLayoutListener {
|
||||||
binding.cardView.updateLayoutParams<ConstraintLayout.LayoutParams> {
|
override fun onGlobalLayout() {
|
||||||
val fullHeight = activity.window.decorView.height
|
activity.window.decorView.rootWindowInsets?.let {
|
||||||
val insets = activity.window.decorView.rootWindowInsets
|
setCardViewMax(it)
|
||||||
matchConstraintMaxHeight =
|
}
|
||||||
fullHeight - (insets?.systemWindowInsetTop ?: 0) -
|
if (binding.titleLayout.height > 0) {
|
||||||
binding.titleLayout.height - 75.dpToPx
|
binding.titleLayout.viewTreeObserver.removeOnGlobalLayoutListener(this)
|
||||||
}
|
}
|
||||||
if (binding.titleLayout.height > 0) {
|
|
||||||
binding.titleLayout.viewTreeObserver.removeOnGlobalLayoutListener(this)
|
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
binding.cardView.doOnApplyWindowInsets { _, insets, _ ->
|
||||||
|
binding.cardView.updateLayoutParams<ConstraintLayout.LayoutParams> {
|
||||||
|
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<ConstraintLayout.LayoutParams> {
|
||||||
|
height = headerHeight + binding.titleLayout.paddingBottom
|
||||||
|
}
|
||||||
|
setCardViewMax(insets)
|
||||||
|
}
|
||||||
|
|
||||||
(binding.root.parent.parent as? View)?.viewTreeObserver?.addOnGlobalLayoutListener(object : OnGlobalLayoutListener {
|
(binding.root.parent.parent as? View)?.viewTreeObserver?.addOnGlobalLayoutListener(object : OnGlobalLayoutListener {
|
||||||
override fun onGlobalLayout() {
|
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<ConstraintLayout.LayoutParams> {
|
||||||
|
matchConstraintMaxHeight = newHeight
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
super.onStart()
|
super.onStart()
|
||||||
sheetBehavior.collapse()
|
sheetBehavior.collapse()
|
||||||
|
Loading…
Reference in New Issue
Block a user