Quellcode durchsuchen

1.添加获取moca试题库module

王鹏鹏 vor 2 Jahren
Ursprung
Commit
b45e0bf206

+ 1 - 1
.idea/misc.xml

@@ -141,7 +141,7 @@
         <entry key="..\:/workspace/hcp-pad/moca/src/main/res/layout/fragment_number_records.xml" value="0.329232995658466" />
         <entry key="..\:/workspace/hcp-pad/moca/src/main/res/layout/fragment_record_result.xml" value="0.23697916666666666" />
         <entry key="..\:/workspace/hcp-pad/moca/src/main/res/layout/fragment_signature.xml" value="0.23697916666666666" />
-        <entry key="..\:/workspace/hcp-pad/moca/src/main/res/layout/fragment_single_choice.xml" value="0.536" />
+        <entry key="..\:/workspace/hcp-pad/moca/src/main/res/layout/fragment_single_choice.xml" value="0.264" />
         <entry key="..\:/workspace/hcp-pad/moca/src/main/res/layout/fragment_sound_record.xml" value="0.4" />
         <entry key="..\:/workspace/hcp-pad/moca/src/main/res/layout/fragment_timepiece.xml" value="0.8129032258064516" />
         <entry key="..\:/workspace/hcp-pad/moca/src/main/res/layout/fragment_tips.xml" value="0.22239583333333332" />

+ 60 - 25
moca/src/main/java/com/yingyangfly/moca/singlechoice/SingleChoiceFragment.kt

@@ -8,6 +8,7 @@ import com.yingyang.moca.databinding.FragmentSingleChoiceBinding
 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.moca.adapter.ChoiceAdapter
 
 /**
@@ -19,6 +20,7 @@ class SingleChoiceFragment : BaseFragment<FragmentSingleChoiceBinding>() {
      * 问题id
      */
     private var questionId = 0
+    private var question: QuestionsBean? = null
     private val choiceItemList = mutableListOf<QuestionsBean>()
     private val adapter by lazy { ChoiceAdapter() }
 
@@ -41,31 +43,55 @@ class SingleChoiceFragment : BaseFragment<FragmentSingleChoiceBinding>() {
     override fun initListener() {
         binding {
             btnPrevious.setOnSingleClickListener {
-                if (questionId == 60) {
-                    btnPrevious.setOnSingleClickListener {
-                        val controller = Navigation.findNavController(it)
-                        val bundle = bundleOf("questionId" to 59)
+                val controller = Navigation.findNavController(it)
+                when (questionId) {
+                    76 -> {
+                        questionId++
+                        loadData()
+                    }
+                    77 -> {
+                        val bundle = bundleOf("questionId" to questionId)
                         controller.navigate(
-                            R.id.action_singleChoiceFragment_to_numberRecordsFragment,
+                            R.id.action_singleChoiceFragment_to_weekFragment,
                             bundle
                         )
                     }
-                } else {
-                    questionId--
-                    loadData()
+                    60 -> {
+                        btnPrevious.setOnSingleClickListener {
+                            val bundle = bundleOf("questionId" to 59)
+                            controller.navigate(
+                                R.id.action_singleChoiceFragment_to_numberRecordsFragment,
+                                bundle
+                            )
+                        }
+                    }
+                    else -> {
+                        questionId--
+                        loadData()
+                    }
                 }
             }
             btnNext.setOnSingleClickListener {
-                if (questionId == 60) {
-                    questionId++
-                    loadData()
-                } else {
-                    val controller = Navigation.findNavController(it)
-                    val bundle = bundleOf("questionId" to 62)
-                    controller.navigate(
-                        R.id.action_singleChoiceFragment_to_recordresultfragment,
-                        bundle
-                    )
+                when (questionId) {
+                    60 -> {
+                        questionId++
+                        loadData()
+                    }
+                    77 -> {
+                        questionId--
+                        loadData()
+                    }
+                    76 -> {
+                        "提交信息".toast()
+                    }
+                    else -> {
+                        val controller = Navigation.findNavController(it)
+                        val bundle = bundleOf("questionId" to 62)
+                        controller.navigate(
+                            R.id.action_singleChoiceFragment_to_recordresultfragment,
+                            bundle
+                        )
+                    }
                 }
             }
         }
@@ -84,18 +110,27 @@ class SingleChoiceFragment : BaseFragment<FragmentSingleChoiceBinding>() {
      * 加载数据
      */
     private fun loadData() {
-        binding.tvTitle.text = if (questionId == 60) {
-            "下面有一些词,请您说说它们有什么相似之处,例如: 香蕉和桔他们都是水果,火车和自行车呢"
-        } else {
-            "手表和尺子呢"
-        }
         choiceItemList.clear()
         if (dao != null) {
-            val question = dao?.getQuestion(questionId)
+            question = dao?.getQuestion(questionId)
             if (question != null) {
-                choiceItemList.add(question)
+                choiceItemList.add(question!!)
             }
         }
         adapter.setData(choiceItemList)
+        binding.tvTitle.text = when (questionId) {
+            76 -> {
+                "现在您在哪个城市"
+            }
+            77 -> {
+                "我们现在是在什么地方"
+            }
+            60 -> {
+                "下面有一些词,请您说说它们有什么相似之处,例如: 香蕉和桔他们都是水果,火车和自行车呢"
+            }
+            else -> {
+                "手表和尺子呢"
+            }
+        }
     }
 }

+ 6 - 5
moca/src/main/java/com/yingyangfly/moca/week/WeekFragment.kt

@@ -64,11 +64,12 @@ class WeekFragment : BaseFragment<FragmentWeekBinding>() {
             }
 
             btnNext.setOnSingleClickListener {
-
-
-
-
-
+                val controller = Navigation.findNavController(it)
+                val bundle = bundleOf("questionId" to 77)
+                controller.navigate(
+                    R.id.action_weekFragment_to_singleChoiceFragment,
+                    bundle
+                )
             }
         }
     }

+ 9 - 0
moca/src/main/res/navigation/nav_moca.xml

@@ -279,6 +279,11 @@
         <action
             android:id="@+id/action_singleChoiceFragment_to_recordresultfragment"
             app:destination="@id/recordResultFragment" />
+
+        <action
+            android:id="@+id/action_singleChoiceFragment_to_weekFragment"
+            app:destination="@id/weekFragment" />
+
     </fragment>
 
     <fragment
@@ -305,6 +310,10 @@
             android:id="@+id/action_weekFragment_to_numberRecordsFragment"
             app:destination="@id/numberRecordsFragment" />
 
+        <action
+            android:id="@+id/action_weekFragment_to_singleChoiceFragment"
+            app:destination="@id/singleChoiceFragment" />
+
     </fragment>