Browse Source

1.添加获取moca试题库module

王鹏鹏 2 years ago
parent
commit
079c78efa6

+ 42 - 6
moca/src/main/java/com/yingyangfly/moca/drawdesign/VerifyAnswersFragment.kt

@@ -57,12 +57,15 @@ class VerifyAnswersFragment : BaseFragment<FragmentVerifyAnswersBinding>() {
             }
             btnNext.setOnSingleClickListener {
                 if (judge()) {
-                    val controller = Navigation.findNavController(it)
-                    val bundle = bundleOf("questionId" to 41)
-                    controller.navigate(
-                        R.id.action_verifyAnswersFragment_to_identifyPictureFragment,
-                        bundle
-                    )
+                    binding.rvChoice.post {
+                        updateStatus()
+                        val controller = Navigation.findNavController(it)
+                        val bundle = bundleOf("questionId" to 41)
+                        controller.navigate(
+                            R.id.action_verifyAnswersFragment_to_identifyPictureFragment,
+                            bundle
+                        )
+                    }
                 }
             }
         }
@@ -117,4 +120,37 @@ class VerifyAnswersFragment : BaseFragment<FragmentVerifyAnswersBinding>() {
         }
         return true
     }
+
+    /**
+     * 判断答案是否全部正确
+     */
+    private fun updateStatus() {
+        var isAllCorrect = true
+        if (choiceItemList.isNullOrEmpty().not()) {
+            choiceItemList.forEach {
+                if (it.correct == "0") {
+                    isAllCorrect = false
+                }
+            }
+        }
+        if (isAllCorrect.not()) {
+            choiceItemList.forEach {
+                it.reviewId = it.id
+                it.score = "0"
+                it.correct = "0"
+                if (dao != null) {
+                    dao?.update(it)
+                }
+            }
+        } else {
+            choiceItemList.forEach {
+                it.reviewId = it.id
+                it.score = it.reviewScore
+                it.correct = "1"
+                if (dao != null) {
+                    dao?.update(it)
+                }
+            }
+        }
+    }
 }

+ 42 - 6
moca/src/main/java/com/yingyangfly/moca/signature/DesignsChoiceFragment.kt

@@ -60,12 +60,48 @@ class DesignsChoiceFragment : BaseFragment<FragmentDesignsChoiceBinding>() {
             }
             btnNext.setOnSingleClickListener {
                 if (judge()) {
-                    val controller = Navigation.findNavController(it)
-                    val bundle = bundleOf("questionId" to 38)
-                    controller.navigate(
-                        R.id.action_designsChoiceFragment_to_drawDesignFragment,
-                        bundle
-                    )
+                    binding.rvChoice.post {
+                        updateStatus()
+                        val controller = Navigation.findNavController(it)
+                        val bundle = bundleOf("questionId" to 38)
+                        controller.navigate(
+                            R.id.action_designsChoiceFragment_to_drawDesignFragment,
+                            bundle
+                        )
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * 判断答案是否全部正确
+     */
+    private fun updateStatus() {
+        var isAllCorrect = true
+        if (choiceItemList.isNullOrEmpty().not()) {
+            choiceItemList.forEach {
+                if (it.correct == "0") {
+                    isAllCorrect = false
+                }
+            }
+        }
+        if (isAllCorrect.not()) {
+            choiceItemList.forEach {
+                it.reviewId = it.id
+                it.score = "0"
+                it.correct = "0"
+                if (dao != null) {
+                    dao?.update(it)
+                }
+            }
+        } else {
+            choiceItemList.forEach {
+                it.reviewId = it.id
+                it.score = it.reviewScore
+                it.correct = "1"
+                if (dao != null) {
+                    dao?.update(it)
                 }
             }
         }