|
|
@@ -8,9 +8,10 @@ import android.view.ViewGroup
|
|
|
import android.widget.LinearLayout
|
|
|
import android.widget.PopupWindow
|
|
|
import com.grkj.iscs.R
|
|
|
-import com.grkj.iscs.databinding.ItemBleBinding
|
|
|
import com.grkj.iscs.databinding.LayoutSelectableInputBinding
|
|
|
-import com.grkj.iscs.util.ToastUtils
|
|
|
+import com.grkj.iscs.databinding.LayoutSelectableinputSpinnerBinding
|
|
|
+import com.zhy.adapter.recyclerview.CommonAdapter
|
|
|
+import com.zhy.adapter.recyclerview.base.ViewHolder
|
|
|
|
|
|
|
|
|
class SelectableInput(private val ctx: Context, attrs: AttributeSet) : LinearLayout(ctx, attrs) {
|
|
|
@@ -21,6 +22,11 @@ class SelectableInput(private val ctx: Context, attrs: AttributeSet) : LinearLay
|
|
|
}
|
|
|
|
|
|
private var mBinding: LayoutSelectableInputBinding
|
|
|
+ private var mDropdownView: View? = null
|
|
|
+ private var mPopWindow: PopupWindow? = null
|
|
|
+ var mOptionList = mutableListOf<String>()
|
|
|
+ private var isSkipListener: Boolean = true
|
|
|
+ private var mSelectListener: OnSpinnerSelectListener? = null
|
|
|
|
|
|
init {
|
|
|
val root = View.inflate(ctx, R.layout.layout_selectable_input, this)
|
|
|
@@ -42,35 +48,18 @@ class SelectableInput(private val ctx: Context, attrs: AttributeSet) : LinearLay
|
|
|
|
|
|
private fun setMode(mode: Int) {
|
|
|
if (mode == MODE_SELECT) {
|
|
|
- mBinding.et.isEnabled = false
|
|
|
-
|
|
|
- mBinding.et.visibility = View.GONE
|
|
|
-
|
|
|
- mBinding.tvName.setOnClickListener {
|
|
|
- val contentView = LayoutInflater.from(ctx).inflate(R.layout.item_ble, null)
|
|
|
-
|
|
|
- val popWnd = PopupWindow(context)
|
|
|
- popWnd.contentView = contentView
|
|
|
-// popWnd.width = ViewGroup.LayoutParams.MATCH_PARENT
|
|
|
- popWnd.width = this.width
|
|
|
- popWnd.height = ViewGroup.LayoutParams.WRAP_CONTENT
|
|
|
- popWnd.isOutsideTouchable = true
|
|
|
- popWnd.showAsDropDown(mBinding.tvName)
|
|
|
-
|
|
|
- val popBinding = ItemBleBinding.bind(contentView)
|
|
|
- popBinding.bleName.setOnClickListener {
|
|
|
- ToastUtils.tip("ble name")
|
|
|
- popWnd.dismiss()
|
|
|
+// mBinding.et.isEnabled = false
|
|
|
+ mBinding.et.inputType = 0
|
|
|
+
|
|
|
+// btnDropdown.visibility = View.VISIBLE
|
|
|
+ mBinding.et.setOnClickListener {
|
|
|
+ if (mOptionList.isNotEmpty()) {
|
|
|
+ showDropdown()
|
|
|
}
|
|
|
}
|
|
|
-// btnDropdown.visibility = View.VISIBLE
|
|
|
-// if (!options.isNullOrEmpty()) {
|
|
|
-// btnDropdown.setOnClickListener(onBtnDropdownClickListener)
|
|
|
-// }
|
|
|
} else {
|
|
|
mBinding.et.isEnabled = true
|
|
|
|
|
|
- mBinding.et.visibility = View.VISIBLE
|
|
|
// btnDropdown.visibility = View.GONE
|
|
|
// btnDropdown.setOnClickListener(null)
|
|
|
// clContainer.setOnClickListener {
|
|
|
@@ -80,4 +69,40 @@ class SelectableInput(private val ctx: Context, attrs: AttributeSet) : LinearLay
|
|
|
// }
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private fun showDropdown() {
|
|
|
+ mDropdownView?:let {
|
|
|
+ mDropdownView = LayoutInflater.from(ctx).inflate(R.layout.layout_selectableinput_spinner, null)
|
|
|
+ }
|
|
|
+
|
|
|
+ mPopWindow ?: let {
|
|
|
+ mPopWindow = PopupWindow(context)
|
|
|
+ mPopWindow?.contentView = mDropdownView
|
|
|
+ mPopWindow?.width = mBinding.et.width
|
|
|
+ mPopWindow?.height = ViewGroup.LayoutParams.WRAP_CONTENT
|
|
|
+ mPopWindow?.isOutsideTouchable = true
|
|
|
+
|
|
|
+ val popBinding = LayoutSelectableinputSpinnerBinding.bind(mDropdownView!!)
|
|
|
+ popBinding.rvOptions.adapter = object : CommonAdapter<String>(ctx, R.layout.item_rv_selectableinput_spinner, mOptionList) {
|
|
|
+ override fun convert(holder: ViewHolder?, option: String?, position: Int) {
|
|
|
+ holder?.setText(R.id.tv_option, option)
|
|
|
+ holder?.setOnClickListener(R.id.tv_option) {
|
|
|
+ mBinding.et.setText(option)
|
|
|
+ mSelectListener?.onSelect(option, position)
|
|
|
+ mPopWindow?.dismiss()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ mPopWindow?.showAsDropDown(mBinding.et)
|
|
|
+ }
|
|
|
+
|
|
|
+ fun setOnSpinnerSelectListener(onSpinnerSelectListener: OnSpinnerSelectListener) {
|
|
|
+ mSelectListener = onSpinnerSelectListener
|
|
|
+ }
|
|
|
+
|
|
|
+ interface OnSpinnerSelectListener {
|
|
|
+ fun onSelect(str: String?, index: Int)
|
|
|
+ }
|
|
|
}
|