diff options
author | Allan Wang <me@allanwang.ca> | 2017-11-12 03:46:50 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-12 03:46:50 -0500 |
commit | 43cd1034b3319365db52d03efdfff333822c7335 (patch) | |
tree | 6e7e5d6c6198a632e11a2855a1022feefff7b666 /searchview | |
parent | 637851b6ddc4a22583797a45bdbb72eb9c6dac23 (diff) | |
download | kau-43cd1034b3319365db52d03efdfff333822c7335.tar.gz kau-43cd1034b3319365db52d03efdfff333822c7335.tar.bz2 kau-43cd1034b3319365db52d03efdfff333822c7335.zip |
misc (#102)
* Update gradle
* Increment android libs and add progress animator
* Null check on searchview unbind, fixes #100
* Add searchview holder interface
* Rename methods
Diffstat (limited to 'searchview')
-rw-r--r-- | searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt | 2 | ||||
-rw-r--r-- | searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchViewHolder.kt | 25 |
2 files changed, 26 insertions, 1 deletions
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 |