|
@@ -5,31 +5,27 @@ import android.view.View
|
|
|
import android.view.ViewGroup
|
|
import android.view.ViewGroup
|
|
|
import android.widget.PopupWindow
|
|
import android.widget.PopupWindow
|
|
|
import com.google.gson.Gson
|
|
import com.google.gson.Gson
|
|
|
-import com.google.gson.reflect.TypeToken
|
|
|
|
|
import com.grkj.iscs.R
|
|
import com.grkj.iscs.R
|
|
|
import com.grkj.iscs.databinding.FragmentSystemSettingBinding
|
|
import com.grkj.iscs.databinding.FragmentSystemSettingBinding
|
|
|
import com.grkj.iscs.databinding.LayoutSelectableinputSpinnerBinding
|
|
import com.grkj.iscs.databinding.LayoutSelectableinputSpinnerBinding
|
|
|
-import com.grkj.iscs.model.DeviceConst.DOCK_TYPE_COLLECT
|
|
|
|
|
-import com.grkj.iscs.model.DeviceConst.DOCK_TYPE_ELEC_LOCK_BOARD
|
|
|
|
|
-import com.grkj.iscs.model.DeviceConst.DOCK_TYPE_KEY
|
|
|
|
|
-import com.grkj.iscs.model.DeviceConst.DOCK_TYPE_LOCK
|
|
|
|
|
-import com.grkj.iscs.model.DeviceConst.DOCK_TYPE_PORTABLE
|
|
|
|
|
-import com.grkj.iscs.util.CommonUtils
|
|
|
|
|
import com.grkj.iscs.util.SPUtils
|
|
import com.grkj.iscs.util.SPUtils
|
|
|
-import com.grkj.iscs.util.ToastUtils
|
|
|
|
|
import com.grkj.iscs.util.byteToHexString
|
|
import com.grkj.iscs.util.byteToHexString
|
|
|
-import com.grkj.iscs.view.base.BaseFragment
|
|
|
|
|
|
|
+import com.grkj.iscs.view.base.BaseMvpFragment
|
|
|
|
|
+import com.grkj.iscs.view.iview.ISystemSettingView
|
|
|
|
|
+import com.grkj.iscs.view.presenter.SystemSettingPresenter
|
|
|
import com.zhy.adapter.recyclerview.CommonAdapter
|
|
import com.zhy.adapter.recyclerview.CommonAdapter
|
|
|
import com.zhy.adapter.recyclerview.base.ViewHolder
|
|
import com.zhy.adapter.recyclerview.base.ViewHolder
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 系统设置页
|
|
* 系统设置页
|
|
|
*/
|
|
*/
|
|
|
-class SystemSettingFragment : BaseFragment<FragmentSystemSettingBinding>() {
|
|
|
|
|
|
|
+class SystemSettingFragment : BaseMvpFragment<ISystemSettingView, SystemSettingPresenter, FragmentSystemSettingBinding>() {
|
|
|
|
|
|
|
|
private var mDockTypeList = mutableListOf<DockItem>()
|
|
private var mDockTypeList = mutableListOf<DockItem>()
|
|
|
|
|
+ private var mPortList = mutableListOf<String>()
|
|
|
private var mDropdownView: View? = null
|
|
private var mDropdownView: View? = null
|
|
|
- private var mPopWindow: PopupWindow? = null
|
|
|
|
|
|
|
+ private var mTypePop: PopupWindow? = null
|
|
|
|
|
+ private var mPortPop: PopupWindow? = null
|
|
|
private var mDockList = mutableListOf<DockTestFragment.DockTestBean>()
|
|
private var mDockList = mutableListOf<DockTestFragment.DockTestBean>()
|
|
|
private var mSelectedBoardType: Byte? = null
|
|
private var mSelectedBoardType: Byte? = null
|
|
|
|
|
|
|
@@ -37,34 +33,18 @@ class SystemSettingFragment : BaseFragment<FragmentSystemSettingBinding>() {
|
|
|
get() = FragmentSystemSettingBinding.inflate(layoutInflater)
|
|
get() = FragmentSystemSettingBinding.inflate(layoutInflater)
|
|
|
|
|
|
|
|
override fun initView() {
|
|
override fun initView() {
|
|
|
- val dockConfigJson = SPUtils.getDockConfig(requireActivity())
|
|
|
|
|
- if (!dockConfigJson.isNullOrEmpty()) {
|
|
|
|
|
- val tempList: MutableList<DockTestFragment.DockTestBean> =
|
|
|
|
|
- Gson().fromJson(
|
|
|
|
|
- dockConfigJson,
|
|
|
|
|
- object : TypeToken<MutableList<DockTestFragment.DockTestBean>>() {}.type
|
|
|
|
|
- )
|
|
|
|
|
- if (tempList.isNotEmpty()) {
|
|
|
|
|
- mDockList.addAll(tempList)
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ mDockList.addAll(presenter?.getDockList()!!)
|
|
|
|
|
|
|
|
- mDockTypeList.addAll(
|
|
|
|
|
- mutableListOf(
|
|
|
|
|
- DockItem(getString(R.string.board_type_key), DOCK_TYPE_KEY),
|
|
|
|
|
- DockItem(getString(R.string.board_type_lock), DOCK_TYPE_LOCK),
|
|
|
|
|
- DockItem(getString(R.string.board_type_portal), DOCK_TYPE_PORTABLE),
|
|
|
|
|
- DockItem(getString(R.string.board_type_collect), DOCK_TYPE_COLLECT),
|
|
|
|
|
- DockItem(getString(R.string.board_type_elec_lock), DOCK_TYPE_ELEC_LOCK_BOARD)
|
|
|
|
|
- )
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
- mBinding?.rlSpinner?.setOnClickListener {
|
|
|
|
|
|
|
+ mDockTypeList.addAll(presenter?.getDockTypeList()!!)
|
|
|
|
|
+
|
|
|
|
|
+ mBinding?.rlSpinnerType?.setOnClickListener {
|
|
|
showBoardTypeDropDown()
|
|
showBoardTypeDropDown()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
mBinding?.tvAdd?.setOnClickListener {
|
|
mBinding?.tvAdd?.setOnClickListener {
|
|
|
- addBoard()
|
|
|
|
|
|
|
+ presenter?.addBoard(mBinding?.etAddress?.text.toString(), mSelectedBoardType, mDockList) {
|
|
|
|
|
+ mBinding?.rvBoard?.adapter?.notifyDataSetChanged()
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
mBinding?.rvBoard?.adapter = object : CommonAdapter<DockTestFragment.DockTestBean>(
|
|
mBinding?.rvBoard?.adapter = object : CommonAdapter<DockTestFragment.DockTestBean>(
|
|
@@ -87,6 +67,19 @@ class SystemSettingFragment : BaseFragment<FragmentSystemSettingBinding>() {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ mPortList.addAll(presenter?.getSerialPorts()!!)
|
|
|
|
|
+
|
|
|
|
|
+ mBinding?.rlSpinnerPort?.setOnClickListener {
|
|
|
|
|
+ showPortDropDown()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ mBinding?.tvPort?.text = SPUtils.getPortConfig(requireActivity())
|
|
|
|
|
+
|
|
|
|
|
+ mBinding?.tvSetPort?.setOnClickListener {
|
|
|
|
|
+ presenter?.setPort(mBinding?.tvPort?.text.toString())
|
|
|
|
|
+ // TODO 设置端口
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private fun showBoardTypeDropDown() {
|
|
private fun showBoardTypeDropDown() {
|
|
@@ -95,13 +88,13 @@ class SystemSettingFragment : BaseFragment<FragmentSystemSettingBinding>() {
|
|
|
.inflate(R.layout.layout_selectableinput_spinner, null)
|
|
.inflate(R.layout.layout_selectableinput_spinner, null)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- mPopWindow ?: let {
|
|
|
|
|
- mPopWindow = PopupWindow(context)
|
|
|
|
|
- mPopWindow?.contentView = mDropdownView
|
|
|
|
|
- mPopWindow?.width = mBinding?.rlSpinner!!.width
|
|
|
|
|
- mPopWindow?.height = ViewGroup.LayoutParams.WRAP_CONTENT
|
|
|
|
|
- mPopWindow?.isOutsideTouchable = true
|
|
|
|
|
- mPopWindow?.isFocusable = true
|
|
|
|
|
|
|
+ mTypePop ?: let {
|
|
|
|
|
+ mTypePop = PopupWindow(context)
|
|
|
|
|
+ mTypePop?.contentView = mDropdownView
|
|
|
|
|
+ mTypePop?.width = mBinding?.rlSpinnerType!!.width
|
|
|
|
|
+ mTypePop?.height = ViewGroup.LayoutParams.WRAP_CONTENT
|
|
|
|
|
+ mTypePop?.isOutsideTouchable = true
|
|
|
|
|
+ mTypePop?.isFocusable = true
|
|
|
|
|
|
|
|
val popBinding = LayoutSelectableinputSpinnerBinding.bind(mDropdownView!!)
|
|
val popBinding = LayoutSelectableinputSpinnerBinding.bind(mDropdownView!!)
|
|
|
popBinding.rvOptions.adapter = object : CommonAdapter<DockItem>(
|
|
popBinding.rvOptions.adapter = object : CommonAdapter<DockItem>(
|
|
@@ -113,34 +106,52 @@ class SystemSettingFragment : BaseFragment<FragmentSystemSettingBinding>() {
|
|
|
holder?.setText(R.id.tv_option, option?.name)
|
|
holder?.setText(R.id.tv_option, option?.name)
|
|
|
holder?.setOnClickListener(R.id.tv_option) {
|
|
holder?.setOnClickListener(R.id.tv_option) {
|
|
|
mBinding?.tvBoardType?.text = option?.name
|
|
mBinding?.tvBoardType?.text = option?.name
|
|
|
- mPopWindow?.dismiss()
|
|
|
|
|
|
|
+ mTypePop?.dismiss()
|
|
|
mSelectedBoardType = option?.type
|
|
mSelectedBoardType = option?.type
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- mPopWindow?.showAsDropDown(mBinding?.rlSpinner)
|
|
|
|
|
|
|
+ mTypePop?.showAsDropDown(mBinding?.rlSpinnerType)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private fun addBoard() {
|
|
|
|
|
- val address = mBinding?.etAddress?.text.toString()
|
|
|
|
|
- if (mSelectedBoardType == null) {
|
|
|
|
|
- ToastUtils.tip(R.string.please_select_board_type)
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
- if (address.isEmpty()) {
|
|
|
|
|
- ToastUtils.tip(R.string.please_input_address)
|
|
|
|
|
- return
|
|
|
|
|
|
|
+ private fun showPortDropDown() {
|
|
|
|
|
+ mDropdownView ?: let {
|
|
|
|
|
+ mDropdownView = LayoutInflater.from(requireActivity())
|
|
|
|
|
+ .inflate(R.layout.layout_selectableinput_spinner, null)
|
|
|
}
|
|
}
|
|
|
- if (!CommonUtils.isValidHex(address)) {
|
|
|
|
|
- ToastUtils.tip(R.string.please_input_valid_address)
|
|
|
|
|
- return
|
|
|
|
|
|
|
+
|
|
|
|
|
+ mPortPop ?: let {
|
|
|
|
|
+ mPortPop = PopupWindow(context)
|
|
|
|
|
+ mPortPop?.contentView = mDropdownView
|
|
|
|
|
+ mPortPop?.width = mBinding?.rlSpinnerType!!.width
|
|
|
|
|
+ mPortPop?.height = ViewGroup.LayoutParams.WRAP_CONTENT
|
|
|
|
|
+ mPortPop?.isOutsideTouchable = true
|
|
|
|
|
+ mPortPop?.isFocusable = true
|
|
|
|
|
+
|
|
|
|
|
+ val popBinding = LayoutSelectableinputSpinnerBinding.bind(mDropdownView!!)
|
|
|
|
|
+ popBinding.rvOptions.adapter = object : CommonAdapter<String>(
|
|
|
|
|
+ requireActivity(),
|
|
|
|
|
+ R.layout.item_rv_selectableinput_spinner,
|
|
|
|
|
+ mPortList
|
|
|
|
|
+ ) {
|
|
|
|
|
+ override fun convert(holder: ViewHolder?, option: String, position: Int) {
|
|
|
|
|
+ holder?.setText(R.id.tv_option, option)
|
|
|
|
|
+ holder?.setOnClickListener(R.id.tv_option) {
|
|
|
|
|
+ mBinding?.tvPort?.text = option
|
|
|
|
|
+ mPortPop?.dismiss()
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- mDockList.add(DockTestFragment.DockTestBean(address.toInt(16).toByte(), mSelectedBoardType!!))
|
|
|
|
|
- mBinding?.rvBoard?.adapter?.notifyDataSetChanged()
|
|
|
|
|
- SPUtils.saveDockConfig(requireActivity(), Gson().toJson(mDockList))
|
|
|
|
|
|
|
+
|
|
|
|
|
+ mPortPop?.showAsDropDown(mBinding?.rlSpinnerPort)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ override fun initPresenter(): SystemSettingPresenter {
|
|
|
|
|
+ return SystemSettingPresenter()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private data class DockItem(val name: String, val type: Byte)
|
|
|
|
|
|
|
+ data class DockItem(val name: String, val type: Byte)
|
|
|
}
|
|
}
|