Browse Source

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

王鹏鹏 2 years ago
parent
commit
bfd34287f5

+ 47 - 43
mmse/src/main/java/com/yingyangfly/mmse/fragment/CountFragment.kt

@@ -1,12 +1,14 @@
 package com.yingyangfly.mmse.fragment
 
 import android.os.Bundle
+import android.util.Log
 import androidx.core.os.bundleOf
 import androidx.navigation.Navigation
 import androidx.recyclerview.widget.GridLayoutManager
 import com.yingyang.mmse.R
 import com.yingyang.mmse.databinding.FragmentCountBinding
 import com.yingyangfly.baselib.base.BaseFragment
+import com.yingyangfly.baselib.db.QuestionsBean
 import com.yingyangfly.baselib.ext.setOnSingleClickListener
 import com.yingyangfly.baselib.ext.toast
 import com.yingyangfly.mmse.adapter.NumberAdapter
@@ -25,6 +27,12 @@ class CountFragment : BaseFragment<FragmentCountBinding>() {
     private val numberList = mutableListOf<String>()
     private val adapter by lazy { NumberAdapter() }
 
+    private var firstquestion: QuestionsBean? = null
+    private var secondQuestion: QuestionsBean? = null
+    private var thirdQuestion: QuestionsBean? = null
+    private var fourthQuestion: QuestionsBean? = null
+    private var fifthQuestion: QuestionsBean? = null
+
     override fun onCreate(savedInstanceState: Bundle?) {
         questionId = arguments?.getInt("questionId") ?: 14
         choiceItems = arguments?.getString("choiceItems") ?: ""
@@ -50,7 +58,7 @@ class CountFragment : BaseFragment<FragmentCountBinding>() {
         binding {
             btnPrevious.setOnSingleClickListener {
                 val bundle = Bundle()
-                bundle.putInt("questionId", 19)
+                bundle.putInt("questionId", 11)
                 bundle.putString("choiceItems", choiceItems)
                 val controller = Navigation.findNavController(it)
                 controller.navigate(
@@ -60,14 +68,14 @@ class CountFragment : BaseFragment<FragmentCountBinding>() {
             }
 
             btnNext.setOnSingleClickListener {
-                if (judge()) {
-                    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
+                )
+//                }
             }
         }
     }
@@ -86,48 +94,53 @@ class CountFragment : BaseFragment<FragmentCountBinding>() {
      */
     private fun loadData() {
         if (dao != null) {
-            val firstquestion = dao?.getQuestion(questionId)
+            firstquestion = dao?.getQuestion(questionId)
+            Log.e("wpp", "firstquestion-----------------" + firstquestion?.inputString)
             if (firstquestion != null) {
-                binding.tvResultOne.text = if (firstquestion.inputString.isNullOrEmpty()) {
+                binding.tvResultOne.text = if (firstquestion?.inputString.isNullOrEmpty()) {
                     ""
                 } else {
-                    firstquestion.inputString
+                    firstquestion?.inputString
                 }
             }
             val secondQuestionnId = questionId + 1
-            val secondQuestion = dao?.getQuestion(secondQuestionnId)
+            secondQuestion = dao?.getQuestion(secondQuestionnId)
+            Log.e("wpp", "secondQuestion-----------------" + secondQuestion?.inputString)
             if (secondQuestion != null) {
-                binding.tvResultTwo.text = if (secondQuestion.inputString.isNullOrEmpty()) {
+                binding.tvResultTwo.text = if (secondQuestion?.inputString.isNullOrEmpty()) {
                     ""
                 } else {
-                    secondQuestion.inputString
+                    secondQuestion?.inputString
                 }
             }
             val thirdQuestionId = questionId + 2
-            val thirdQuestion = dao?.getQuestion(thirdQuestionId)
+            thirdQuestion = dao?.getQuestion(thirdQuestionId)
+            Log.e("wpp", "thirdQuestion-----------------" + thirdQuestion?.inputString)
             if (thirdQuestion != null) {
-                binding.tvResultThree.text = if (thirdQuestion.inputString.isNullOrEmpty()) {
+                binding.tvResultThree.text = if (thirdQuestion?.inputString.isNullOrEmpty()) {
                     ""
                 } else {
-                    thirdQuestion.inputString
+                    thirdQuestion?.inputString
                 }
             }
             val fourthQuestionId = questionId + 3
-            val fourthQuestion = dao?.getQuestion(fourthQuestionId)
+            fourthQuestion = dao?.getQuestion(fourthQuestionId)
+            Log.e("wpp", "fourthQuestion-----------------" + fourthQuestion?.inputString)
             if (fourthQuestion != null) {
-                binding.tvResultFour.text = if (fourthQuestion.inputString.isNullOrEmpty()) {
+                binding.tvResultFour.text = if (fourthQuestion?.inputString.isNullOrEmpty()) {
                     ""
                 } else {
-                    fourthQuestion.inputString
+                    fourthQuestion?.inputString
                 }
             }
             val fifthQuestionId = questionId + 4
-            val fifthQuestion = dao?.getQuestion(fifthQuestionId)
+            fifthQuestion = dao?.getQuestion(fifthQuestionId)
+            Log.e("wpp", "fifthQuestion-----------------" + fifthQuestion?.inputString)
             if (fifthQuestion != null) {
-                binding.tvResultFive.text = if (fifthQuestion.inputString.isNullOrEmpty()) {
+                binding.tvResultFive.text = if (fifthQuestion?.inputString.isNullOrEmpty()) {
                     ""
                 } else {
-                    fifthQuestion.inputString
+                    fifthQuestion?.inputString
                 }
             }
         }
@@ -142,54 +155,45 @@ class CountFragment : BaseFragment<FragmentCountBinding>() {
                 "请输入第一道题目的答案".toast()
                 return false
             } else {
-                val firstquestion = dao?.getQuestion(questionId)
                 if (firstquestion != null) {
-                    firstquestion.inputString = binding.tvResultOne.text.toString()
-                    dao?.update(firstquestion)
+                    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)
+                    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)
+                    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)
+                    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)
+                    fifthQuestion?.inputString = binding.tvResultFive.text.toString()
+                    dao?.update(fifthQuestion!!)
                 }
             }
         }

+ 1 - 1
mmse/src/main/java/com/yingyangfly/mmse/fragment/JudgmentFragment.kt

@@ -17,7 +17,7 @@ import com.yingyangfly.baselib.ext.toast
 class JudgmentFragment : BaseFragment<FragmentJudgmentBinding>() {
 
     /**
-     * 原始问题id
+     * 原始问题id(6.7.8.9.10) ()
      */
     var questionId = 0
 

+ 63 - 4
mmse/src/main/java/com/yingyangfly/mmse/fragment/JudgmentRecordFragment.kt

@@ -1,16 +1,35 @@
 package com.yingyangfly.mmse.fragment
 
+import android.os.Bundle
+import android.text.TextUtils
+import androidx.core.os.bundleOf
 import androidx.navigation.Navigation
 import com.yingyang.mmse.R
 import com.yingyang.mmse.databinding.FragmentJudgmentRecordBinding
 import com.yingyangfly.baselib.base.BaseFragment
+import com.yingyangfly.baselib.db.QuestionsBean
 import com.yingyangfly.baselib.ext.setOnSingleClickListener
+import com.yingyangfly.baselib.ext.toast
+import com.yingyangfly.baselib.voice.PlayVoice
 
 /**
  * 听录音重复
  */
 class JudgmentRecordFragment : BaseFragment<FragmentJudgmentRecordBinding>() {
 
+    /**
+     * 原始问题id
+     */
+    var questionId = 0
+    var question: QuestionsBean? = null
+
+    private var playVoice: PlayVoice? = null
+
+    override fun onCreate(savedInstanceState: Bundle?) {
+        questionId = arguments?.getInt("questionId") ?: 24
+        super.onCreate(savedInstanceState)
+    }
+
     override fun initViews() {
 
     }
@@ -18,16 +37,38 @@ class JudgmentRecordFragment : BaseFragment<FragmentJudgmentRecordBinding>() {
     override fun initListener() {
         binding {
             soundImage.setOnSingleClickListener {
-
+                if (question != null) {
+                    playVoice?.speak(question?.reviewDesc!!)
+                }
+            }
+            judgeRadio.setOnCheckedChangeListener { group, checkedId ->
+                if (question != null) {
+                    if (checkedId == R.id.btnDeny) {
+                        question?.inputString = "否"
+                    } else if (checkedId == R.id.btnCorrect) {
+                        question?.inputString = "是"
+                    }
+                    dao?.update(question!!)
+                }
             }
             btnPrevious.setOnSingleClickListener {
+                val bundle = bundleOf("questionId" to 22)
                 val controller = Navigation.findNavController(it)
-                controller.navigate(R.id.action_judgmentRecordFragment_to_recognitionImageFragment)
+                controller.navigate(
+                    R.id.action_judgmentRecordFragment_to_recognitionImageFragment,
+                    bundle
+                )
             }
 
             btnNext.setOnSingleClickListener {
-                val controller = Navigation.findNavController(it)
-                controller.navigate(R.id.action_judgmentRecordFragment_to_readFragment)
+                if (question != null) {
+                    if (question?.inputString.isNullOrEmpty()) {
+                        "请判断受试者的回答是否正确".toast()
+                    } else {
+                        val controller = Navigation.findNavController(it)
+                        controller.navigate(R.id.action_judgmentRecordFragment_to_readFragment)
+                    }
+                }
             }
         }
     }
@@ -35,4 +76,22 @@ class JudgmentRecordFragment : BaseFragment<FragmentJudgmentRecordBinding>() {
     override fun initData() {
 
     }
+
+    override fun onResume() {
+        super.onResume()
+        loadData()
+    }
+
+    /**
+     * 加载数据
+     */
+    private fun loadData() {
+        if (dao != null) {
+            question = dao?.getQuestion(questionId)
+            if (question != null) {
+                binding.btnDeny.isChecked = TextUtils.equals(question!!.inputString, "否")
+                binding.btnCorrect.isChecked = TextUtils.equals(question!!.inputString, "是")
+            }
+        }
+    }
 }

+ 10 - 18
mmse/src/main/java/com/yingyangfly/mmse/fragment/MultipleChoiceFragment.kt

@@ -1,6 +1,7 @@
 package com.yingyangfly.mmse.fragment
 
 import android.os.Bundle
+import android.util.Log
 import androidx.core.os.bundleOf
 import androidx.navigation.Navigation
 import com.yingyang.mmse.R
@@ -34,6 +35,7 @@ class MultipleChoiceFragment : BaseFragment<FragmentMultipleChoiceBinding>() {
             rvChoice.adapter = adapter
             adapter.onNumClickListener = { bean ->
                 if (dao != null) {
+                    Log.e("wpp", bean.reviewItem + "------------------>" + bean.inputString)
                     dao?.update(bean)
                 }
             }
@@ -47,7 +49,7 @@ class MultipleChoiceFragment : BaseFragment<FragmentMultipleChoiceBinding>() {
                     val controller = Navigation.findNavController(it)
                     controller.navigate(R.id.action_multipleChoiceFragment_to_recordActionFragment)
                 } else {
-                    val bundle = bundleOf("questionId" to questionId)
+                    val bundle = bundleOf("questionId" to 11)
                     val controller = Navigation.findNavController(it)
                     controller.navigate(
                         R.id.action_multipleChoiceFragment_to_soundRecordFragment,
@@ -85,6 +87,7 @@ class MultipleChoiceFragment : BaseFragment<FragmentMultipleChoiceBinding>() {
 
     override fun onResume() {
         super.onResume()
+        Log.e("wpp", "===================")
         loadData()
     }
 
@@ -116,23 +119,12 @@ class MultipleChoiceFragment : BaseFragment<FragmentMultipleChoiceBinding>() {
      * 非空判断
      */
     private fun judge(): Boolean {
-        if (dao != null) {
-            val firstquestion = dao?.getQuestion(questionId)
-            if (firstquestion != null && firstquestion.inputString.isNullOrEmpty()) {
-                "请判断第一道题目答案是否正确".toast()
-                return false
-            }
-            val secondQuestionnId = questionId + 1
-            val secondQuestion = dao?.getQuestion(secondQuestionnId)
-            if (secondQuestion != null && secondQuestion.inputString.isNullOrEmpty()) {
-                "请判断第二道题目答案是否正确".toast()
-                return false
-            }
-            val thirdQuestionId = questionId + 2
-            val thirdQuestion = dao?.getQuestion(thirdQuestionId)
-            if (thirdQuestion != null && thirdQuestion.inputString.isNullOrEmpty()) {
-                "请判断第三道题目答案是否正确".toast()
-                return false
+        if (choiceItemList.isNullOrEmpty().not()) {
+            choiceItemList.forEach {
+                if (it.inputString.isNullOrEmpty()) {
+                    "请判断答案是否正确".toast()
+                    return false
+                }
             }
         }
         return true

+ 2 - 1
mmse/src/main/java/com/yingyangfly/mmse/fragment/RecognitionImageFragment.kt

@@ -61,8 +61,9 @@ class RecognitionImageFragment : BaseFragment<FragmentRecognitionImageBinding>()
                     val controller = Navigation.findNavController(it)
                     controller.navigate(R.id.action_recognitionImageFragment_to_memoryWordsFragment)
                 } else {
+                    val bundle = bundleOf("questionId" to 24)
                     val controller = Navigation.findNavController(it)
-                    controller.navigate(R.id.action_recognitionImageFragment_to_judgmentRecordFragment)
+                    controller.navigate(R.id.action_recognitionImageFragment_to_judgmentRecordFragment, bundle)
                 }
             }
         }

+ 1 - 1
mmse/src/main/java/com/yingyangfly/mmse/fragment/SelectedItemFragment.kt

@@ -20,7 +20,7 @@ import com.yingyangfly.mmse.adapter.SelectedItemAdapter
 class SelectedItemFragment : BaseFragment<FragmentSelectedItemBinding>() {
 
     /**
-     * 原始问题id
+     * 原始问题id (2.3) (5)
      */
     var questionId = 0
 

+ 1 - 2
mmse/src/main/java/com/yingyangfly/mmse/fragment/SoundRecordFragment.kt

@@ -38,8 +38,7 @@ class SoundRecordFragment : BaseFragment<FragmentSoundRecordBinding>() {
     override fun initListener() {
         binding {
             btnPrevious.setOnSingleClickListener {
-                questionId--
-                val bundle = bundleOf("questionId" to questionId)
+                val bundle = bundleOf("questionId" to 10)
                 val controller = Navigation.findNavController(it)
                 controller.navigate(
                     R.id.action_soundRecordFragment_to_judgmentFragment,

+ 1 - 1
mmse/src/main/res/values/strings.xml

@@ -4,7 +4,7 @@
     <string name="next_question" tools:ignore="ResourceName">下一题</string>
     <string name="previous_question" tools:ignore="ResourceName">上一题</string>
     <string name="staff_judgment" tools:ignore="ResourceName">请工作人员判定</string>
-    <string name="determine_whether_subject_answer_correct" tools:ignore="ResourceName">判断受试者的回答是否正确</string>
+    <string name="determine_whether_subject_answer_correct" tools:ignore="ResourceName">判断受试者的回答是否正确</string>
     <string name="correct" tools:ignore="ResourceName">是</string>
     <string name="deny" tools:ignore="ResourceName">否</string>
     <string name="continues" tools:ignore="ResourceName">继续</string>