Browse Source

1.添加获取moca试题库module

王鹏鹏 2 years ago
parent
commit
fe1e76c4f6

+ 77 - 32
moca/src/main/java/com/yingyangfly/moca/numberrecords/NumberRecordsFragment.kt

@@ -9,6 +9,7 @@ import com.yingyang.moca.databinding.FragmentNumberRecordsBinding
 import com.yingyangfly.baselib.base.BaseFragment
 import com.yingyangfly.baselib.db.QuestionsBean
 import com.yingyangfly.baselib.ext.setOnSingleClickListener
+import com.yingyangfly.baselib.ext.show
 import com.yingyangfly.baselib.ext.toast
 import com.yingyangfly.moca.adapter.NumberAdapter
 
@@ -73,37 +74,62 @@ class NumberRecordsFragment : BaseFragment<FragmentNumberRecordsBinding>() {
     override fun initListener() {
         binding {
             btnPrevious.setOnSingleClickListener {
-                if (questionId == 59) {
-                    val controller = Navigation.findNavController(it)
-                    val bundle = bundleOf("questionId" to questionId)
-                    controller.navigate(
-                        R.id.action_numberRecordsFragment_to_timepieceFragment,
-                        bundle
-                    )
-                } else {
-                    val controller = Navigation.findNavController(it)
-                    val bundle = bundleOf("questionId" to 51)
-                    controller.navigate(
-                        R.id.action_numberRecordsFragment_to_memorizeNumbersFragment,
-                        bundle
-                    )
+                when (questionId) {
+                    74 -> {
+                        val controller = Navigation.findNavController(it)
+                        val bundle = bundleOf("questionId" to 67)
+                        controller.navigate(
+                            R.id.action_numberRecordsFragment_to_tipsFragment,
+                            bundle
+                        )
+                    }
+                    73, 72 -> {
+                        questionId++
+                        loadData()
+                    }
+                    59 -> {
+                        val controller = Navigation.findNavController(it)
+                        val bundle = bundleOf("questionId" to questionId)
+                        controller.navigate(
+                            R.id.action_numberRecordsFragment_to_timepieceFragment,
+                            bundle
+                        )
+                    }
+                    else -> {
+                        val controller = Navigation.findNavController(it)
+                        val bundle = bundleOf("questionId" to 51)
+                        controller.navigate(
+                            R.id.action_numberRecordsFragment_to_memorizeNumbersFragment,
+                            bundle
+                        )
+                    }
                 }
             }
             btnNext.setOnSingleClickListener {
-                if (questionId == 59) {
-                    val controller = Navigation.findNavController(it)
-                    val bundle = bundleOf("questionId" to 60)
-                    controller.navigate(
-                        R.id.action_numberRecordsFragment_to_singleChoiceFragment,
-                        bundle
-                    )
-                } else {
-                    val controller = Navigation.findNavController(it)
-                    val bundle = bundleOf("questionId" to 52)
-                    controller.navigate(
-                        R.id.action_numberRecordsFragment_to_computationFragment,
-                        bundle
-                    )
+                when (questionId) {
+                    72 -> {
+                        "判断星期".toast()
+                    }
+                    73, 74 -> {
+                        questionId--
+                        loadData()
+                    }
+                    59 -> {
+                        val controller = Navigation.findNavController(it)
+                        val bundle = bundleOf("questionId" to 60)
+                        controller.navigate(
+                            R.id.action_numberRecordsFragment_to_singleChoiceFragment,
+                            bundle
+                        )
+                    }
+                    else -> {
+                        val controller = Navigation.findNavController(it)
+                        val bundle = bundleOf("questionId" to 52)
+                        controller.navigate(
+                            R.id.action_numberRecordsFragment_to_computationFragment,
+                            bundle
+                        )
+                    }
                 }
             }
         }
@@ -122,10 +148,29 @@ class NumberRecordsFragment : BaseFragment<FragmentNumberRecordsBinding>() {
      * 加载数据
      */
     private fun loadData() {
-        binding.tvTitle.text = if (questionId == 59) {
-            "请问受试者说了"
-        } else {
-            "请问受试者错了"
+        when (questionId) {
+            72 -> {
+                binding.tvTitle.text = "今年是哪一年"
+                binding.tvTimes.show(false)
+            }
+            73 -> {
+                binding.tvTitle.text = "现在是几月"
+                binding.tvTimes.show(false)
+            }
+            74 -> {
+                binding.tvTitle.text = "今天是几号"
+                binding.tvTimes.show(false)
+            }
+            59 -> {
+                binding.tvTitle.text = "请问受试者说了"
+                binding.tvTimes.text = "个"
+                binding.tvTimes.show(true)
+            }
+            else -> {
+                binding.tvTitle.text = "请问受试者错了"
+                binding.tvTimes.text = "次"
+                binding.tvTimes.show(true)
+            }
         }
         numberList.clear()
         for (i in 1..9) {

+ 6 - 1
moca/src/main/java/com/yingyangfly/moca/tips/TipsFragment.kt

@@ -51,7 +51,12 @@ class TipsFragment : BaseFragment<FragmentTipsBinding>() {
             }
 
             btnNext.setOnSingleClickListener {
-                "今天是几号".toast()
+                val controller = Navigation.findNavController(it)
+                val bundle = bundleOf("questionId" to 74)
+                controller.navigate(
+                    R.id.action_tipsFragment_to_numberRecordsFragment,
+                    bundle
+                )
             }
         }
     }

+ 1 - 0
moca/src/main/res/layout/fragment_number_records.xml

@@ -51,6 +51,7 @@
                 android:textStyle="bold" />
 
             <androidx.appcompat.widget.AppCompatTextView
+                android:id="@+id/tvTimes"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:text="@string/time"

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

@@ -197,6 +197,10 @@
             android:id="@+id/action_numberRecordsFragment_to_singleChoiceFragment"
             app:destination="@id/singleChoiceFragment" />
 
+        <action
+            android:id="@+id/action_numberRecordsFragment_to_tipsFragment"
+            app:destination="@id/tipsFragment" />
+
     </fragment>
 
     <fragment
@@ -282,6 +286,9 @@
             android:id="@+id/action_tipsFragment_to_recordResultFragment"
             app:destination="@id/recordResultFragment" />
 
+        <action
+            android:id="@+id/action_tipsFragment_to_numberRecordsFragment"
+            app:destination="@id/numberRecordsFragment" />
 
     </fragment>
 </navigation>