Browse Source

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

王鹏鹏 2 năm trước cách đây
mục cha
commit
fd881095d8

+ 3 - 0
baselib/src/main/java/com/yingyangfly/baselib/db/QuestionsDao.kt

@@ -17,6 +17,9 @@ interface QuestionsDao : BaseDao<QuestionsBean> {
     @Query("select * from Questions where id = :id")
     fun getQuestion(id: Int): QuestionsBean
 
+    @Query("select * from Questions where reviewItem = :reviewItem")
+    fun getQuestionByReviewItem(reviewItem: String): QuestionsBean
+
     @Query("select * from Questions order by id desc ")
     fun getAllByIdDesc(): MutableList<QuestionsBean>
 

+ 10 - 0
mmse/src/main/java/com/yingyangfly/mmse/adapter/ChoiceAdapter.kt

@@ -9,7 +9,17 @@ import com.yingyangfly.baselib.adapter.BaseDataBindingAdapter
  */
 class ChoiceAdapter(override val layoutId: Int = R.layout.item_choice) :
     BaseDataBindingAdapter<String, ItemChoiceBinding>() {
+
+    var onNumClickListener: ((bean: String, type: String) -> Unit)? = null
+
     override fun onBindViewHolder(binding: ItemChoiceBinding, item: String, position: Int) {
         binding.data = item
+        binding.radioChoice.setOnCheckedChangeListener { group, checkedId ->
+            if (checkedId == R.id.radioCorrect) {
+                onNumClickListener?.invoke(item, "是")
+            } else if (checkedId == R.id.radioDeny) {
+                onNumClickListener?.invoke(item, "否")
+            }
+        }
     }
 }

+ 49 - 7
mmse/src/main/java/com/yingyangfly/mmse/fragment/MultipleChoiceFragment.kt

@@ -7,6 +7,7 @@ import com.yingyang.mmse.R
 import com.yingyang.mmse.databinding.FragmentMultipleChoiceBinding
 import com.yingyangfly.baselib.base.BaseFragment
 import com.yingyangfly.baselib.ext.setOnSingleClickListener
+import com.yingyangfly.baselib.ext.toast
 import com.yingyangfly.mmse.adapter.ChoiceAdapter
 
 /**
@@ -31,6 +32,15 @@ class MultipleChoiceFragment : BaseFragment<FragmentMultipleChoiceBinding>() {
     override fun initViews() {
         binding {
             rvChoice.adapter = adapter
+            adapter.onNumClickListener = { bean, type ->
+                if (dao != null) {
+                    val questionsBean = dao?.getQuestionByReviewItem(bean)
+                    if (questionsBean != null) {
+                        questionsBean.inputString = type
+                        dao?.update(questionsBean)
+                    }
+                }
+            }
         }
     }
 
@@ -45,13 +55,15 @@ class MultipleChoiceFragment : BaseFragment<FragmentMultipleChoiceBinding>() {
                 )
             }
             btnNext.setOnSingleClickListener {
-                val bundle = Bundle()
-                bundle.putInt("questionId", 14)
-                val controller = Navigation.findNavController(it)
-                controller.navigate(
-                    R.id.action_multipleChoiceFragment_to_countFragment,
-                    bundle
-                )
+                if (judge()) {
+                    val bundle = Bundle()
+                    bundle.putInt("questionId", 14)
+                    val controller = Navigation.findNavController(it)
+                    controller.navigate(
+                        R.id.action_multipleChoiceFragment_to_countFragment,
+                        bundle
+                    )
+                }
             }
         }
     }
@@ -86,4 +98,34 @@ class MultipleChoiceFragment : BaseFragment<FragmentMultipleChoiceBinding>() {
         }
         adapter.setData(choiceItemList)
     }
+
+    /**
+     * 非空判断
+     */
+    private fun judge(): Boolean {
+        if (dao != null) {
+            val firstquestion = dao?.getQuestion(questionId)
+            if (firstquestion != null) {
+                if (firstquestion.reviewItem.isNullOrEmpty()) {
+                    "请判断是否正确".toast()
+                    return false
+                }
+            }
+            val secondQuestion = dao?.getQuestion(12)
+            if (secondQuestion != null) {
+                if (secondQuestion.reviewItem.isNullOrEmpty()) {
+                    "请判断是否正确".toast()
+                    return false
+                }
+            }
+            val thirdQuestion = dao?.getQuestion(13)
+            if (thirdQuestion != null) {
+                if (thirdQuestion.reviewItem.isNullOrEmpty()) {
+                    "请判断是否正确".toast()
+                    return false
+                }
+            }
+        }
+        return true
+    }
 }