Преглед на файлове

refactor(更新) :
- StepFragment 移除第四步操作,流程优化
- SwitchStatusFragment 界面与交互优化
- 新增地图点位点击后,右侧列表自动滚动至对应项并高亮显示功能
- 调整右侧列表布局,增加登录按钮和分割线
- 地图名称显示优化,使用 `motorMapShortName` 字段
- CustomSwitchStationLayer 新增 `onClickListener`,用于处理点位点击事件
- LotoSwitchMapPageRespVO 增加 `mapName` 和 `motorMapShortName` 字段
- MotorMapInfoRespVO 增加 `isSelect` 字段,用于标记列表项是否被选中
- 新增 `common_switch_layout_bg.xml`、`common_switch_layout_bg_normal.xml`、`common_switch_layout_bg_selected.xml` 列表项背景
- 调整 `fragment_switch_status.xml` 布局,优化右侧列表的显示和宽度
- 调整 `item_switch.xml` 布局,背景改为 `common_switch_layout_bg`

周文健 преди 1 месец
родител
ревизия
be1a40ea92

+ 2 - 0
app/src/main/java/com/grkj/iscs_mars/model/vo/map/LotoSwitchMapPageRespVO.kt

@@ -14,6 +14,8 @@ data class LotoSwitchMapPageRespVO(
         val motorMapId: Long?,
         val lotoId: String?,
         val motorMapName: String?,
+        val mapName: String?,
+        val motorMapShortName: String?,
         val lotoSerialNumber: String?
     )
 }

+ 1 - 0
app/src/main/java/com/grkj/iscs_mars/model/vo/map/MotorMapInfoRespVO.kt

@@ -34,5 +34,6 @@ data class MotorMapInfoRespVO(
         val pointSerialNumber: String?,
 
         var status: String?,
+        var isSelect: Boolean = false
     )
 }

+ 20 - 19
app/src/main/java/com/grkj/iscs_mars/view/fragment/StepFragment.kt

@@ -181,16 +181,23 @@ class StepFragment(val goBack: () -> Unit, val changePage: (PageChangeBO) -> Uni
 
 
     private fun initMap() {
-        gestureDetector = GestureDetector(requireContext(), object : GestureDetector.SimpleOnGestureListener() {
-            override fun onDoubleTap(e: MotionEvent): Boolean {
-                mBinding?.mapview?.currentRotateDegrees = 0f
-                return super.onDoubleTap(e)
-            }
-            override fun onFling(e1: MotionEvent?, e2: MotionEvent, velocityX: Float, velocityY: Float): Boolean {
-                mBinding?.mapview?.currentRotateDegrees = 0f
-                return super.onFling(e1, e2, velocityX, velocityY)
-            }
-        })
+        gestureDetector =
+            GestureDetector(requireContext(), object : GestureDetector.SimpleOnGestureListener() {
+                override fun onDoubleTap(e: MotionEvent): Boolean {
+                    mBinding?.mapview?.currentRotateDegrees = 0f
+                    return super.onDoubleTap(e)
+                }
+
+                override fun onFling(
+                    e1: MotionEvent?,
+                    e2: MotionEvent,
+                    velocityX: Float,
+                    velocityY: Float
+                ): Boolean {
+                    mBinding?.mapview?.currentRotateDegrees = 0f
+                    return super.onFling(e1, e2, velocityX, velocityY)
+                }
+            })
         mBinding?.mapview?.isScaleAndRotateTogether = false
         mBinding?.mapview?.setOnTouchListener { _, event ->
             gestureDetector.onTouchEvent(event)
@@ -211,6 +218,7 @@ class StepFragment(val goBack: () -> Unit, val changePage: (PageChangeBO) -> Uni
                     mBinding?.mapview?.refresh()
                 }
             }
+
             override fun onMapLoadFail() {
                 ToastUtils.tip("onMapLoadFail")
             }
@@ -278,7 +286,7 @@ class StepFragment(val goBack: () -> Unit, val changePage: (PageChangeBO) -> Uni
                             presenter?.mapDataHandleForStations(
                                 requireContext(),
                                 itMapInfo,
-                                mMachineryDetail?.pointIdList?:mutableListOf(),
+                                mMachineryDetail?.pointIdList ?: mutableListOf(),
                                 { mBinding?.mapview },
                                 stationLayer
                             ) { mapBmp ->
@@ -387,14 +395,7 @@ class StepFragment(val goBack: () -> Unit, val changePage: (PageChangeBO) -> Uni
                 )
             }
 
-            4 -> {
-                if (mStep != 3) {
-                    return
-                }
-                updateStep(4)
-            }
-
-            5, 6, 7, 8 -> {
+            4, 5, 6, 7, 8 -> {
                 if (mStep != step - 1) {
                     ToastUtils.tip(
                         getString(

+ 26 - 5
app/src/main/java/com/grkj/iscs_mars/view/fragment/SwitchStatusFragment.kt

@@ -5,6 +5,7 @@ import android.view.Gravity
 import android.view.MotionEvent
 import android.widget.LinearLayout
 import androidx.core.view.isVisible
+import androidx.recyclerview.widget.LinearLayoutManager
 import androidx.viewpager2.widget.ViewPager2
 import com.drake.brv.BindingAdapter
 import com.drake.brv.annotaion.DividerOrientation
@@ -22,8 +23,8 @@ import com.grkj.iscs_mars.modbus.ModBusController
 import com.grkj.iscs_mars.model.eventmsg.MsgEventConstants
 import com.grkj.iscs_mars.model.vo.map.LotoSwitchMapPageRespVO
 import com.grkj.iscs_mars.model.vo.map.MotorMapInfoRespVO
+import com.grkj.iscs_mars.model.vo.map.MotorMapInfoRespVO.IsMotorMapPoint
 import com.grkj.iscs_mars.util.CommonUtils
-import com.grkj.iscs_mars.util.ToastUtils
 import com.grkj.iscs_mars.view.base.BaseMvpFragment
 import com.grkj.iscs_mars.view.dialog.SwitchInfoDialog
 import com.grkj.iscs_mars.view.iview.ISwitchStatusView
@@ -33,6 +34,7 @@ import com.onlylemi.mapview.library.MapViewListener
 import com.sik.sikcore.extension.setDebouncedClickListener
 import com.sik.sikcore.thread.ThreadUtils
 
+
 class SwitchStatusFragment(private val vp2: ViewPager2?) :
     BaseMvpFragment<ISwitchStatusView, SwitchStatusPresenter, FragmentSwitchStatusBinding>() {
     private var stationLayer: CustomSwitchStationLayer? = null
@@ -84,10 +86,7 @@ class SwitchStatusFragment(private val vp2: ViewPager2?) :
                 onBind {
                     val item = getModel<LotoSwitchMapPageRespVO.Record>()
                     val itemBinding = getBinding<ItemMapBinding>()
-                    itemBinding.mapName.text = item.motorMapName?.substring(
-                        0,
-                        if (item.motorMapName.length > 6) 6 else item.motorMapName.length
-                    )
+                    itemBinding.mapName.text = item.motorMapShortName
                     itemBinding.mapName.isSelected = item.motorMapId == currentMotorMapId
                     itemBinding.mapName.setDebouncedClickListener {
                         isMapLoaded = false
@@ -108,6 +107,13 @@ class SwitchStatusFragment(private val vp2: ViewPager2?) :
         val switchData = ModBusController.getSwitchData()
         itemBinding.switchName.text = "${item.motorName}"
         itemBinding.switchId.text = context.getString(R.string.switch_id, item.motorCode)
+        itemBinding.root.isSelected = item.isSelect
+        if (item.isSelect) {
+            itemBinding.root.postDelayed({
+                item.isSelect = false
+                adapter.notifyDataSetChanged()
+            }, 2000)
+        }
         val switchStatus = switchData
             .find { it.idx == item.pointSerialNumber?.toInt() }?.enabled
             ?: (item.status == "1")
@@ -221,6 +227,21 @@ class SwitchStatusFragment(private val vp2: ViewPager2?) :
                     )
                     switchInfoDialog.showPopupWindow(screenX.toInt(), screenY.toInt())
                 }
+                onClickListener = { point, _, _, _, _ ->
+                    mBinding?.pointList?.isVisible = true
+                    val layoutManager = mBinding?.rvList?.layoutManager as LinearLayoutManager
+                    mBinding?.rvList?.models?.filterNotNull()
+                        ?.filterIsInstance<IsMotorMapPoint>()
+                        ?.find { it.motorCode == point.motorCode }?.apply {
+                            isSelect = true
+                        }
+                    layoutManager.scrollToPositionWithOffset(
+                        mBinding?.rvList?.models?.filterNotNull()
+                            ?.filterIsInstance<IsMotorMapPoint>()
+                            ?.indexOfFirst { it.motorCode == point.motorCode } ?: -1,
+                        0
+                    ) // 第二个参数是偏移量
+                }
             }
             mBinding?.mapview?.addLayer(stationLayer)
         }

+ 1 - 1
app/src/main/java/com/grkj/iscs_mars/view/presenter/SwitchStatusPresenter.kt

@@ -130,7 +130,7 @@ class SwitchStatusPresenter : BasePresenter<ISwitchStatusView>() {
                         worldY = backendH - worldY
                     }
                     // todo 随机电机状态
-//                    pt.status = Random.nextInt(2).toString()
+                    pt.status = Random.nextInt(2).toString()
                     val switchStatus =
                         if (pt.status == "1") CustomSwitchStationLayer.STATUS_ON
                         else CustomSwitchStationLayer.STATUS_OFF

+ 14 - 1
app/src/main/java/com/grkj/iscs_mars/view/widget/CustomSwitchStationLayer.kt

@@ -163,6 +163,8 @@ class CustomSwitchStationLayer @JvmOverloads constructor(
     // ===== 兼容原版:对外回调 =====
     var onLongPressListener: ((point: IsolationPoint, screenX: Float, screenY: Float, mapX: Float, mapY: Float) -> Unit)? =
         null
+    var onClickListener: ((point: IsolationPoint, screenX: Float, screenY: Float, mapX: Float, mapY: Float) -> Unit)? =
+        null
 
     init {
         paint = Paint(Paint.ANTI_ALIAS_FLAG).apply { style = Paint.Style.FILL_AND_STROKE }
@@ -333,7 +335,18 @@ class CustomSwitchStationLayer @JvmOverloads constructor(
                 val targetCenter = centerOf(hit)
                 val eid = hit.entityId
                 val name = hit.motorCode
-
+                if (abs(event.x - downScreenX) < 10 && abs(event.y - downScreenY) < 10) {
+                    val p = currentPressed!!
+                    val c = centerOf(p)
+                    val screen = mapToScreen(c.x, c.y)
+                    onClickListener?.invoke(
+                        p,
+                        screen.x,
+                        screen.y - getSwitchR() / 2f - 4,
+                        c.x,
+                        c.y
+                    )
+                }
                 currentMapCenter()?.let { cur ->
                     mapView?.animateCenterOnPoint(
                         cur.x,

+ 5 - 0
app/src/main/res/drawable/common_switch_layout_bg.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
+    <item android:drawable="@drawable/common_switch_layout_bg_selected" android:state_selected="true" />
+    <item android:drawable="@drawable/common_switch_layout_bg_normal" />
+</selector>

+ 9 - 0
app/src/main/res/drawable/common_switch_layout_bg_normal.xml

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+    android:shape="rectangle">
+    <solid android:color="@color/color_map_base" />
+    <stroke
+        android:width="1dp"
+        android:color="@color/color_map_stroke" />
+    <corners android:radius="@dimen/common_radius_small" />
+</shape>

+ 9 - 0
app/src/main/res/drawable/common_switch_layout_bg_selected.xml

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+    android:shape="rectangle">
+    <solid android:color="@color/color_map_base" />
+    <stroke
+        android:width="4dp"
+        android:color="@color/color_map_stroke" />
+    <corners android:radius="@dimen/common_radius_small" />
+</shape>

+ 53 - 59
app/src/main/res/layout/fragment_switch_status.xml

@@ -14,11 +14,11 @@
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_centerHorizontal="true"
-        android:paddingHorizontal="@dimen/common_spacing"
         android:layout_marginVertical="@dimen/common_text_padding"
         android:background="@drawable/bg_switch_title"
         android:gravity="center"
         android:minWidth="200dp"
+        android:paddingHorizontal="@dimen/common_spacing"
         android:textColor="@color/white"
         android:textSize="@dimen/map_title_text_size"
         tools:text="123" />
@@ -35,71 +35,65 @@
             android:id="@+id/mapview"
             android:layout_width="match_parent"
             android:layout_height="match_parent" />
+    </FrameLayout>
 
-        <androidx.constraintlayout.widget.ConstraintLayout
-            android:layout_width="wrap_content"
+    <androidx.constraintlayout.widget.ConstraintLayout
+        android:layout_width="wrap_content"
+        android:layout_height="match_parent"
+        android:layout_alignParentRight="true">
+
+        <LinearLayout
+            android:id="@+id/point_list"
+            android:layout_width="240dp"
             android:layout_height="match_parent"
-            android:layout_gravity="right">
+            android:layout_marginLeft="12dp"
+            android:background="@drawable/common_layout_bg"
+            android:minWidth="200dp"
+            android:orientation="vertical"
+            android:padding="@dimen/common_spacing"
+            android:visibility="gone"
+            app:layout_constraintBottom_toBottomOf="parent"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintStart_toStartOf="@id/cb_show"
+            app:layout_constraintTop_toTopOf="parent">
 
-            <LinearLayout
-                android:id="@+id/point_list"
+            <com.grkj.iscs_mars.view.widget.CommonBtn
+                android:id="@+id/cb_login"
                 android:layout_width="wrap_content"
-                android:layout_height="match_parent"
-                android:layout_marginLeft="12dp"
-                android:background="@drawable/common_layout_bg"
-                android:minWidth="200dp"
-                android:orientation="vertical"
-                android:padding="@dimen/common_spacing"
-                android:visibility="gone"
-                app:layout_constraintBottom_toBottomOf="parent"
-                app:layout_constraintEnd_toEndOf="parent"
-                app:layout_constraintStart_toStartOf="@id/cb_show"
-                app:layout_constraintTop_toTopOf="parent">
-
-                <androidx.recyclerview.widget.RecyclerView
-                    android:id="@+id/map_rv"
-                    android:layout_width="match_parent"
-                    android:layout_height="wrap_content"
-                    android:layout_marginTop="@dimen/common_spacing" />
-
-                <TextView
-                    android:layout_width="match_parent"
-                    android:layout_height="wrap_content"
-                    android:layout_gravity="center_horizontal"
-                    android:layout_marginVertical="@dimen/common_spacing"
-                    android:gravity="center"
-                    android:text="@string/switch_information"
-                    android:textColor="@color/black"
-                    android:textSize="@dimen/common_text_size"
-                    android:textStyle="bold" />
+                android:layout_height="wrap_content"
+                android:layout_gravity="right"
+                android:layout_marginVertical="@dimen/common_spacing_small"
+                app:btn_bg="@drawable/common_btn_blue_bg"
+                app:btn_name="@string/login" />
 
-                <androidx.recyclerview.widget.RecyclerView
-                    android:id="@+id/rv_list"
-                    android:layout_width="match_parent"
-                    android:layout_height="match_parent"
-                    android:minWidth="200dp"
-                    android:paddingHorizontal="10dp" />
-            </LinearLayout>
+            <View
+                android:layout_width="match_parent"
+                android:layout_height="1dp"
+                android:background="@color/color_d7d2d2" />
 
-            <ImageView
-                android:id="@+id/cb_show"
-                android:layout_width="24dp"
-                android:layout_height="24dp"
-                android:src="@drawable/icon_chevron_left"
-                app:layout_constraintBottom_toBottomOf="parent"
-                app:layout_constraintStart_toStartOf="parent"
-                app:layout_constraintTop_toTopOf="parent" />
+            <androidx.recyclerview.widget.RecyclerView
+                android:id="@+id/map_rv"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:layout_marginTop="@dimen/common_spacing" />
 
-        </androidx.constraintlayout.widget.ConstraintLayout>
+            <androidx.recyclerview.widget.RecyclerView
+                android:id="@+id/rv_list"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:layout_marginTop="@dimen/common_spacing"
+                android:minWidth="200dp"
+                android:paddingHorizontal="10dp" />
+        </LinearLayout>
 
-        <com.grkj.iscs_mars.view.widget.CommonBtn
-            android:id="@+id/cb_login"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_gravity="center_horizontal|bottom"
-            android:layout_marginVertical="@dimen/common_spacing_small"
-            app:btn_bg="@drawable/common_btn_blue_bg"
-            app:btn_name="@string/login" />
-    </FrameLayout>
+        <ImageView
+            android:id="@+id/cb_show"
+            android:layout_width="24dp"
+            android:layout_height="24dp"
+            android:src="@drawable/icon_chevron_left"
+            app:layout_constraintBottom_toBottomOf="parent"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toTopOf="parent" />
 
+    </androidx.constraintlayout.widget.ConstraintLayout>
 </RelativeLayout>

+ 7 - 7
app/src/main/res/layout/item_switch.xml

@@ -1,18 +1,18 @@
 <?xml version="1.0" encoding="utf-8"?>
 <layout xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:tools="http://schemas.android.com/tools"
-    xmlns:app="http://schemas.android.com/apk/res-auto">
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools">
 
     <LinearLayout
         android:id="@+id/root"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:background="@drawable/common_layout_bg"
+        android:background="@drawable/common_switch_layout_bg"
         android:divider="@drawable/divider_vertical_small"
         android:orientation="vertical"
         android:padding="@dimen/common_spacing_small"
-        app:rippleColor="?attr/colorPrimary"
-        android:showDividers="middle">
+        android:showDividers="middle"
+        app:rippleColor="?attr/colorPrimary">
 
         <TextView
             android:id="@+id/switch_name"
@@ -49,10 +49,10 @@
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:background="@drawable/bg_switch_off"
-                android:textColor="@color/white"
-                android:textSize="@dimen/common_text_size_small"
                 android:paddingHorizontal="@dimen/common_spacing_small"
                 android:paddingVertical="@dimen/common_spacing_smallest"
+                android:textColor="@color/white"
+                android:textSize="@dimen/common_text_size_small"
                 android:textStyle="bold"
                 tools:text="OFF" />
         </LinearLayout>