ソースを参照

1.添加获取moca试题库module

王鹏鹏 2 年 前
コミット
bd7803fdea

+ 93 - 2
moca/src/main/java/com/yingyangfly/moca/record/RecordResultFragment.kt

@@ -1,26 +1,51 @@
 package com.yingyangfly.moca.record
 
+import android.os.Bundle
 import androidx.core.os.bundleOf
 import androidx.navigation.Navigation
 import com.yingyang.moca.R
 import com.yingyang.moca.databinding.FragmentRecordResultBinding
 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 RecordResultFragment : BaseFragment<FragmentRecordResultBinding>() {
 
-    override fun initViews() {
+    /**
+     * 问题id
+     */
+    private var questionId = 0
+    private var number = 0
+    private val choiceItemList = mutableListOf<QuestionsBean>()
+    private val adapter by lazy { ChoiceAdapter() }
 
+    override fun onCreate(savedInstanceState: Bundle?) {
+        questionId = arguments?.getInt("questionId") ?: 33
+        number = arguments?.getInt("number") ?: 1
+        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 44)
+                val bundle = bundleOf("questionId" to 44, "number" to number)
                 controller.navigate(
                     R.id.action_recordResultFragment_to_listenRecordFragment,
                     bundle
@@ -28,7 +53,18 @@ class RecordResultFragment : BaseFragment<FragmentRecordResultBinding>() {
             }
 
             btnNext.setOnSingleClickListener {
+                if (judge()) {
+                    if (number == 1) {
+                        val controller = Navigation.findNavController(it)
+                        val bundle = bundleOf("questionId" to 44, "number" to 2)
+                        controller.navigate(
+                            R.id.action_recordResultFragment_to_listenRecordFragment,
+                            bundle
+                        )
+                    } else {
 
+                    }
+                }
             }
         }
     }
@@ -36,4 +72,59 @@ class RecordResultFragment : BaseFragment<FragmentRecordResultBinding>() {
     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
+    }
 }

+ 75 - 1
moca/src/main/res/layout/fragment_record_result.xml

@@ -1,13 +1,87 @@
 <?xml version="1.0" encoding="utf-8"?>
 <layout xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:tools="http://schemas.android.com/tools"
     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/please_say_words_you_just_heard"
+            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"

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

@@ -31,4 +31,5 @@
     <string name="you_will_hea_words_please_listen_remember_please_listen_to_the_question" tools:ignore="ResourceName">下面您将听到几个词,请您仔细听并努力记住这些词,等一下要问您,请听题</string>
     <string name="previous_page" tools:ignore="ResourceName">上一页</string>
     <string name="may_i_ask_if_subjects_correctly_name_animals_picture" tools:ignore="ResourceName">请问受试者是否正确说出图中动物名称</string>
+    <string name="please_say_words_you_just_heard" tools:ignore="ResourceName">请您说出刚才听到的词</string>
 </resources>