Skip to content

Commit

Permalink
Rearrange code
Browse files Browse the repository at this point in the history
  • Loading branch information
DonMat committed Jul 13, 2018
1 parent 07fa97b commit 8a7a00d
Showing 1 changed file with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ import android.widget.Spinner


class SearchableSpinner : Spinner, View.OnTouchListener, OnSearchableItemClick<Any?> {
override fun onSearchableItemClicked(item: Any?, position: Int) {
setSelection(mItems.indexOf(item))
}

private lateinit var searchDialog: SearchableSpinnerDialog
private val mContext: Context
Expand All @@ -54,15 +51,6 @@ class SearchableSpinner : Spinner, View.OnTouchListener, OnSearchableItemClick<A
init()
}

private fun init() {
searchDialog = SearchableSpinnerDialog.getInstance(mItems)
searchDialog.setTitle(mDialogTitle)
searchDialog.setDismissText(mCloseText)
searchDialog.onSearchableItemClick = this

setOnTouchListener(this)
}

override fun onTouch(v: View?, event: MotionEvent?): Boolean {
if (searchDialog.isAdded) return true

Expand All @@ -80,6 +68,10 @@ class SearchableSpinner : Spinner, View.OnTouchListener, OnSearchableItemClick<A
return true
}

override fun onSearchableItemClicked(item: Any?, position: Int) {
setSelection(mItems.indexOf(item))
}

fun setDialogTitle(title: String?) {
mDialogTitle = title
searchDialog.setTitle(title)
Expand All @@ -95,6 +87,15 @@ class SearchableSpinner : Spinner, View.OnTouchListener, OnSearchableItemClick<A
searchDialog.setDismissText(dismiss, onDismissListener)
}

private fun init() {
searchDialog = SearchableSpinnerDialog.getInstance(mItems)
searchDialog.setTitle(mDialogTitle)
searchDialog.setDismissText(mCloseText)
searchDialog.onSearchableItemClick = this

setOnTouchListener(this)
}

private fun setAttributes(context: Context, attrs: AttributeSet) {
val attributes = context.obtainStyledAttributes(attrs, R.styleable.SearchableSpinner)

Expand Down

0 comments on commit 8a7a00d

Please sign in to comment.