Browse Source

1.添加获取mmse试题库UI跳转

王鹏鹏 2 years ago
parent
commit
5ee1395d80

+ 123 - 6
mmse/src/main/java/com/yingyangfly/mmse/fragment/CountFragment.kt

@@ -8,6 +8,7 @@ import com.yingyang.mmse.R
 import com.yingyang.mmse.databinding.FragmentCountBinding
 import com.yingyangfly.baselib.base.BaseFragment
 import com.yingyangfly.baselib.ext.setOnSingleClickListener
+import com.yingyangfly.baselib.ext.toast
 import com.yingyangfly.mmse.adapter.NumberAdapter
 
 /**
@@ -15,11 +16,17 @@ import com.yingyangfly.mmse.adapter.NumberAdapter
  */
 class CountFragment : BaseFragment<FragmentCountBinding>() {
 
+    /**
+     * 问题id
+     */
+    var questionId = 0
+
     var choiceItems = ""
     private val numberList = mutableListOf<String>()
     private val adapter by lazy { NumberAdapter() }
 
     override fun onCreate(savedInstanceState: Bundle?) {
+        questionId = arguments?.getInt("questionId") ?: 14
         choiceItems = arguments?.getString("choiceItems") ?: ""
         super.onCreate(savedInstanceState)
     }
@@ -53,12 +60,14 @@ class CountFragment : BaseFragment<FragmentCountBinding>() {
             }
 
             btnNext.setOnSingleClickListener {
-                val bundle = bundleOf("questionId" to 22)
-                val controller = Navigation.findNavController(it)
-                controller.navigate(
-                    R.id.action_countFragment_to_recognitionImageFragment,
-                    bundle
-                )
+                if (judge()) {
+                    val bundle = bundleOf("questionId" to 22)
+                    val controller = Navigation.findNavController(it)
+                    controller.navigate(
+                        R.id.action_countFragment_to_recognitionImageFragment,
+                        bundle
+                    )
+                }
             }
         }
     }
@@ -76,6 +85,114 @@ class CountFragment : BaseFragment<FragmentCountBinding>() {
      * 加载数据
      */
     private fun loadData() {
+        if (dao != null) {
+            val firstquestion = dao?.getQuestion(questionId)
+            if (firstquestion != null) {
+                binding.tvResultOne.text = if (firstquestion.inputString.isNullOrEmpty()) {
+                    ""
+                } else {
+                    firstquestion.inputString
+                }
+            }
+            val secondQuestionnId = questionId + 1
+            val secondQuestion = dao?.getQuestion(secondQuestionnId)
+            if (secondQuestion != null) {
+                binding.tvResultTwo.text = if (secondQuestion.inputString.isNullOrEmpty()) {
+                    ""
+                } else {
+                    secondQuestion.inputString
+                }
+            }
+            val thirdQuestionId = questionId + 2
+            val thirdQuestion = dao?.getQuestion(thirdQuestionId)
+            if (thirdQuestion != null) {
+                binding.tvResultThree.text = if (thirdQuestion.inputString.isNullOrEmpty()) {
+                    ""
+                } else {
+                    thirdQuestion.inputString
+                }
+            }
+            val fourthQuestionId = questionId + 3
+            val fourthQuestion = dao?.getQuestion(fourthQuestionId)
+            if (fourthQuestion != null) {
+                binding.tvResultFour.text = if (fourthQuestion.inputString.isNullOrEmpty()) {
+                    ""
+                } else {
+                    fourthQuestion.inputString
+                }
+            }
+            val fifthQuestionId = questionId + 4
+            val fifthQuestion = dao?.getQuestion(fifthQuestionId)
+            if (fifthQuestion != null) {
+                binding.tvResultFive.text = if (fifthQuestion.inputString.isNullOrEmpty()) {
+                    ""
+                } else {
+                    fifthQuestion.inputString
+                }
+            }
+        }
+    }
 
+    /**
+     * 非空判断
+     */
+    private fun judge(): Boolean {
+        if (dao != null) {
+            if (binding.tvResultOne.text.toString().isNullOrEmpty()) {
+                "请输入第一道题目的答案".toast()
+                return false
+            } else {
+                val firstquestion = dao?.getQuestion(questionId)
+                if (firstquestion != null) {
+                    firstquestion.inputString = binding.tvResultOne.text.toString()
+                    dao?.update(firstquestion)
+                }
+            }
+            if (binding.tvResultTwo.text.toString().isNullOrEmpty()) {
+                "请输入第二道题目的答案".toast()
+                return false
+            } else {
+                val secondQuestionnId = questionId + 1
+                val secondQuestion = dao?.getQuestion(secondQuestionnId)
+                if (secondQuestion != null) {
+                    secondQuestion.inputString = binding.tvResultTwo.text.toString()
+                    dao?.update(secondQuestion)
+                }
+            }
+            if (binding.tvResultThree.text.toString().isNullOrEmpty()) {
+                "请输入第三道题目的答案".toast()
+                return false
+            } else {
+                val thirdQuestionId = questionId + 2
+                val thirdQuestion = dao?.getQuestion(thirdQuestionId)
+                if (thirdQuestion != null) {
+                    thirdQuestion.inputString = binding.tvResultThree.text.toString()
+                    dao?.update(thirdQuestion)
+                }
+            }
+            if (binding.tvResultFour.text.toString().isNullOrEmpty()) {
+                "请输入第四道题目的答案".toast()
+                return false
+            } else {
+                val fourthQuestionId = questionId + 3
+                val fourthQuestion = dao?.getQuestion(fourthQuestionId)
+                if (fourthQuestion != null) {
+                    fourthQuestion.inputString = binding.tvResultFour.text.toString()
+                    dao?.update(fourthQuestion)
+                }
+            }
+            if (binding.tvResultFive.text.toString().isNullOrEmpty()) {
+                "请输入第五道题目的答案".toast()
+                return false
+            } else {
+                val fifthQuestionId = questionId + 4
+                val fifthQuestion = dao?.getQuestion(fifthQuestionId)
+                if (fifthQuestion != null) {
+                    fifthQuestion.inputString = binding.tvResultFive.text.toString()
+                    dao?.update(fifthQuestion)
+                }
+            }
+        }
+        return true
     }
 }

+ 6 - 4
mmse/src/main/java/com/yingyangfly/mmse/fragment/RecognitionImageFragment.kt

@@ -24,7 +24,7 @@ class RecognitionImageFragment : BaseFragment<FragmentRecognitionImageBinding>()
     private val adapter by lazy { ChoiceAdapter() }
 
     override fun onCreate(savedInstanceState: Bundle?) {
-        questionId = arguments?.getInt("questionId") ?: 11
+        questionId = arguments?.getInt("questionId") ?: 22
         super.onCreate(savedInstanceState)
     }
 
@@ -83,13 +83,15 @@ class RecognitionImageFragment : BaseFragment<FragmentRecognitionImageBinding>()
     private fun loadData() {
         choiceItemList.clear()
         if (dao != null) {
-            val firstquestion = dao?.getQuestion(22)
+            val firstquestion = dao?.getQuestion(questionId)
             if (firstquestion != null) {
+                binding.firstData = firstquestion
                 choiceItemList.add(firstquestion)
             }
-
-            val secondQuestion = dao?.getQuestion(23)
+            val secondQuestionId = questionId + 1
+            val secondQuestion = dao?.getQuestion(secondQuestionId)
             if (secondQuestion != null) {
+                binding.secondData = secondQuestion
                 choiceItemList.add(secondQuestion)
             }
         }

+ 11 - 5
mmse/src/main/res/layout/fragment_recognition_image.xml

@@ -7,7 +7,11 @@
     <data>
 
         <variable
-            name="data"
+            name="firstData"
+            type="com.yingyangfly.baselib.db.QuestionsBean" />
+
+        <variable
+            name="secondData"
             type="com.yingyangfly.baselib.db.QuestionsBean" />
     </data>
 
@@ -33,9 +37,10 @@
             android:layout_height="@dimen/divider_179px"
             android:layout_marginTop="@dimen/divider_26px"
             android:layout_marginEnd="@dimen/divider_15px"
-            android:background="@mipmap/icon_play_sound"
+            app:isCircle="@{false}"
             app:layout_constraintEnd_toStartOf="@+id/iamgeeLine"
-            app:layout_constraintTop_toBottomOf="@+id/tvTitle" />
+            app:layout_constraintTop_toBottomOf="@+id/tvTitle"
+            app:loadHeadImg="@{firstData.reviewDesc}" />
 
         <View
             android:id="@+id/iamgeeLine"
@@ -52,9 +57,10 @@
             android:layout_height="@dimen/divider_179px"
             android:layout_marginStart="@dimen/divider_15px"
             android:layout_marginTop="@dimen/divider_26px"
-            android:background="@mipmap/icon_play_sound"
+            app:isCircle="@{false}"
             app:layout_constraintStart_toEndOf="@+id/iamgeeLine"
-            app:layout_constraintTop_toBottomOf="@+id/tvTitle" />
+            app:layout_constraintTop_toBottomOf="@+id/tvTitle"
+            app:loadHeadImg="@{secondData.reviewDesc}" />
 
         <com.google.android.material.card.MaterialCardView
             android:layout_width="@dimen/divider_620px"