diff options
3 files changed, 10 insertions, 6 deletions
diff --git a/library/src/main/kotlin/ca/allanwang/kau/searchview/SearchCard.kt b/library/src/main/kotlin/ca/allanwang/kau/searchview/SearchCard.kt index 77da6b0..74f72d0 100644 --- a/library/src/main/kotlin/ca/allanwang/kau/searchview/SearchCard.kt +++ b/library/src/main/kotlin/ca/allanwang/kau/searchview/SearchCard.kt @@ -5,6 +5,7 @@ import android.graphics.Rect import android.support.v7.widget.CardView import android.util.AttributeSet import android.view.ViewGroup +import ca.allanwang.kau.utils.parentViewGroup /** * Created by Allan Wang on 2017-06-26. @@ -19,7 +20,7 @@ class SearchCard @JvmOverloads constructor( val parentVisibleHeight: Int get() { val r = Rect() - (parent as ViewGroup).getWindowVisibleDisplayFrame(r) + parentViewGroup.getWindowVisibleDisplayFrame(r) return r.height() } diff --git a/library/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt b/library/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt index 3b4afae..ba8243d 100644 --- a/library/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt +++ b/library/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt @@ -81,7 +81,7 @@ class SearchView @JvmOverloads constructor( } var revealDuration: Long = 300L var transitionDuration: Long = 100L - var shouldClearOnClose: Boolean = true + var shouldClearOnClose: Boolean = false var openListener: ((searchView: SearchView) -> Unit)? = null var closeListener: ((searchView: SearchView) -> Unit)? = null /** @@ -183,7 +183,7 @@ class SearchView @JvmOverloads constructor( init { View.inflate(context, R.layout.kau_search_view, this) z = 99f - iconNav.setSearchIcon(configs.navIcon).setOnClickListener { clearResults() } + iconNav.setSearchIcon(configs.navIcon).setOnClickListener { revealClose() } iconClear.setSearchIcon(configs.clearIcon).setOnClickListener { editText.text.clear() } tintForeground(configs.foregroundColor) tintBackground(configs.backgroundColor) @@ -241,12 +241,12 @@ class SearchView @JvmOverloads constructor( } fun unBind(replacementMenuItemClickListener: MenuItem.OnMenuItemClickListener? = null) { - (parent as ViewGroup).removeView(this) + parentViewGroup.removeView(this) menuItem?.setOnMenuItemClickListener(replacementMenuItemClickListener) } fun configureCoords(item: MenuItem) { - val view = (parent as ViewGroup).findViewById<View>(item.itemId) ?: return + val view = parentViewGroup.findViewById<View>(item.itemId) ?: return val locations = IntArray(2) view.getLocationOnScreen(locations) menuX = (locations[0] + view.width / 2) diff --git a/library/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt b/library/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt index 2b7d888..84d7e50 100644 --- a/library/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt +++ b/library/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt @@ -75,4 +75,7 @@ fun View.snackbar(@StringRes textId: Int, duration: Int = Snackbar.LENGTH_LONG, @KauUtils fun View.setRippleBackground(@ColorInt foregroundColor: Int, @ColorInt backgroundColor: Int) { background = createSimpleRippleDrawable(foregroundColor, backgroundColor) -}
\ No newline at end of file +} + +@KauUtils val View.parentViewGroup: ViewGroup + get() = parent as ViewGroup
\ No newline at end of file |