From dded7fe1d51cb3da855d02201ca150c9b7fd0495 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期二, 15 九月 2020 10:41:52 +0800
Subject: [PATCH] 修复一键分享功能中,整改建议 没有显示的问题

---
 app/src/main/java/cn/flightfeather/thirdapp/module/inspection/MenuProblemUpdateActivity.kt |   89 ++++++++++++++++++++++++--------------------
 1 files changed, 49 insertions(+), 40 deletions(-)

diff --git a/app/src/main/java/cn/flightfeather/thirdapp/module/inspection/MenuProblemUpdateActivity.kt b/app/src/main/java/cn/flightfeather/thirdapp/module/inspection/MenuProblemUpdateActivity.kt
index b8e0011..82d8415 100644
--- a/app/src/main/java/cn/flightfeather/thirdapp/module/inspection/MenuProblemUpdateActivity.kt
+++ b/app/src/main/java/cn/flightfeather/thirdapp/module/inspection/MenuProblemUpdateActivity.kt
@@ -71,6 +71,36 @@
         problemVo = intent.getSerializableExtra("problemlistVo") as ProblemlistVo
     }
 
+    override fun onSuggestionLoaded() {
+        super.onSuggestionLoaded()
+        if (problemVo != null && viewModel.suggestionList.value?.isNotEmpty() == true) {
+            //鏁存敼寤鸿
+            var advice = problemVo!!.advise
+            var getSuggestion = false
+            for (i in viewModel.suggestionList.value?.indices ?: 0..0) {
+                val s = viewModel.suggestionList.value?.get(i)
+                if (s != null && advice.contains(s)) {
+                    advice = advice.replace(s, "")
+                    sp_take_evidence_select_suggestion.setSelection(i)
+                    getSuggestion = true
+                    break
+                }
+            }
+            //鏁存敼寤鸿澶囨敞
+            if (getSuggestion) {
+                var suggestionRemark = advice.removeRange(0, 1)//鍒犻櫎绗竴涓瓧绗︼紝鎷彿鈥滐紙鈥�
+                suggestionRemark = suggestionRemark.dropLast(1)//鍒犻櫎鏈�鍚庝竴涓瓧绗︼紝鎷彿鈥滐級鈥�
+                et_take_evidence_suggestion.setText(suggestionRemark)
+            }
+        }
+        sp_take_evidence_select_problem_type.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
+            override fun onNothingSelected(parent: AdapterView<*>?) = Unit
+            override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
+                onProblemTypeSelected(position)
+            }
+        }
+    }
+
     override fun initObserver() {
         super.initObserver()
         viewModel.loadingOver.observe(this, Observer {
@@ -84,7 +114,6 @@
                             if (pt.guid == problemTypeId) {
                                 problemType = entry.key
                                 originProblemName = pt.name
-                                setSelectListener()
                                 return@breaking
                             }
                         }
@@ -93,6 +122,7 @@
                 for (i in viewModel.problemFatherType.value?.indices ?: 0..0) {
                     if (viewModel.problemFatherType.value?.get(i) == problemType) {
                         sp_take_evidence_select_problem_type.setSelection(i)
+                        onProblemTypeSelected(i)
                         break
                     }
                 }
@@ -124,22 +154,6 @@
                     locationRemark = locationRemark.dropLast(1)//鍒犻櫎鏈�鍚庝竴涓瓧绗︼紝鎷彿鈥滐級鈥�
                 }
                 et_take_evidence_location.setText(locationRemark)
-
-                //鏁存敼寤鸿
-                var advice = problemVo!!.advise
-                var suggestion = ""
-                for (i in viewModel.suggestionList.value?.indices ?: 0..0) {
-                    val s = viewModel.suggestionList.value?.get(i)
-                    if (s != null && advice.contains(s)) {
-                        advice = advice.replace(s, "")
-                        sp_take_evidence_select_suggestion.setSelection(i)
-                        break
-                    }
-                }
-                //鏁存敼寤鸿澶囨敞
-                var suggestionRemark = advice.removeRange(0, 1)//鍒犻櫎绗竴涓瓧绗︼紝鎷彿鈥滐紙鈥�
-                suggestionRemark = suggestionRemark.dropLast(1)//鍒犻櫎鏈�鍚庝竴涓瓧绗︼紝鎷彿鈥滐級鈥�
-                et_take_evidence_suggestion.setText(suggestionRemark)
             }
         })
 
@@ -224,31 +238,26 @@
         viewModel.deleteMediaFile(deleteMediaFileList)
     }
 
-    private fun setSelectListener() {
-        sp_take_evidence_select_problem_type.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
-            override fun onNothingSelected(parent: AdapterView<*>?) = Unit
-            override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
-                val problemType = viewModel.problemFatherType.value?.get(position)
-                viewModel.refreshProblems(problemType)
+    private fun onProblemTypeSelected(position: Int) {
+        val problemType = viewModel.problemFatherType.value?.get(position)
+        viewModel.refreshProblems(problemType)
 
-                viewModel.problemFatherType.value?.let {
-                    if (it[position] == "鎬佸害") {
-                        updateUIByProblemType(View.GONE)
-                    } else {
-                        updateUIByProblemType(View.VISIBLE)
-                    }
-                }
-
-                val problemNameList = viewModel.problemMap[problemType] ?: arrayListOf()
-                for (i in problemNameList.indices) {
-                    if (problemNameList[i].name == originProblemName) {
-                        sp_take_evidence_select_problem.setSelection(i)
-                        break
-                    }
-                }
-
-                viewModel.problemType.value?.get(0)?.guid?.let { viewModel.getSuggestionList(it) }
+        viewModel.problemFatherType.value?.let {
+            if (it[position] == "鎬佸害") {
+                updateUIByProblemType(View.GONE)
+            } else {
+                updateUIByProblemType(View.VISIBLE)
             }
         }
+
+        val problemNameList = viewModel.problemMap[problemType] ?: arrayListOf()
+        for (i in problemNameList.indices) {
+            if (problemNameList[i].name == originProblemName) {
+                sp_take_evidence_select_problem.setSelection(i)
+                break
+            }
+        }
+
+        viewModel.problemType.value?.get(0)?.guid?.let { viewModel.getSuggestionList(it) }
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3