Forráskód Böngészése

引入日期选择;引入SelectableInput并修改适配;调整优化物资更换手动操作页rv item显示

Frankensteinly 8 hónapja
szülő
commit
41feb6ce59

+ 2 - 0
app/build.gradle

@@ -84,4 +84,6 @@ dependencies {
 
     implementation "androidx.navigation:navigation-fragment-ktx:2.6.0"
     implementation "androidx.navigation:navigation-ui-ktx:2.6.0"
+
+    implementation 'com.github.jzmanu:MDatePickerSample:v1.0.5'
 }

+ 177 - 0
app/src/main/java/com/grkj/iscs_mc/view/widget/SelectableInput.kt

@@ -0,0 +1,177 @@
+package com.grkj.iscs_mc.view.widget
+
+import android.content.Context
+import android.util.AttributeSet
+import android.view.Gravity
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import android.view.inputmethod.InputMethodManager
+import android.widget.LinearLayout
+import android.widget.PopupWindow
+import androidx.appcompat.content.res.AppCompatResources
+import com.grkj.iscs_mc.R
+import com.grkj.iscs_mc.databinding.LayoutSelectableInputBinding
+import com.grkj.iscs_mc.databinding.LayoutSelectableinputSpinnerBinding
+import com.manu.mdatepicker.MDatePicker
+import com.zhy.adapter.recyclerview.CommonAdapter
+import com.zhy.adapter.recyclerview.base.ViewHolder
+import java.text.SimpleDateFormat
+import java.util.Date
+
+class SelectableInput(private val ctx: Context, attrs: AttributeSet) : LinearLayout(ctx, attrs) {
+
+    companion object {
+        const val MODE_INPUT = 0
+        const val MODE_SELECT = 1
+        const val MODE_DATE = 2
+    }
+
+    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
+    var mSelectIdx: Int? = null
+
+    init {
+        val root = View.inflate(ctx, R.layout.layout_selectable_input, this)
+        mBinding = LayoutSelectableInputBinding.bind(root)
+
+        val attrSet = ctx.obtainStyledAttributes(attrs, R.styleable.SelectableInput)
+
+        val isRequired = attrSet.getBoolean(R.styleable.SelectableInput_required, false)
+        mBinding.tvPrefix.visibility = if (isRequired) View.VISIBLE else View.INVISIBLE
+
+        val isEnabled = attrSet.getBoolean(R.styleable.SelectableInput_enabled, true)
+        mBinding.et.isEnabled = isEnabled
+
+        val mode = attrSet.getInt(R.styleable.SelectableInput_mode, 0)
+        setMode(mode)
+
+        mBinding.tvName.text = attrSet.getString(R.styleable.SelectableInput_name)
+        mBinding.et.hint = attrSet.getString(R.styleable.SelectableInput_edittext_hint)
+
+        val editWidth = attrSet.getDimensionPixelSize(R.styleable.SelectableInput_edit_width, -1)
+        if (editWidth != -1) {
+            mBinding.et.width = editWidth
+        }
+
+        attrSet.recycle()
+    }
+
+    private fun setMode(mode: Int) {
+        when (mode) {
+            // 选择模式
+            MODE_SELECT -> {
+                mBinding.et.background = if (mBinding.et.isEnabled) {
+                    AppCompatResources.getDrawable(ctx, R.drawable.selectable_input_spinner_bg)
+                } else {
+                    AppCompatResources.getDrawable(ctx, R.drawable.selectable_input_spinner_disabled_bg)
+                }
+
+                mBinding.et.inputType = 0
+
+                mBinding.et.setOnClickListener {
+                    if (mOptionList.isNotEmpty()) {
+                        showDropdown()
+                    }
+                }
+
+                mBinding.et.setOnTouchListener { view, _ ->
+                    view.requestFocus()
+                    return@setOnTouchListener false
+                }
+            }
+            // 输入模式
+            MODE_INPUT -> {
+                mBinding.et.background = if (mBinding.et.isEnabled) {
+                    AppCompatResources.getDrawable(ctx, R.drawable.selectable_input_text_bg)
+                } else {
+                    AppCompatResources.getDrawable(ctx, R.drawable.selectable_input_text_disabled_bg)
+                }
+
+                mBinding.et.setOnFocusChangeListener { view, b ->
+                    if (!b) {
+                        val imm = ctx.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
+                        imm.hideSoftInputFromWindow(view.windowToken, 0)
+                    }
+                }
+            }
+            // 日期模式
+            else -> {
+                mBinding.et.background = if (mBinding.et.isEnabled) {
+                    AppCompatResources.getDrawable(ctx, R.drawable.selectable_input_spinner_bg)
+                } else {
+                    AppCompatResources.getDrawable(ctx, R.drawable.selectable_input_spinner_disabled_bg)
+                }
+
+                mBinding.et.inputType = 0
+
+                mBinding.et.setOnClickListener {
+                    MDatePicker.create(ctx)
+                        .setCanceledTouchOutside(true)
+                        .setGravity(Gravity.CENTER)
+                        .setSupportTime(true)
+                        .setTwelveHour(false)
+                        .setOnDateResultListener {
+                            setText(SimpleDateFormat("yyyy-MM-dd").format(Date(it)))
+                        }
+                        .build().show()
+                }
+            }
+        }
+    }
+
+    fun setText(v: String?) {
+        isSkipListener = true
+        mBinding.et.setText(v)
+        v?.let {
+            mBinding.et.setSelection(it.length)
+        }
+        isSkipListener = false
+    }
+
+    fun getText(): String {
+        return mBinding.et.text.toString()
+    }
+
+    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
+            mPopWindow?.isFocusable = 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()
+                        mSelectIdx = position
+                    }
+                }
+            }
+        }
+
+        mPopWindow?.showAsDropDown(mBinding.et)
+    }
+
+    fun setOnSpinnerSelectListener(onSpinnerSelectListener: OnSpinnerSelectListener) {
+        mSelectListener = onSpinnerSelectListener
+    }
+
+    interface OnSpinnerSelectListener {
+        fun onSelect(str: String?, index: Int)
+    }
+}

+ 15 - 0
app/src/main/res/drawable/selectable_input_spinner_bg.xml

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
+    <item>
+        <shape android:shape="rectangle">
+            <solid android:color="@color/white" />
+            <corners android:radius="@dimen/selectable_input_radius" />
+        </shape>
+    </item>
+    <item
+        android:width="@dimen/selectable_input_spinner_arrow_size"
+        android:height="@dimen/selectable_input_spinner_arrow_size"
+        android:drawable="@mipmap/ic_dropdown"
+        android:gravity="end|center_vertical"
+        android:right="@dimen/selectable_input_spinner_arrow_margin" />
+</layer-list>

+ 15 - 0
app/src/main/res/drawable/selectable_input_spinner_disabled_bg.xml

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
+    <item>
+        <shape android:shape="rectangle">
+            <solid android:color="@color/common_bg_white_60" />
+            <corners android:radius="@dimen/selectable_input_radius" />
+        </shape>
+    </item>
+    <item
+        android:width="@dimen/selectable_input_spinner_arrow_size"
+        android:height="@dimen/selectable_input_spinner_arrow_size"
+        android:drawable="@mipmap/ic_dropdown"
+        android:gravity="end|center_vertical"
+        android:right="@dimen/selectable_input_spinner_arrow_margin" />
+</layer-list>

+ 6 - 0
app/src/main/res/drawable/selectable_input_text_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">
+    <solid android:color="@color/white" />
+    <corners android:radius="@dimen/selectable_input_radius" />
+</shape>

+ 6 - 0
app/src/main/res/drawable/selectable_input_text_disabled_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">
+    <solid android:color="@color/common_bg_white_60" />
+    <corners android:radius="@dimen/selectable_input_radius" />
+</shape>

+ 203 - 12
app/src/main/res/layout/item_rv_manual_replacement.xml

@@ -32,22 +32,38 @@
             android:text="@string/new_material" />
     </LinearLayout>
 
-    <com.grkj.iscs_mc.view.widget.CommonBtn
-        android:id="@+id/cb_confirm"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
+    <TextView
+        android:id="@+id/tv_confirm"
+        style="@style/CommonBtnRed"
+        android:layout_width="56dp"
+        android:layout_height="17dp"
         android:layout_alignParentRight="true"
         android:layout_alignParentBottom="true"
-        android:layout_marginVertical="@dimen/common_spacing_small"
-        android:layout_marginRight="@dimen/common_spacing_small"
-        app:btn_bg="@drawable/common_btn_red_bg"
-        app:btn_name="@string/save" />
+        android:layout_marginVertical="3dp"
+        android:layout_marginRight="3dp"
+        android:padding="0dp"
+        android:text="@string/confirm_replacement"
+        android:textSize="@dimen/common_text_size_small" />
+
+    <TextView
+        android:id="@+id/tv_reset"
+        style="@style/CommonBtnRed"
+        android:layout_width="56dp"
+        android:layout_height="17dp"
+        android:layout_alignParentBottom="true"
+        android:layout_marginVertical="3dp"
+        android:layout_marginRight="3dp"
+        android:layout_toLeftOf="@id/tv_confirm"
+        android:backgroundTint="@color/common_light_gray"
+        android:padding="0dp"
+        android:text="@string/reset_modification"
+        android:textSize="@dimen/common_text_size_small" />
 
     <View
         android:id="@+id/v_bottom_divider"
         android:layout_width="match_parent"
         android:layout_height="@dimen/divider_line_width"
-        android:layout_above="@id/cb_confirm"
+        android:layout_above="@id/tv_confirm"
         android:background="@color/main_color" />
 
     <LinearLayout
@@ -66,11 +82,11 @@
 
             <RelativeLayout
                 android:layout_width="match_parent"
-                android:layout_height="71dp">
+                android:layout_height="68dp">
 
                 <ImageView
-                    android:layout_width="50dp"
-                    android:layout_height="50dp"
+                    android:layout_width="53dp"
+                    android:layout_height="53dp"
                     android:layout_centerInParent="true" />
             </RelativeLayout>
 
@@ -79,7 +95,89 @@
                 android:layout_height="@dimen/divider_line_width"
                 android:background="@color/main_color" />
 
+            <com.grkj.iscs_mc.view.widget.SelectableInput
+                android:id="@+id/ci_name_old"
+                android:layout_width="wrap_content"
+                android:layout_height="13dp"
+                android:layout_gravity="right"
+                android:layout_marginVertical="2.2dp"
+                android:layout_marginRight="@dimen/common_spacing_small"
+                app:edit_width="85dp"
+                app:enabled="false"
+                app:name="@string/name"
+                app:required="false" />
+
+            <View
+                android:layout_width="match_parent"
+                android:layout_height="@dimen/divider_line_width"
+                android:background="@color/main_color" />
+
+            <com.grkj.iscs_mc.view.widget.SelectableInput
+                android:id="@+id/ci_type_old"
+                android:layout_width="wrap_content"
+                android:layout_height="13dp"
+                android:layout_gravity="right"
+                android:layout_marginVertical="2.2dp"
+                android:layout_marginRight="@dimen/common_spacing_small"
+                app:edit_width="85dp"
+                app:enabled="false"
+                app:mode="select"
+                app:name="@string/type"
+                app:required="false" />
+
+            <View
+                android:layout_width="match_parent"
+                android:layout_height="@dimen/divider_line_width"
+                android:background="@color/main_color" />
+
+            <com.grkj.iscs_mc.view.widget.SelectableInput
+                android:id="@+id/ci_model_old"
+                android:layout_width="wrap_content"
+                android:layout_height="13dp"
+                android:layout_gravity="right"
+                android:layout_marginVertical="2.2dp"
+                android:layout_marginRight="@dimen/common_spacing_small"
+                app:edit_width="85dp"
+                app:enabled="false"
+                app:mode="select"
+                app:name="@string/model"
+                app:required="false" />
 
+            <View
+                android:layout_width="match_parent"
+                android:layout_height="@dimen/divider_line_width"
+                android:background="@color/main_color" />
+
+            <com.grkj.iscs_mc.view.widget.SelectableInput
+                android:id="@+id/ci_rfid_old"
+                android:layout_width="wrap_content"
+                android:layout_height="13dp"
+                android:layout_gravity="right"
+                android:layout_marginVertical="2.2dp"
+                android:layout_marginRight="@dimen/common_spacing_small"
+                app:edit_width="85dp"
+                app:enabled="false"
+                app:mode="input"
+                app:name="@string/rfid"
+                app:required="false" />
+
+            <View
+                android:layout_width="match_parent"
+                android:layout_height="@dimen/divider_line_width"
+                android:background="@color/main_color" />
+
+            <com.grkj.iscs_mc.view.widget.SelectableInput
+                android:id="@+id/ci_date_old"
+                android:layout_width="wrap_content"
+                android:layout_height="13dp"
+                android:layout_gravity="right"
+                android:layout_marginVertical="2.2dp"
+                android:layout_marginRight="@dimen/common_spacing_small"
+                app:edit_width="85dp"
+                app:enabled="false"
+                app:mode="date"
+                app:name="@string/valid_date"
+                app:required="false" />
         </LinearLayout>
 
         <View
@@ -94,6 +192,99 @@
             android:layout_weight="1"
             android:orientation="vertical">
 
+            <RelativeLayout
+                android:layout_width="match_parent"
+                android:layout_height="68dp">
+
+                <ImageView
+                    android:layout_width="53dp"
+                    android:layout_height="53dp"
+                    android:layout_centerInParent="true" />
+            </RelativeLayout>
+
+            <View
+                android:layout_width="match_parent"
+                android:layout_height="@dimen/divider_line_width"
+                android:background="@color/main_color" />
+
+            <com.grkj.iscs_mc.view.widget.SelectableInput
+                android:id="@+id/ci_name_new"
+                android:layout_width="wrap_content"
+                android:layout_height="13dp"
+                android:layout_gravity="right"
+                android:layout_marginVertical="2.2dp"
+                android:layout_marginRight="@dimen/common_spacing_small"
+                app:edit_width="85dp"
+                app:name="@string/name"
+                app:required="false" />
+
+            <View
+                android:layout_width="match_parent"
+                android:layout_height="@dimen/divider_line_width"
+                android:background="@color/main_color" />
+
+            <com.grkj.iscs_mc.view.widget.SelectableInput
+                android:id="@+id/ci_type_new"
+                android:layout_width="wrap_content"
+                android:layout_height="13dp"
+                android:layout_gravity="right"
+                android:layout_marginVertical="2.2dp"
+                android:layout_marginRight="@dimen/common_spacing_small"
+                app:edit_width="85dp"
+                app:mode="select"
+                app:name="@string/type"
+                app:required="false" />
+
+            <View
+                android:layout_width="match_parent"
+                android:layout_height="@dimen/divider_line_width"
+                android:background="@color/main_color" />
+
+            <com.grkj.iscs_mc.view.widget.SelectableInput
+                android:id="@+id/ci_model_new"
+                android:layout_width="wrap_content"
+                android:layout_height="13dp"
+                android:layout_gravity="right"
+                android:layout_marginVertical="2.2dp"
+                android:layout_marginRight="@dimen/common_spacing_small"
+                app:edit_width="85dp"
+                app:mode="select"
+                app:name="@string/model"
+                app:required="false" />
+
+            <View
+                android:layout_width="match_parent"
+                android:layout_height="@dimen/divider_line_width"
+                android:background="@color/main_color" />
+
+            <com.grkj.iscs_mc.view.widget.SelectableInput
+                android:id="@+id/ci_rfid_new"
+                android:layout_width="wrap_content"
+                android:layout_height="13dp"
+                android:layout_gravity="right"
+                android:layout_marginVertical="2.2dp"
+                android:layout_marginRight="@dimen/common_spacing_small"
+                app:edit_width="85dp"
+                app:mode="input"
+                app:name="@string/rfid"
+                app:required="false" />
+
+            <View
+                android:layout_width="match_parent"
+                android:layout_height="@dimen/divider_line_width"
+                android:background="@color/main_color" />
+
+            <com.grkj.iscs_mc.view.widget.SelectableInput
+                android:id="@+id/ci_date_new"
+                android:layout_width="wrap_content"
+                android:layout_height="13dp"
+                android:layout_gravity="right"
+                android:layout_marginVertical="2.2dp"
+                android:layout_marginRight="@dimen/common_spacing_small"
+                app:edit_width="85dp"
+                app:mode="date"
+                app:name="@string/valid_date"
+                app:required="false" />
         </LinearLayout>
     </LinearLayout>
 

+ 19 - 0
app/src/main/res/layout/item_rv_selectableinput_spinner.xml

@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:layout_margin="@dimen/rv_item_margin"
+    android:background="@color/white"
+    android:orientation="horizontal">
+
+    <TextView
+        android:id="@+id/tv_option"
+        style="@style/CommonTextView"
+        android:layout_width="match_parent"
+        android:textColor="@color/black" />
+
+    <View
+        android:layout_width="match_parent"
+        android:layout_height="1dp"
+        android:background="#cccccc" />
+</LinearLayout>

+ 32 - 0
app/src/main/res/layout/layout_selectable_input.xml

@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:gravity="top"
+    android:orientation="horizontal">
+
+    <TextView
+        android:id="@+id/tv_prefix"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="@string/selectable_input_prefix"
+        android:textColor="@color/selectable_input_prefix"
+        android:textSize="@dimen/common_text_size_small" />
+
+    <TextView
+        android:id="@+id/tv_name"
+        style="@style/CommonTextView"
+        android:textSize="@dimen/common_text_size_small" />
+
+    <EditText
+        android:id="@+id/et"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_marginLeft="@dimen/common_spacing_small"
+        android:background="@drawable/selectable_input_spinner_bg"
+        android:gravity="center_vertical"
+        android:maxLines="1"
+        android:paddingLeft="@dimen/selectable_input_edit_padding"
+        android:textColor="@color/black"
+        android:textSize="@dimen/common_text_size_small" />
+</LinearLayout>

+ 10 - 0
app/src/main/res/layout/layout_selectableinput_spinner.xml

@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content">
+
+    <androidx.recyclerview.widget.RecyclerView
+        android:id="@+id/rv_options"
+        style="@style/CommonRecyclerView"
+        android:layout_height="wrap_content" />
+</RelativeLayout>

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


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

@@ -5,6 +5,20 @@
         <attr name="bar_icon" format="reference" />
     </declare-styleable>
 
+    <declare-styleable name="SelectableInput">
+        <attr name="mode">
+            <flag name="input" value="0x00000000" />
+            <flag name="select" value="0x00000001" />
+            <flag name="date" value="0x00000002" />
+        </attr>
+        <attr name="required" default="false" format="boolean" />
+        <attr name="name" format="string" />
+        <attr name="spinner_hint" format="string" />
+        <attr name="edittext_hint" format="string" />
+        <attr name="enabled" format="boolean" />
+        <attr name="edit_width" format="dimension" />
+    </declare-styleable>
+
     <declare-styleable name="CommonBtn">
         <attr name="btn_name" format="string" />
         <attr name="btn_icon" format="reference" />

+ 11 - 0
app/src/main/res/values/dimens.xml

@@ -19,6 +19,17 @@
     <dimen name="common_btn_width">150dp</dimen>
     <dimen name="common_btn_height">50dp</dimen>
 
+    <!--  输入选择控件  -->
+    <dimen name="selectable_input_width">20dp</dimen>
+    <dimen name="selectable_input_radius">2dp</dimen>
+    <dimen name="selectable_input_stroke">1dp</dimen>
+    <dimen name="selectable_input_min_height">23dp</dimen>
+    <dimen name="selectable_input_spinner_arrow_size">10dp</dimen>
+    <dimen name="selectable_input_spinner_arrow_margin">3dp</dimen>
+    <dimen name="selectable_input_edit_padding">3dp</dimen>
+
+    <dimen name="rv_item_margin">1dp</dimen>
+
     <dimen name="switch_width">46dp</dimen>
     <dimen name="switch_height">26dp</dimen>
     <dimen name="switch_radius">13dp</dimen>

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

@@ -7,6 +7,8 @@
     <string name="common_net_download">请确认网络状态正常且下载地址无误后重试!</string>
     <string name="common_download_erro_notag">下载失败!请确认文件存储位置后重试</string>
 
+    <string name="selectable_input_prefix">*</string>
+
     <string name="material_management_system">物资管理系统</string>
     <string name="material_management">物资管理</string>
     <string name="please_input_account">请输入用户名</string>
@@ -78,4 +80,11 @@
 
     <string name="old_material">旧物资</string>
     <string name="new_material">新物资</string>
+
+    <string name="name">名称</string>
+    <string name="type">类型</string>
+    <string name="model">型号</string>
+    <string name="valid_date">有效期</string>
+    <string name="confirm_replacement">确定更换</string>
+    <string name="reset_modification">重新填写</string>
 </resources>