فهرست منبع

完善工艺SOP页面;添加CommonBtn通用按钮组件

Frankensteinly 10 ماه پیش
والد
کامیت
c775e4899a

+ 45 - 4
app/src/main/java/com/grkj/iscs/view/fragment/TechnologySopFragment.kt

@@ -1,6 +1,7 @@
 package com.grkj.iscs.view.fragment
 
 import android.widget.ImageView
+import android.widget.LinearLayout
 import androidx.recyclerview.widget.RecyclerView
 import com.bumptech.glide.Glide
 import com.grkj.iscs.R
@@ -21,6 +22,8 @@ class TechnologySopFragment :
     BaseMvpFragment<ITechnologySopView, TechnologySopPresenter, FragmentTechnologySopBinding>() {
 
     private val mMachineryList = mutableListOf<MachineryPageRespVO.Record>()
+    private var mMachineryIdx = -1
+    private var mSopTypeIdx = -1
 
     override val viewBinding: FragmentTechnologySopBinding
         get() = FragmentTechnologySopBinding.inflate(layoutInflater)
@@ -31,31 +34,55 @@ class TechnologySopFragment :
             R.layout.item_rv_technology_sop,
             mMachineryList
         ) {
-            override fun convert(holder: ViewHolder, data: MachineryPageRespVO.Record?, position: Int) {
+            override fun convert(holder: ViewHolder, data: MachineryPageRespVO.Record?, parPos: Int) {
+                holder.getView<LinearLayout>(R.id.root).isSelected = parPos == mMachineryIdx
                 holder.setText(R.id.tv_name, data?.machineryName)
                 Glide.with(this@TechnologySopFragment).load(data?.machineryImg).into(holder.getView(R.id.iv_pic))
+                holder.setOnClickListener(R.id.root) {
+                    if (mMachineryIdx != parPos) {
+                        mSopTypeIdx = -1
+                    }
+                    mMachineryIdx = parPos
+                    refreshSelected()
+                    notifyDataSetChanged()
+                }
+
                 val recyclerView = holder.getView<RecyclerView>(R.id.rv_type)
                 recyclerView.adapter = object : CommonAdapter<MachineryPageRespVO.Record.SysDictData>(
                     requireActivity(),
                     R.layout.item_rv_technology_sop_type,
                     data?.sysDictDatas ?: mutableListOf()
                 ) {
-                    override fun convert(holder: ViewHolder, type: MachineryPageRespVO.Record.SysDictData?, position: Int) {
+                    override fun convert(holder: ViewHolder, type: MachineryPageRespVO.Record.SysDictData?, childPos: Int) {
+                        holder.getView<LinearLayout>(R.id.root).isSelected = (childPos == mSopTypeIdx && parPos == mMachineryIdx)
                         type?.dictLabel?.let {
                             holder.setText(R.id.tv_name, it)
                         }
                         mSopTypeList.find { it.type.toString() == type?.dictValue }?.icon?.let { icon ->
                             holder.getView<ImageView>(R.id.iv_type).setImageResource(icon)
                         }
+                        holder.setOnClickListener(R.id.root) {
+                            mMachineryIdx = parPos
+                            mSopTypeIdx = childPos
+                            mBinding?.rvTechnology?.adapter?.notifyDataSetChanged()
+                            refreshSelected()
+                            notifyDataSetChanged()
+                        }
                     }
                 }
             }
         }
 
-        refreshPage(8)
+        // TODO 测试数据
+        refreshPage("本地测试工艺", 8)
+
+        mBinding?.cbStart?.setOnClickListener {
+
+        }
     }
 
-    fun refreshPage(workstationId: Int) {
+    fun refreshPage(title: String, workstationId: Int) {
+        mBinding?.tvTitle?.text = title
         presenter?.getMachineryPage(workstationId) {
             mMachineryList.clear()
             it?.records?.let {
@@ -65,6 +92,20 @@ class TechnologySopFragment :
         }
     }
 
+    private fun refreshSelected() {
+        val sopName = if (mMachineryIdx == -1) {
+            ""
+        } else {
+            "-${mMachineryList[mMachineryIdx].machineryName}"
+        }
+        val sopTypeName = if (mSopTypeIdx == -1) {
+            ""
+        } else {
+            "-${mMachineryList[mMachineryIdx].sysDictDatas?.get(mSopTypeIdx)?.dictLabel}"
+        }
+        mBinding?.tvSelected?.text = getString(R.string.current_sop, "${mBinding?.tvTitle?.text}$sopName$sopTypeName")
+    }
+
     override fun initPresenter(): TechnologySopPresenter {
         return TechnologySopPresenter()
     }

+ 39 - 0
app/src/main/java/com/grkj/iscs/view/widget/CommonBtn.kt

@@ -0,0 +1,39 @@
+package com.grkj.iscs.view.widget
+
+import android.content.Context
+import android.util.AttributeSet
+import android.view.LayoutInflater
+import android.view.View
+import android.widget.LinearLayout
+import com.grkj.iscs.R
+import com.grkj.iscs.databinding.LayoutCommonBtnBinding
+
+/**
+ * 通用Tab控件
+ */
+class CommonBtn(private val ctx: Context, attrs: AttributeSet) : LinearLayout(ctx, attrs) {
+
+    private var mBinding: LayoutCommonBtnBinding
+
+    init {
+        val root = View.inflate(ctx, R.layout.layout_common_btn, this)
+        mBinding = LayoutCommonBtnBinding.bind(root)
+
+        val attrSet = ctx.obtainStyledAttributes(attrs, R.styleable.CommonBtn)
+
+        val btnText = attrSet.getString(R.styleable.CommonBtn_btn_name)
+        mBinding.tvName.text = btnText
+
+        val btnIcon = attrSet.getResourceId(R.styleable.CommonBtn_btn_icon, 0)
+        if (btnIcon != 0) {
+            mBinding.iv.setImageResource(btnIcon)
+        }
+
+        val background = attrSet.getResourceId(R.styleable.CommonBtn_btn_bg, 0)
+        if (background != 0) {
+            mBinding.root.setBackgroundResource(background)
+        }
+
+        attrSet.recycle()
+    }
+}

+ 6 - 0
app/src/main/res/drawable/common_btn_blue_bg.xml

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

+ 6 - 0
app/src/main/res/drawable/common_btn_red_bg.xml

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

+ 1 - 1
app/src/main/res/drawable/item_rv_technology_sop_type_bg_normal.xml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
 <shape xmlns:android="http://schemas.android.com/apk/res/android">
     <corners android:radius="@dimen/common_radius_small" />
-    <solid android:color="@color/main_color" />
+    <solid android:color="@color/main_color_dark" />
 </shape>

+ 1 - 1
app/src/main/res/drawable/item_rv_technology_sop_type_bg_selected.xml

@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <shape xmlns:android="http://schemas.android.com/apk/res/android">
     <corners android:radius="@dimen/common_radius_small" />
-    <solid android:color="@color/main_color" />
+    <solid android:color="@color/main_color_dark" />
     <stroke
         android:width="@dimen/divider_line_width"
         android:color="@color/white" />

+ 1 - 0
app/src/main/res/layout/dialog_login.xml

@@ -64,6 +64,7 @@
             style="@style/CommonBtn"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
+            android:background="@drawable/white_stroke_bg"
             android:text="@string/cancel" />
     </LinearLayout>
 </com.google.android.material.card.MaterialCardView>

+ 30 - 1
app/src/main/res/layout/fragment_technology_sop.xml

@@ -1,16 +1,45 @@
 <?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     tools:context=".view.fragment.TechnologySopFragment">
 
+    <com.grkj.iscs.view.widget.CommonBtn
+        android:id="@+id/cb_start"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignParentRight="true"
+        android:layout_alignParentBottom="true"
+        app:btn_bg="@drawable/common_btn_blue_bg"
+        app:btn_icon="@mipmap/start"
+        app:btn_name="@string/start_the_job" />
+
+    <TextView
+        android:id="@+id/tv_selected"
+        style="@style/CommonBtnBlue"
+        android:layout_width="match_parent"
+        android:layout_alignParentBottom="true"
+        android:layout_toLeftOf="@id/cb_start"
+        android:gravity="left|center_vertical"
+        android:text="@string/current_sop"
+        android:layout_marginRight="@dimen/common_padding"/>
+
     <LinearLayout
         android:layout_width="match_parent"
-        android:layout_height="wrap_content"
+        android:layout_height="match_parent"
+        android:layout_above="@id/tv_selected"
+        android:layout_marginBottom="@dimen/common_padding"
+        android:background="@drawable/item_rv_technology_sop_bg_normal"
         android:orientation="vertical"
         android:padding="@dimen/common_padding">
 
+        <TextView
+            android:id="@+id/tv_title"
+            style="@style/CommonTextView"
+            android:layout_marginLeft="@dimen/common_padding" />
+
         <androidx.recyclerview.widget.RecyclerView
             android:id="@+id/rv_technology"
             style="@style/CommonRecyclerView"

+ 18 - 0
app/src/main/res/layout/layout_common_btn.xml

@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="wrap_content"
+    android:layout_height="wrap_content"
+    android:gravity="center_vertical"
+    android:orientation="horizontal"
+    android:padding="@dimen/common_text_padding">
+
+    <ImageView
+        android:id="@+id/iv"
+        android:layout_width="14dp"
+        android:layout_height="14dp" />
+
+    <TextView
+        android:id="@+id/tv_name"
+        style="@style/CommonTextView"
+        android:layout_marginLeft="5dp" />
+</LinearLayout>

BIN
app/src/main/res/mipmap/start.png


+ 6 - 0
app/src/main/res/values/attrs.xml

@@ -15,4 +15,10 @@
         <attr name="edittext_hint" format="string" />
         <attr name="enabled" format="boolean" />
     </declare-styleable>
+
+    <declare-styleable name="CommonBtn">
+        <attr name="btn_name" format="string" />
+        <attr name="btn_icon" format="reference" />
+        <attr name="btn_bg" format="reference" />
+    </declare-styleable>
 </resources>

+ 2 - 0
app/src/main/res/values/colors.xml

@@ -5,6 +5,7 @@
     <color name="aquamarine">#7FFFD4</color>
 
     <color name="main_color">#00AAFF</color>
+    <color name="main_color_dark">#CC055EB3</color>
     <color name="common_transparent">#00000000</color>
     <color name="common_bg_white_10">#1affffff</color>
     <color name="common_bg_white_20">#33ffffff</color>
@@ -25,4 +26,5 @@
     <color name="switch_track_off">#E9E9E9</color>
     <color name="dialog_card_login_bg">#990E57EA</color>
     <color name="home_menu_bg">#4D2B7AE9</color>
+    <color name="common_btn_red_bg">#80FF0000</color>
 </resources>

+ 1 - 1
app/src/main/res/values/dimens.xml

@@ -63,7 +63,7 @@
     <dimen name="page_padding">20dp</dimen>
     <dimen name="item_rv_technology_height">207dp</dimen>
     <dimen name="item_rv_technology_width">118dp</dimen>
-    <dimen name="item_rv_technology_type_height">18dp</dimen>
+    <dimen name="item_rv_technology_type_height">17dp</dimen>
     <dimen name="item_rv_technology_type_width">46dp</dimen>
     <dimen name="item_rv_technology_type_padding">3dp</dimen>
     <dimen name="dialog_tip_width">256dp</dimen>

+ 1 - 0
app/src/main/res/values/strings.xml

@@ -137,4 +137,5 @@
     <string name="please_scan_face">请刷脸</string>
     <string name="please_scan_fingerprint">请刷指纹</string>
     <string name="login">登录</string>
+    <string name="current_sop">当前SOP:%s</string>
 </resources>

+ 12 - 0
app/src/main/res/values/styles.xml

@@ -18,6 +18,18 @@
         <item name="android:padding">@dimen/common_text_padding</item>
     </style>
 
+    <style name="CommonBtnBlue" parent="CommonBtn">
+        <item name="android:layout_width">wrap_content</item>
+        <item name="android:layout_height">wrap_content</item>
+        <item name="android:background">@drawable/common_btn_blue_bg</item>
+    </style>
+
+    <style name="CommonBtnRed" parent="CommonBtn">
+        <item name="android:layout_width">wrap_content</item>
+        <item name="android:layout_height">wrap_content</item>
+        <item name="android:background">@drawable/common_btn_red_bg</item>
+    </style>
+
     <style name="CommonRecyclerView">
         <item name="android:layout_width">match_parent</item>
         <item name="android:layout_height">match_parent</item>