|
|
@@ -1,6 +1,8 @@
|
|
|
package com.grkj.iscs_mc.view.widget
|
|
|
|
|
|
import android.content.Context
|
|
|
+import android.text.Editable
|
|
|
+import android.text.TextWatcher
|
|
|
import android.util.AttributeSet
|
|
|
import android.view.Gravity
|
|
|
import android.view.LayoutInflater
|
|
|
@@ -33,6 +35,7 @@ class SelectableInput(private val ctx: Context, attrs: AttributeSet) : LinearLay
|
|
|
private val mOptionList = mutableListOf<String>()
|
|
|
private var isSkipListener: Boolean = true
|
|
|
private var mSelectListener: OnSpinnerSelectListener? = null
|
|
|
+ private var mTextChangeListener: OnTextChangeListener? = null
|
|
|
var mSelectIdx: Int? = null
|
|
|
|
|
|
init {
|
|
|
@@ -92,8 +95,23 @@ class SelectableInput(private val ctx: Context, attrs: AttributeSet) : LinearLay
|
|
|
AppCompatResources.getDrawable(ctx, R.drawable.selectable_input_text_disabled_bg)
|
|
|
}
|
|
|
|
|
|
+ val textWatcher = object : TextWatcher {
|
|
|
+ override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {}
|
|
|
+
|
|
|
+ override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
|
|
|
+ if (mBinding.et.hasFocus()) {
|
|
|
+ mTextChangeListener?.onTextChange(p0.toString())
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun afterTextChanged(p0: Editable?) {}
|
|
|
+ }
|
|
|
+
|
|
|
mBinding.et.setOnFocusChangeListener { view, b ->
|
|
|
- if (!b) {
|
|
|
+ if (b) {
|
|
|
+ mBinding.et.addTextChangedListener(textWatcher)
|
|
|
+ } else {
|
|
|
+ mBinding.et.removeTextChangedListener(textWatcher)
|
|
|
val imm = ctx.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
|
|
imm.hideSoftInputFromWindow(view.windowToken, 0)
|
|
|
}
|
|
|
@@ -117,6 +135,7 @@ class SelectableInput(private val ctx: Context, attrs: AttributeSet) : LinearLay
|
|
|
.setTwelveHour(false)
|
|
|
.setOnDateResultListener {
|
|
|
setText(SimpleDateFormat("yyyy-MM-dd").format(Date(it)))
|
|
|
+ mTextChangeListener?.onTextChange(getText())
|
|
|
}
|
|
|
.build().show()
|
|
|
}
|
|
|
@@ -176,7 +195,15 @@ class SelectableInput(private val ctx: Context, attrs: AttributeSet) : LinearLay
|
|
|
mSelectListener = onSpinnerSelectListener
|
|
|
}
|
|
|
|
|
|
+ fun setOnTextChangeListener(onTextChangeListener: OnTextChangeListener) {
|
|
|
+ mTextChangeListener = onTextChangeListener
|
|
|
+ }
|
|
|
+
|
|
|
interface OnSpinnerSelectListener {
|
|
|
fun onSelect(str: String?, index: Int)
|
|
|
}
|
|
|
+
|
|
|
+ interface OnTextChangeListener {
|
|
|
+ fun onTextChange(str: String?)
|
|
|
+ }
|
|
|
}
|