|
|
@@ -34,9 +34,17 @@ import com.onlylemi.mapview.library.MapViewListener
|
|
|
import com.sik.sikcore.extension.setDebouncedClickListener
|
|
|
import com.sik.sikcore.thread.ThreadUtils
|
|
|
|
|
|
-
|
|
|
-class SwitchStatusFragment(private val vp2: ViewPager2?) :
|
|
|
+class SwitchStatusFragment :
|
|
|
BaseMvpFragment<ISwitchStatusView, SwitchStatusPresenter, FragmentSwitchStatusBinding>() {
|
|
|
+
|
|
|
+ companion object {
|
|
|
+ fun newInstance(): SwitchStatusFragment = SwitchStatusFragment()
|
|
|
+ }
|
|
|
+
|
|
|
+ // 从 Activity 拿 ViewPager2(避免构造参数)
|
|
|
+ private val vp2: ViewPager2?
|
|
|
+ get() = activity?.findViewById(R.id.vp2)
|
|
|
+
|
|
|
private var stationLayer: CustomSwitchStationLayer? = null
|
|
|
private lateinit var gestureDetector: GestureDetector
|
|
|
private lateinit var switchInfoDialog: SwitchInfoDialog
|
|
|
@@ -44,9 +52,7 @@ class SwitchStatusFragment(private val vp2: ViewPager2?) :
|
|
|
private var currentLotoId = ""
|
|
|
private var isMapLoaded = false
|
|
|
|
|
|
- override fun initPresenter(): SwitchStatusPresenter {
|
|
|
- return SwitchStatusPresenter()
|
|
|
- }
|
|
|
+ override fun initPresenter(): SwitchStatusPresenter = SwitchStatusPresenter()
|
|
|
|
|
|
override val viewBinding: FragmentSwitchStatusBinding
|
|
|
get() = FragmentSwitchStatusBinding.inflate(layoutInflater)
|
|
|
@@ -76,9 +82,7 @@ class SwitchStatusFragment(private val vp2: ViewPager2?) :
|
|
|
mBinding?.mapview?.setBackgroundColorInt(requireContext().getColor(R.color.color_map_base))
|
|
|
mBinding?.rvList?.linear()?.dividerSpace(10, DividerOrientation.GRID)?.setup {
|
|
|
addType<MotorMapInfoRespVO.IsMotorMapPoint>(R.layout.item_switch)
|
|
|
- onBind {
|
|
|
- onRVListBinding()
|
|
|
- }
|
|
|
+ onBind { onRVListBinding() }
|
|
|
}
|
|
|
mBinding?.mapRv?.linear(LinearLayout.HORIZONTAL)?.dividerSpace(10, DividerOrientation.GRID)
|
|
|
?.setup {
|
|
|
@@ -103,7 +107,7 @@ class SwitchStatusFragment(private val vp2: ViewPager2?) :
|
|
|
|
|
|
private fun BindingAdapter.BindingViewHolder.onRVListBinding() {
|
|
|
val itemBinding = getBinding<ItemSwitchBinding>()
|
|
|
- val item = getModel<MotorMapInfoRespVO.IsMotorMapPoint>()
|
|
|
+ val item = getModel<IsMotorMapPoint>()
|
|
|
val switchData = ModBusController.getSwitchData()
|
|
|
itemBinding.switchName.text = "${item.motorName}"
|
|
|
itemBinding.switchId.text = context.getString(R.string.switch_id, item.motorCode)
|
|
|
@@ -122,28 +126,24 @@ class SwitchStatusFragment(private val vp2: ViewPager2?) :
|
|
|
itemBinding.switchStatus.setBackgroundResource(R.drawable.bg_switch_off)
|
|
|
itemBinding.switchStatus.text = CommonUtils.getStr(R.string.switch_close)
|
|
|
}
|
|
|
-
|
|
|
true -> {
|
|
|
itemBinding.switchStatus.setBackgroundResource(R.drawable.bg_switch_on)
|
|
|
itemBinding.switchStatus.text = CommonUtils.getStr(R.string.switch_open)
|
|
|
}
|
|
|
-
|
|
|
else -> {
|
|
|
itemBinding.switchStatus.setBackgroundResource(R.drawable.bg_switch_alarm)
|
|
|
itemBinding.switchStatus.text = CommonUtils.getStr(R.string.switch_alarm)
|
|
|
}
|
|
|
}
|
|
|
itemBinding.root.setDebouncedClickListener {
|
|
|
- stationLayer?.selectPoint(
|
|
|
- item.motorId
|
|
|
- )
|
|
|
+ stationLayer?.selectPoint(item.motorId)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
override fun onResume() {
|
|
|
super.onResume()
|
|
|
isMapLoaded = false
|
|
|
- mBinding?.mapview?.setRenderEnabled(true) // ✅ 当前页开始渲染
|
|
|
+ mBinding?.mapview?.setRenderEnabled(true)
|
|
|
BusinessManager.mEventBus.observe(this) {
|
|
|
when (it.code) {
|
|
|
MsgEventConstants.MSG_EVENT_SWITCH_COLLECTION_UPDATE_RESULT -> {
|
|
|
@@ -166,8 +166,9 @@ class SwitchStatusFragment(private val vp2: ViewPager2?) :
|
|
|
mBinding?.mapTitle?.text =
|
|
|
(it.records.find { it.lotoSerialNumber == requireContext().serialNo() }
|
|
|
?: it.records[0]).motorMapName
|
|
|
- getMap((it.records.find { it.lotoSerialNumber == requireContext().serialNo() }
|
|
|
- ?: it.records[0]).motorMapId.toString(),
|
|
|
+ getMap(
|
|
|
+ (it.records.find { it.lotoSerialNumber == requireContext().serialNo() }
|
|
|
+ ?: it.records[0]).motorMapId.toString(),
|
|
|
(it.records.find { it.lotoSerialNumber == requireContext().serialNo() }
|
|
|
?: it.records[0]).lotoId.toString()
|
|
|
)
|
|
|
@@ -177,13 +178,11 @@ class SwitchStatusFragment(private val vp2: ViewPager2?) :
|
|
|
|
|
|
override fun onPause() {
|
|
|
super.onPause()
|
|
|
- mBinding?.mapview?.setRenderEnabled(false) // ✅ 离开当前页立刻停渲染
|
|
|
+ mBinding?.mapview?.setRenderEnabled(false)
|
|
|
}
|
|
|
|
|
|
private fun getMap(mapId: String, lotoId: String) {
|
|
|
- if (lotoId.isEmpty() || mapId.isEmpty()) {
|
|
|
- return
|
|
|
- }
|
|
|
+ if (lotoId.isEmpty() || mapId.isEmpty()) return
|
|
|
presenter?.getMapInfo(mapId.toLong()) { itMapInfo ->
|
|
|
presenter?.getMotorMapInfo(lotoId.toLong()) { itMotorMapInfo ->
|
|
|
mBinding?.rvList?.models = itMotorMapInfo?.data
|
|
|
@@ -207,16 +206,11 @@ class SwitchStatusFragment(private val vp2: ViewPager2?) :
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 初始化地图
|
|
|
- */
|
|
|
private fun initMap() {
|
|
|
mBinding?.mapview?.isScaleAndRotateTogether = false
|
|
|
mBinding?.mapview?.setOnTouchListener { _, event ->
|
|
|
gestureDetector.onTouchEvent(event); false
|
|
|
}
|
|
|
-
|
|
|
- // ✅ 提前创建点位层(不要等 onMapLoadSuccess)
|
|
|
if (stationLayer == null) {
|
|
|
stationLayer = CustomSwitchStationLayer(mBinding?.mapview, mutableListOf()).apply {
|
|
|
onLongPressListener = { point, screenX, screenY, _, _ ->
|
|
|
@@ -240,24 +234,19 @@ class SwitchStatusFragment(private val vp2: ViewPager2?) :
|
|
|
?.filterIsInstance<IsMotorMapPoint>()
|
|
|
?.indexOfFirst { it.motorCode == point.motorCode } ?: -1,
|
|
|
0
|
|
|
- ) // 第二个参数是偏移量
|
|
|
+ )
|
|
|
}
|
|
|
}
|
|
|
mBinding?.mapview?.addLayer(stationLayer)
|
|
|
}
|
|
|
-
|
|
|
mBinding?.mapview?.setMapViewListener(object : MapViewListener {
|
|
|
override fun onMapLoadSuccess() {
|
|
|
- // 地图加载完成后,只做视图层面的事,别再 new layer 了
|
|
|
mBinding?.mapview?.post {
|
|
|
mBinding?.mapview?.currentRotateDegrees = 0f
|
|
|
mBinding?.mapview?.refresh()
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- override fun onMapLoadFail() {
|
|
|
- }
|
|
|
+ override fun onMapLoadFail() = Unit
|
|
|
})
|
|
|
}
|
|
|
-
|
|
|
-}
|
|
|
+}
|