|
|
@@ -0,0 +1,60 @@
|
|
|
+package com.grkj.iscs.widget
|
|
|
+
|
|
|
+import android.content.Context
|
|
|
+import android.util.AttributeSet
|
|
|
+import android.view.View
|
|
|
+import android.view.inputmethod.InputMethodManager
|
|
|
+import android.widget.LinearLayout
|
|
|
+import com.grkj.iscs.R
|
|
|
+import com.grkj.iscs.databinding.LayoutSelectableInputBinding
|
|
|
+
|
|
|
+class SelectableInput(ctx: Context, attrs: AttributeSet) : LinearLayout(ctx, attrs) {
|
|
|
+
|
|
|
+ companion object {
|
|
|
+ const val MODE_INPUT = 0
|
|
|
+ const val MODE_SELECT = 1
|
|
|
+ }
|
|
|
+
|
|
|
+ private var mBinding: LayoutSelectableInputBinding
|
|
|
+
|
|
|
+ init {
|
|
|
+ val root = View.inflate(ctx, R.layout.layout_selectable_input, this)
|
|
|
+ mBinding = LayoutSelectableInputBinding.bind(root)
|
|
|
+
|
|
|
+ val attrSet = ctx.obtainStyledAttributes(attrs, R.styleable.SelectableInput)
|
|
|
+
|
|
|
+ val mode = attrSet.getInt(R.styleable.SelectableInput_mode, 0)
|
|
|
+ setMode(mode)
|
|
|
+
|
|
|
+ val isRequired = attrSet.getBoolean(R.styleable.SelectableInput_required, false)
|
|
|
+ mBinding.tvPrefix.visibility = if (isRequired) View.VISIBLE else View.GONE
|
|
|
+
|
|
|
+ mBinding.tvName.text = attrSet.getString(R.styleable.SelectableInput_name)
|
|
|
+ mBinding.et.hint = attrSet.getString(R.styleable.SelectableInput_edittext_hint)
|
|
|
+
|
|
|
+ attrSet.recycle()
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun setMode(mode: Int) {
|
|
|
+ if (mode == MODE_SELECT) {
|
|
|
+ mBinding.et.isEnabled = false
|
|
|
+ mBinding.spinner.visibility = View.VISIBLE
|
|
|
+ mBinding.et.visibility = View.GONE
|
|
|
+// btnDropdown.visibility = View.VISIBLE
|
|
|
+// if (!options.isNullOrEmpty()) {
|
|
|
+// btnDropdown.setOnClickListener(onBtnDropdownClickListener)
|
|
|
+// }
|
|
|
+ } else {
|
|
|
+ mBinding.et.isEnabled = true
|
|
|
+ mBinding.spinner.visibility = View.GONE
|
|
|
+ mBinding.et.visibility = View.VISIBLE
|
|
|
+// btnDropdown.visibility = View.GONE
|
|
|
+// btnDropdown.setOnClickListener(null)
|
|
|
+// clContainer.setOnClickListener {
|
|
|
+// editText.requestFocus()
|
|
|
+// val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
|
|
+// imm.showSoftInput(editText, 0)
|
|
|
+// }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|