mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-11-29 13:22:59 -08:00
fix: SearchFiltersView height #2541
This commit is contained in:
2 files changed
+50
-14
No files matched your search
@@ -1,6 +1,9 @@
|
||||
package com.kunzisoft.keepass.view
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.Parcelable
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
@@ -70,6 +73,9 @@ class SearchFiltersView @JvmOverloads constructor(
|
||||
private var searchRecycleBin: CompoundButton
|
||||
private var searchTemplate: CompoundButton
|
||||
|
||||
private var isExpanded = false
|
||||
var onExpansionChanged: ((expanded: Boolean) -> Unit)? = null
|
||||
|
||||
var searchParameters = SearchParameters()
|
||||
get() {
|
||||
return field.apply {
|
||||
@@ -163,8 +169,8 @@ class SearchFiltersView @JvmOverloads constructor(
|
||||
|
||||
// Expand menu with button
|
||||
searchExpandButton.setOnClickListener {
|
||||
val isVisible = searchAdvanceFiltersContainer?.visibility == VISIBLE
|
||||
if (isVisible)
|
||||
val isExpanded = searchAdvanceFiltersContainer?.visibility == VISIBLE
|
||||
if (isExpanded)
|
||||
closeAdvancedFilters()
|
||||
else
|
||||
openAdvancedFilters()
|
||||
@@ -294,14 +300,46 @@ class SearchFiltersView @JvmOverloads constructor(
|
||||
searchTemplate.isEnabled = enable
|
||||
}
|
||||
|
||||
fun closeAdvancedFilters() {
|
||||
searchAdvanceFiltersContainer?.collapse()
|
||||
fun closeAdvancedFilters(animate: Boolean = true) {
|
||||
isExpanded = false
|
||||
searchAdvanceFiltersContainer?.collapse(animate) {
|
||||
onExpansionChanged?.invoke(false)
|
||||
}
|
||||
}
|
||||
|
||||
private fun openAdvancedFilters() {
|
||||
searchAdvanceFiltersContainer?.expand(true,
|
||||
fun openAdvancedFilters(animate: Boolean = true) {
|
||||
isExpanded = true
|
||||
searchAdvanceFiltersContainer?.expand(animate,
|
||||
searchAdvanceFiltersContainer?.getFullHeight()
|
||||
)
|
||||
) {
|
||||
onExpansionChanged?.invoke(true)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(): Parcelable {
|
||||
val bundle = Bundle()
|
||||
bundle.putParcelable("superState", super.onSaveInstanceState())
|
||||
bundle.putBoolean("isExpanded", isExpanded)
|
||||
return bundle
|
||||
}
|
||||
|
||||
override fun onRestoreInstanceState(state: Parcelable?) {
|
||||
var superState = state
|
||||
if (state is Bundle) {
|
||||
isExpanded = state.getBoolean("isExpanded")
|
||||
if (isExpanded) {
|
||||
searchAdvanceFiltersContainer?.post {
|
||||
openAdvancedFilters(animate = false)
|
||||
}
|
||||
}
|
||||
superState = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
state.getParcelable("superState", Parcelable::class.java)
|
||||
} else {
|
||||
@Suppress("DEPRECATION")
|
||||
state.getParcelable("superState")
|
||||
}
|
||||
}
|
||||
super.onRestoreInstanceState(superState)
|
||||
}
|
||||
|
||||
fun allowAdvancedSearch(show: Boolean) {
|
||||
@@ -317,7 +355,7 @@ class SearchFiltersView @JvmOverloads constructor(
|
||||
when (visibility) {
|
||||
VISIBLE -> {
|
||||
if (searchContainer.visibility != VISIBLE) {
|
||||
searchAdvanceFiltersContainer?.visibility = GONE
|
||||
searchAdvanceFiltersContainer?.visibility = if (isExpanded) VISIBLE else GONE
|
||||
searchContainer.showByFading()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,6 @@ import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.animation.AccelerateDecelerateInterpolator
|
||||
import android.widget.ImageView
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.view.menu.ActionMenuItemView
|
||||
@@ -199,14 +198,13 @@ fun View.expand(animate: Boolean = true,
|
||||
* the layout's visibility is GONE
|
||||
*/
|
||||
fun ViewGroup.getFullHeight(): Int {
|
||||
measure(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
|
||||
val initialVisibility = visibility
|
||||
visibility = LinearLayout.VISIBLE
|
||||
val desiredWidth = View.MeasureSpec.makeMeasureSpec(
|
||||
width,
|
||||
visibility = View.VISIBLE
|
||||
val widthSpec = View.MeasureSpec.makeMeasureSpec(
|
||||
if (width > 0) width else (parent as? View)?.width ?: resources.displayMetrics.widthPixels,
|
||||
View.MeasureSpec.AT_MOST
|
||||
)
|
||||
measure(desiredWidth, View.MeasureSpec.UNSPECIFIED)
|
||||
measure(widthSpec, View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED))
|
||||
val totalHeight = measuredHeight
|
||||
visibility = initialVisibility
|
||||
return totalHeight
|
||||
|
||||
Reference in new issue
Block a user