-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSearchPanelView.kt
79 lines (63 loc) · 2.23 KB
/
SearchPanelView.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package com.colvir.core.views
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.widget.AppCompatEditText
import androidx.constraintlayout.widget.ConstraintLayout
import com.colvir.core.android.R
import com.colvir.core.android.databinding.ViewSearchPanelBinding
import com.colvir.core.extensions.embed
import com.colvir.core.extensions.hideKeyboard
class SearchPanelView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null) :
ConstraintLayout(context, attrs) {
val clearSearchButton: ImageView get() = binding.clearSearchButton
val searchField: AppCompatEditText get() = binding.searchField
val closeButton: ImageView get() = binding.closeSearchButton
val foundText: TextView get() = binding.foundText
var description
get() = binding.foundText.text.toString()
set(value) {
binding.foundText.text = value
}
var hint: String?
get() = searchField.hint?.toString()
set(value) {
searchField.hint = value
}
private var binding_: ViewSearchPanelBinding? = null
protected val binding: ViewSearchPanelBinding
get() = binding_!!
init {
binding_ = ViewSearchPanelBinding.inflate(LayoutInflater.from(context), this)
//setBackgroundColor(AppColors.PRIMARY_COLOR)
init(attrs)
}
private fun init(attrs: AttributeSet?) {
val attributes = context.obtainStyledAttributes(attrs, R.styleable.SearchPanel)
try {
hint = attributes.getString(R.styleable.SearchPanel_search_panel_hint)
} finally {
attributes.recycle()
}
binding.searchField.setOnEditorActionListener { v, actionId, event ->
binding.searchField.clearFocus()
hideKeyboard()
true
}
}
override fun onViewAdded(view: View?) {
super.onViewAdded(view)
if (view?.tag == "content") {
binding.content.embed(view)
}
}
override fun onDetachedFromWindow() {
super.onDetachedFromWindow()
binding_ = null
}
}