Quellcode durchsuchen

1.添加获取moca试题库module

王鹏鹏 vor 2 Jahren
Ursprung
Commit
965f6ffeb4

+ 3 - 2
.idea/misc.xml

@@ -136,14 +136,15 @@
         <entry key="..\:/workspace/hcp-pad/moca/src/main/res/layout/fragment_listen_speak.xml" value="0.22239583333333332" />
         <entry key="..\:/workspace/hcp-pad/moca/src/main/res/layout/fragment_listen_speak_result.xml" value="0.23697916666666666" />
         <entry key="..\:/workspace/hcp-pad/moca/src/main/res/layout/fragment_memorize_numbers.xml" value="0.23697916666666666" />
-        <entry key="..\:/workspace/hcp-pad/moca/src/main/res/layout/fragment_memorize_result.xml" value="0.536" />
+        <entry key="..\:/workspace/hcp-pad/moca/src/main/res/layout/fragment_memorize_result.xml" value="0.4421768707482993" />
         <entry key="..\:/workspace/hcp-pad/moca/src/main/res/layout/fragment_multiple_choice.xml" value="0.23697916666666666" />
         <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.22239583333333332" />
+        <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_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" />
         <entry key="..\:/workspace/hcp-pad/moca/src/main/res/layout/fragment_verify_answers.xml" value="0.4" />
         <entry key="..\:/workspace/hcp-pad/moca/src/main/res/layout/item_choice.xml" value="0.23697916666666666" />
         <entry key="..\:/workspace/hcp-pad/moca/src/main/res/layout/item_moca_choice.xml" value="0.23697916666666666" />

+ 48 - 28
moca/src/main/java/com/yingyangfly/moca/record/RecordResultFragment.kt

@@ -42,30 +42,50 @@ class RecordResultFragment : BaseFragment<FragmentRecordResultBinding>() {
     override fun initListener() {
         binding {
             btnPrevious.setOnSingleClickListener {
-                val controller = Navigation.findNavController(it)
-                val bundle = bundleOf("questionId" to questionId)
-                controller.navigate(
-                    R.id.action_recordResultFragment_to_listenRecordFragment,
-                    bundle
-                )
+                if (questionId == 62) {
+                    val controller = Navigation.findNavController(it)
+                    val bundle = bundleOf("questionId" to 61)
+                    controller.navigate(
+                        R.id.action_recordResultFragment_to_singleChoiceFragment,
+                        bundle
+                    )
+                } else {
+                    val controller = Navigation.findNavController(it)
+                    val bundle = bundleOf("questionId" to questionId)
+                    controller.navigate(
+                        R.id.action_recordResultFragment_to_listenRecordFragment,
+                        bundle
+                    )
+                }
             }
 
             btnNext.setOnSingleClickListener {
                 if (judge()) {
-                    if (questionId == 44) {
-                        val controller = Navigation.findNavController(it)
-                        val bundle = bundleOf("questionId" to 78)
-                        controller.navigate(
-                            R.id.action_recordResultFragment_to_listenRecordFragment,
-                            bundle
-                        )
-                    } else {
-                        val controller = Navigation.findNavController(it)
-                        val bundle = bundleOf("questionId" to 49)
-                        controller.navigate(
-                            R.id.action_recordResultFragment_to_memorizeNumbersFragment,
-                            bundle
-                        )
+                    when (questionId) {
+                        62 -> {
+                            val controller = Navigation.findNavController(it)
+                            val bundle = bundleOf("questionId" to 67)
+                            controller.navigate(
+                                R.id.action_recordResultFragment_to_tipsFragment,
+                                bundle
+                            )
+                        }
+                        44 -> {
+                            val controller = Navigation.findNavController(it)
+                            val bundle = bundleOf("questionId" to 78)
+                            controller.navigate(
+                                R.id.action_recordResultFragment_to_listenRecordFragment,
+                                bundle
+                            )
+                        }
+                        else -> {
+                            val controller = Navigation.findNavController(it)
+                            val bundle = bundleOf("questionId" to 49)
+                            controller.navigate(
+                                R.id.action_recordResultFragment_to_memorizeNumbersFragment,
+                                bundle
+                            )
+                        }
                     }
                 }
             }
@@ -120,14 +140,14 @@ class RecordResultFragment : BaseFragment<FragmentRecordResultBinding>() {
      * 非空判断
      */
     private fun judge(): Boolean {
-        if (choiceItemList.isNullOrEmpty().not()) {
-            choiceItemList.forEach {
-                if (it.inputString.isNullOrEmpty()) {
-                    "请判断答案是否正确".toast()
-                    return false
-                }
-            }
-        }
+//        if (choiceItemList.isNullOrEmpty().not()) {
+//            choiceItemList.forEach {
+//                if (it.inputString.isNullOrEmpty()) {
+//                    "请判断答案是否正确".toast()
+//                    return false
+//                }
+//            }
+//        }
         return true
     }
 }

+ 74 - 3
moca/src/main/java/com/yingyangfly/moca/singlechoice/SingleChoiceFragment.kt

@@ -1,25 +1,72 @@
 package com.yingyangfly.moca.singlechoice
 
+import android.os.Bundle
+import androidx.core.os.bundleOf
+import androidx.navigation.Navigation
+import com.yingyang.moca.R
 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.moca.adapter.ChoiceAdapter
 
 /**
  * 单选
  */
 class SingleChoiceFragment : BaseFragment<FragmentSingleChoiceBinding>() {
 
-    override fun initViews() {
+    /**
+     * 问题id
+     */
+    private var questionId = 0
+    private val choiceItemList = mutableListOf<QuestionsBean>()
+    private val adapter by lazy { ChoiceAdapter() }
+
+    override fun onCreate(savedInstanceState: Bundle?) {
+        questionId = arguments?.getInt("questionId") ?: 60
+        super.onCreate(savedInstanceState)
+    }
 
+    override fun initViews() {
+        binding {
+            rvChoice.adapter = adapter
+            adapter.onNumClickListener = {
+                if (dao != null) {
+                    dao?.update(it)
+                }
+            }
+        }
     }
 
     override fun initListener() {
         binding {
             btnPrevious.setOnSingleClickListener {
-
+                if (questionId == 60) {
+                    btnPrevious.setOnSingleClickListener {
+                        val controller = Navigation.findNavController(it)
+                        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
+                    )
+                }
             }
         }
     }
@@ -27,4 +74,28 @@ class SingleChoiceFragment : BaseFragment<FragmentSingleChoiceBinding>() {
     override fun initData() {
 
     }
+
+    override fun onResume() {
+        super.onResume()
+        loadData()
+    }
+
+    /**
+     * 加载数据
+     */
+    private fun loadData() {
+        binding.tvTitle.text = if (questionId == 60) {
+            "下面有一些词,请您说说它们有什么相似之处,例如: 香蕉和桔他们都是水果,火车和自行车呢"
+        } else {
+            "手表和尺子呢"
+        }
+        choiceItemList.clear()
+        if (dao != null) {
+            val question = dao?.getQuestion(questionId)
+            if (question != null) {
+                choiceItemList.add(question)
+            }
+        }
+        adapter.setData(choiceItemList)
+    }
 }

+ 3 - 0
moca/src/main/java/com/yingyangfly/moca/timepiece/TimepieceFragment.kt

@@ -15,6 +15,7 @@ import com.yingyangfly.baselib.utils.RxTimer
 class TimepieceFragment : BaseFragment<FragmentTimepieceBinding>() {
 
     lateinit var rxTimer: RxTimer
+    private var seconds: Long = 0
 
     override fun initViews() {
         rxTimer = RxTimer()
@@ -29,6 +30,7 @@ class TimepieceFragment : BaseFragment<FragmentTimepieceBinding>() {
                 val time = 59.toLong()
                 rxTimer.interval(m) {
                     if (it < time) {
+                        seconds = it + 1
                         val second = it + 1
                         tvSecond.text = if (second < 9) {
                             "0$second"
@@ -36,6 +38,7 @@ class TimepieceFragment : BaseFragment<FragmentTimepieceBinding>() {
                             second.toString()
                         }
                     } else {
+                        seconds = 0
                         tvMinute.text = "01"
                         tvSecond.text = "00"
                         rxTimer.cancel()

+ 117 - 0
moca/src/main/java/com/yingyangfly/moca/tips/TipsFragment.kt

@@ -0,0 +1,117 @@
+package com.yingyangfly.moca.tips
+
+import android.os.Bundle
+import androidx.core.os.bundleOf
+import androidx.navigation.Navigation
+import com.yingyang.moca.R
+import com.yingyang.moca.databinding.FragmentTipsBinding
+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
+
+/**
+ * 特别提示
+ */
+class TipsFragment : BaseFragment<FragmentTipsBinding>() {
+
+    /**
+     * 问题id
+     */
+    private var questionId = 0
+    private val choiceItemList = mutableListOf<QuestionsBean>()
+    private val adapter by lazy { ChoiceAdapter() }
+
+    override fun onCreate(savedInstanceState: Bundle?) {
+        questionId = arguments?.getInt("questionId") ?: 67
+        super.onCreate(savedInstanceState)
+    }
+
+    override fun initViews() {
+        binding {
+            rvChoice.adapter = adapter
+            adapter.onNumClickListener = {
+                if (dao != null) {
+                    dao?.update(it)
+                }
+            }
+        }
+    }
+
+    override fun initListener() {
+        binding {
+            btnPrevious.setOnSingleClickListener {
+                val controller = Navigation.findNavController(it)
+                val bundle = bundleOf("questionId" to 62)
+                controller.navigate(
+                    R.id.action_tipsFragment_to_recordResultFragment,
+                    bundle
+                )
+            }
+
+            btnNext.setOnSingleClickListener {
+                "今天是几号".toast()
+            }
+        }
+    }
+
+    override fun initData() {
+
+    }
+
+    override fun onResume() {
+        super.onResume()
+        loadData()
+    }
+
+    /**
+     * 加载数据
+     */
+    private fun loadData() {
+        choiceItemList.clear()
+        if (dao != null) {
+            val firstquestion = dao?.getQuestion(questionId)
+            if (firstquestion != null) {
+                choiceItemList.add(firstquestion)
+            }
+            val secondQuestionnId = questionId + 1
+            val secondQuestion = dao?.getQuestion(secondQuestionnId)
+            if (secondQuestion != null) {
+                choiceItemList.add(secondQuestion)
+            }
+            val thirdQuestionId = questionId + 2
+            val thirdQuestion = dao?.getQuestion(thirdQuestionId)
+            if (thirdQuestion != null) {
+                choiceItemList.add(thirdQuestion)
+            }
+            val fourthQuestionId = questionId + 3
+            val fourthQuestion = dao?.getQuestion(fourthQuestionId)
+            if (fourthQuestion != null) {
+                choiceItemList.add(fourthQuestion)
+            }
+
+            val fifthQuestionId = questionId + 4
+            val fifthQuestion = dao?.getQuestion(fifthQuestionId)
+            if (fifthQuestion != null) {
+                choiceItemList.add(fifthQuestion)
+            }
+        }
+        adapter.setData(choiceItemList)
+    }
+
+    /**
+     * 非空判断
+     */
+    private fun judge(): Boolean {
+        if (choiceItemList.isNullOrEmpty().not()) {
+            choiceItemList.forEach {
+                if (it.inputString.isNullOrEmpty()) {
+                    "请判断答案是否正确".toast()
+                    return false
+                }
+            }
+        }
+        return true
+    }
+}

+ 81 - 0
moca/src/main/res/layout/fragment_single_choice.xml

@@ -4,10 +4,91 @@
     xmlns:tools="http://schemas.android.com/tools"
     tools:ignore="ResourceName">
 
+    <data>
+
+        <variable
+            name="data"
+            type="com.yingyangfly.baselib.db.QuestionsBean" />
+    </data>
+
     <androidx.constraintlayout.widget.ConstraintLayout
         android:layout_width="match_parent"
         android:layout_height="match_parent">
 
+        <TextView
+            android:id="@+id/tvTitle"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginStart="@dimen/divider_202px"
+            android:layout_marginTop="@dimen/divider_53px"
+            android:layout_marginEnd="@dimen/divider_202px"
+            android:gravity="center"
+            android:text="@string/here_are_some_words_please_tell_me_what_similarities_they_have"
+            android:textColor="@color/color_FF222222"
+            android:textSize="@dimen/divider_34px"
+            android:textStyle="bold"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toTopOf="parent" />
+
+        <com.google.android.material.card.MaterialCardView
+            android:id="@+id/contentLayout"
+            android:layout_width="wrap_content"
+            android:layout_height="@dimen/divider_175px"
+            android:layout_marginTop="@dimen/divider_32px"
+            android:minWidth="@dimen/divider_620px"
+            android:theme="@style/Theme.MaterialComponents.NoActionBar"
+            app:cardBackgroundColor="@android:color/white"
+            app:cardCornerRadius="@dimen/divider_20px"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toBottomOf="@+id/tvTitle"
+            app:strokeColor="@color/color_FF979797"
+            app:strokeWidth="@dimen/divider_1px">
+
+            <LinearLayout
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:gravity="center_vertical"
+                android:orientation="horizontal">
+
+                <LinearLayout
+                    android:layout_width="@dimen/divider_191px"
+                    android:layout_height="match_parent"
+                    android:background="@color/color_FF4A76FF"
+                    android:gravity="center"
+                    android:orientation="vertical">
+
+                    <androidx.appcompat.widget.AppCompatImageView
+                        android:layout_width="@dimen/divider_65px"
+                        android:layout_height="@dimen/divider_86px"
+                        android:layout_gravity="center"
+                        android:background="@mipmap/icon_doctor_head" />
+
+                    <androidx.appcompat.widget.AppCompatTextView
+                        android:id="@+id/tvYear"
+                        android:layout_width="match_parent"
+                        android:layout_height="wrap_content"
+                        android:layout_marginTop="@dimen/divider_18px"
+                        android:background="@color/color_FF4A76FF"
+                        android:gravity="center_horizontal"
+                        android:text="@string/staff_judgment"
+                        android:textColor="@android:color/white"
+                        android:textSize="@dimen/divider_24px" />
+
+                </LinearLayout>
+
+                <androidx.recyclerview.widget.RecyclerView
+                    android:id="@+id/rvChoice"
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:layout_gravity="center_vertical"
+                    android:layout_marginTop="@dimen/divider_15px"
+                    android:layout_marginBottom="@dimen/divider_23px"
+                    app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
+
+            </LinearLayout>
+        </com.google.android.material.card.MaterialCardView>
 
         <androidx.appcompat.widget.AppCompatButton
             android:id="@+id/btnPrevious"

+ 119 - 0
moca/src/main/res/layout/fragment_tips.xml

@@ -0,0 +1,119 @@
+<?xml version="1.0" encoding="utf-8"?>
+<layout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
+    tools:ignore="ResourceName">
+
+    <androidx.constraintlayout.widget.ConstraintLayout
+        android:layout_width="match_parent"
+        android:layout_height="match_parent">
+
+        <TextView
+            android:id="@+id/tvTitle"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginStart="@dimen/divider_202px"
+            android:layout_marginTop="@dimen/divider_53px"
+            android:layout_marginEnd="@dimen/divider_200px"
+            android:gravity="center"
+            android:text="@string/now_for_category_tips_can_you_recall_words_memorized_before"
+            android:textColor="@color/color_FF222222"
+            android:textSize="@dimen/divider_34px"
+            android:textStyle="bold"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toTopOf="parent" />
+
+        <com.google.android.material.card.MaterialCardView
+            android:id="@+id/contentLayout"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginTop="@dimen/divider_32px"
+            android:minWidth="@dimen/divider_620px"
+            android:minHeight="@dimen/divider_264px"
+            android:theme="@style/Theme.MaterialComponents.NoActionBar"
+            app:cardBackgroundColor="@android:color/white"
+            app:cardCornerRadius="@dimen/divider_20px"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toBottomOf="@+id/tvTitle"
+            app:strokeColor="@color/color_FF979797"
+            app:strokeWidth="@dimen/divider_1px">
+
+            <LinearLayout
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:gravity="center_vertical"
+                android:orientation="horizontal">
+
+                <LinearLayout
+                    android:layout_width="@dimen/divider_191px"
+                    android:layout_height="match_parent"
+                    android:background="@color/color_FF4A76FF"
+                    android:gravity="center"
+                    android:orientation="vertical">
+
+                    <androidx.appcompat.widget.AppCompatImageView
+                        android:layout_width="@dimen/divider_65px"
+                        android:layout_height="@dimen/divider_86px"
+                        android:layout_gravity="center"
+                        android:background="@mipmap/icon_doctor_head" />
+
+                    <androidx.appcompat.widget.AppCompatTextView
+                        android:id="@+id/tvYear"
+                        android:layout_width="match_parent"
+                        android:layout_height="wrap_content"
+                        android:layout_marginTop="@dimen/divider_31px"
+                        android:background="@color/color_FF4A76FF"
+                        android:gravity="center_horizontal"
+                        android:text="@string/staff_judgment"
+                        android:textColor="@android:color/white"
+                        android:textSize="@dimen/divider_24px" />
+
+                </LinearLayout>
+
+                <androidx.recyclerview.widget.RecyclerView
+                    android:id="@+id/rvChoice"
+                    android:layout_width="match_parent"
+                    android:layout_height="match_parent"
+                    android:layout_marginTop="@dimen/divider_15px"
+                    android:layout_marginBottom="@dimen/divider_23px"
+                    app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
+
+            </LinearLayout>
+        </com.google.android.material.card.MaterialCardView>
+
+        <androidx.appcompat.widget.AppCompatButton
+            android:id="@+id/btnPrevious"
+            android:layout_width="@dimen/divider_240px"
+            android:layout_height="@dimen/divider_68px"
+            android:layout_marginStart="@dimen/divider_307px"
+            android:layout_marginBottom="@dimen/divider_60px"
+            android:background="@drawable/bg_previous_question"
+            android:gravity="center"
+            android:text="@string/previous_page"
+            android:textColor="@color/color_FF4A76FF"
+            android:textSize="@dimen/divider_28px"
+            android:textStyle="bold"
+            app:layout_constraintBottom_toBottomOf="parent"
+            app:layout_constraintStart_toStartOf="parent" />
+
+        <androidx.appcompat.widget.AppCompatButton
+            android:id="@+id/btnNext"
+            android:layout_width="@dimen/divider_240px"
+            android:layout_height="@dimen/divider_68px"
+            android:layout_marginEnd="@dimen/divider_305px"
+            android:layout_marginBottom="@dimen/divider_60px"
+            android:background="@drawable/bg_next_question"
+            android:gravity="center"
+            android:text="@string/continues"
+            android:textColor="@android:color/white"
+            android:textSize="@dimen/divider_28px"
+            android:textStyle="bold"
+            app:layout_constraintBottom_toBottomOf="parent"
+            app:layout_constraintEnd_toEndOf="parent" />
+
+
+    </androidx.constraintlayout.widget.ConstraintLayout>
+
+</layout>

+ 21 - 1
moca/src/main/res/navigation/nav_moca.xml

@@ -137,6 +137,13 @@
             android:id="@+id/action_recordResultFragment_to_memorizeNumbersFragment"
             app:destination="@id/memorizeNumbersFragment" />
 
+        <action
+            android:id="@+id/action_recordResultFragment_to_singleChoiceFragment"
+            app:destination="@id/singleChoiceFragment" />
+
+        <action
+            android:id="@+id/action_recordResultFragment_to_tipsFragment"
+            app:destination="@id/tipsFragment" />
     </fragment>
 
     <fragment
@@ -254,14 +261,27 @@
 
     <fragment
         android:id="@+id/singleChoiceFragment"
-        android:name="com.yingyangfly.moca.signature.SignatureFragment"
+        android:name="com.yingyangfly.moca.singlechoice.SingleChoiceFragment"
         android:label="singleChoiceFragment">
 
         <action
             android:id="@+id/action_singleChoiceFragment_to_numberRecordsFragment"
             app:destination="@id/numberRecordsFragment" />
 
+        <action
+            android:id="@+id/action_singleChoiceFragment_to_recordresultfragment"
+            app:destination="@id/recordResultFragment" />
     </fragment>
 
+    <fragment
+        android:id="@+id/tipsFragment"
+        android:name="com.yingyangfly.moca.tips.TipsFragment"
+        android:label="tipsFragment">
+
+        <action
+            android:id="@+id/action_tipsFragment_to_recordResultFragment"
+            app:destination="@id/recordResultFragment" />
+
 
+    </fragment>
 </navigation>

+ 2 - 0
moca/src/main/res/values/strings.xml

@@ -44,4 +44,6 @@
     <string name="zero_zero" tools:ignore="ResourceName">00</string>
     <string name="colon" tools:ignore="ResourceName">:</string>
     <string name="resetting" tools:ignore="ResourceName">复位</string>
+    <string name="here_are_some_words_please_tell_me_what_similarities_they_have" tools:ignore="ResourceName">下面有一些词,请您说说它们有什么相似之处,例如: 香蕉和桔他们都是水果,火车和自行车呢</string>
+    <string name="now_for_category_tips_can_you_recall_words_memorized_before" tools:ignore="ResourceName">现在给您类别提示,您能回忆出来之前记过的词吗</string>
 </resources>