From 979d9cff22806f213b420452ab4a68fcbaf021b6 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期一, 31 五月 2021 17:43:49 +0800
Subject: [PATCH] 1. 修复多项可能引起空指针崩溃的bug; 2. 新建子任务时默认执行人员从全体人员改为当前用户; 3. 新建子任务时默认执行时间强制固定为总任务对应的时段内,确保子任务执行时间不会超出总任务范围。

---
 app/src/main/java/cn/flightfeather/thirdapp/module/task/NewSubTaskActivity.kt |   56 +++++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 39 insertions(+), 17 deletions(-)

diff --git a/app/src/main/java/cn/flightfeather/thirdapp/module/task/NewSubTaskActivity.kt b/app/src/main/java/cn/flightfeather/thirdapp/module/task/NewSubTaskActivity.kt
index a06306c..cb40dd0 100644
--- a/app/src/main/java/cn/flightfeather/thirdapp/module/task/NewSubTaskActivity.kt
+++ b/app/src/main/java/cn/flightfeather/thirdapp/module/task/NewSubTaskActivity.kt
@@ -9,6 +9,7 @@
 import android.view.View
 import android.view.animation.AnimationUtils
 import android.widget.*
+import cn.flightfeather.thirdapp.CommonApplication
 import cn.flightfeather.thirdapp.R
 import cn.flightfeather.thirdapp.adapter.AllRecyclerViewAdapter
 import cn.flightfeather.thirdapp.bean.entity.Scense
@@ -215,19 +216,51 @@
             val tvExecDate =  findViewById<TextView>(R.id.tv_exec_date).apply {
                 text = DateFormatter.dateFormat.format(viewModel.todayTask.starttime)
             }
+
+            // fixme: 2021/5/31 鍒濆浠诲姟鎵ц鑰呴粯璁や负褰撳墠鐢ㄦ埛
+            val ids = viewModel.selectedTopTask?.executorguids?.split(Constant.CONNECTOR)
+            val userNames = viewModel.selectedTopTask?.executorusernames?.split(Constant.CONNECTOR)
+            val realNames = viewModel.selectedTopTask?.executorrealnames?.split(Constant.CONNECTOR)
+            var size = ids?.size
+            size = when {
+                userNames?.size!! > size ?: 0 -> userNames.size
+                realNames?.size!! > size ?: 0 -> realNames.size
+                else -> size
+            }
+            val mCheckedArray = BooleanArray(size ?: 0)
+
+            val id = StringBuilder()
+            val userName = StringBuilder()
+            val realName = StringBuilder()
+            for (i in ids?.indices ?: 0..0) {
+                if (CommonApplication.getInstance().currentUser.guid == ids?.get(i)) {
+                    mCheckedArray[i] = true
+                    if (id.isNotEmpty()) {
+                        id.append(Constant.CONNECTOR)
+                        userName.append(Constant.CONNECTOR)
+                        realName.append(Constant.CONNECTOR)
+                    }
+                    id.append(ids?.get(i))
+                    userName.append(userNames?.get(i))
+                    realName.append(realNames?.get(i))
+                } else {
+                    mCheckedArray[i] = false
+                }
+            }
+
             val tvTaskExecutors = findViewById<TextView>(R.id.tv_task_executors).apply {
-                text = viewModel.selectedTopTask?.executorrealnames?.replace(Constant.CONNECTOR, Constant.CONNECTOR_FOR_VIEW)
+                text = realName.toString().replace(Constant.CONNECTOR, Constant.CONNECTOR_FOR_VIEW)
             }
             viewModel.subTaskExecutor.apply {
-                this.executorGuids = viewModel.selectedTopTask?.executorguids
-                this.executorUserNames = viewModel.selectedTopTask?.executorusernames
-                this.executorRealNames = viewModel.selectedTopTask?.executorrealnames
+                this.executorGuids = ids.toString()
+                this.executorUserNames = userName.toString()
+                this.executorRealNames = realName.toString()
             }
             findViewById<LinearLayout>(R.id.ll_exec_date).setOnClickListener{
                 showDatePickerDialog(tvExecDate)
             }
             findViewById<LinearLayout>(R.id.ll_task_executors).setOnClickListener{
-                showExecutorsDialog(tvTaskExecutors)
+                showExecutorsDialog(tvTaskExecutors, mCheckedArray)
             }
         }
 
@@ -303,22 +336,11 @@
     /**
      * 鏄剧ず浠诲姟鎵ц鑰呭閫夊璇濇
      */
-    private fun showExecutorsDialog(t: TextView) {
+    private fun showExecutorsDialog(t: TextView, mCheckedArray: BooleanArray) {
         // 璁剧疆榛樿閫変腑鐨勯�夐」锛屽叏涓篺alse榛樿鍧囨湭閫変腑
         val executorGuids = viewModel.selectedTopTask?.executorguids?.split(Constant.CONNECTOR)
         val executorUNames = viewModel.selectedTopTask?.executorusernames?.split(Constant.CONNECTOR)?.toTypedArray()
         val executorRNames = viewModel.selectedTopTask?.executorrealnames?.split(Constant.CONNECTOR)?.toTypedArray()
-
-        var size = executorGuids?.size
-        size = when {
-            executorUNames?.size!! > size ?: 0 -> executorUNames.size
-            executorRNames?.size!! > size ?: 0 -> executorRNames.size
-            else -> size
-        }
-        val mCheckedArray = BooleanArray(size ?: 0)
-        for (i in mCheckedArray.indices) {
-            mCheckedArray[i] = true
-        }
 
         val multiChoiceDialog = AlertDialog.Builder(this)
         multiChoiceDialog.setTitle("閫夋嫨浠诲姟鎵ц鑰�")

--
Gitblit v1.9.3