From 43cd1034b3319365db52d03efdfff333822c7335 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sun, 12 Nov 2017 03:46:50 -0500 Subject: misc (#102) * Update gradle * Increment android libs and add progress animator * Null check on searchview unbind, fixes #100 * Add searchview holder interface * Rename methods --- .../ca/allanwang/kau/searchview/SearchView.kt | 2 +- .../allanwang/kau/searchview/SearchViewHolder.kt | 25 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchViewHolder.kt (limited to 'searchview/src/main/kotlin/ca/allanwang') diff --git a/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt b/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt index dabf4bc..50e0298 100644 --- a/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt +++ b/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt @@ -316,7 +316,7 @@ class SearchView @JvmOverloads constructor( * with the option to replace the item click listener */ fun unBind(replacementMenuItemClickListener: ((item: MenuItem) -> Boolean)? = null) { - parentViewGroup.removeView(this) + (parent as? ViewGroup)?.removeView(this) menuItem?.setOnMenuItemClickListener(replacementMenuItemClickListener) menuItem = null } diff --git a/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchViewHolder.kt b/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchViewHolder.kt new file mode 100644 index 0000000..3f81dd0 --- /dev/null +++ b/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchViewHolder.kt @@ -0,0 +1,25 @@ +package ca.allanwang.kau.searchview + +import android.view.MenuItem + +/** + * Created by Allan Wang on 2017-11-12. + * + * Interface to help facilitate searchview binding and actions + */ +interface SearchViewHolder { + + var searchView: SearchView? + + fun searchViewBindIfNull(binder: () -> SearchView) { + if (searchView == null) searchView = binder() + } + + fun searchViewOnBackPress() = searchView?.onBackPressed() ?: false + + fun searchViewUnBind(replacementMenuItemClickListener: ((item: MenuItem) -> Boolean)? = null) { + searchView?.unBind(replacementMenuItemClickListener) + searchView = null + } + +} \ No newline at end of file -- cgit v1.2.3