Procházet zdrojové kódy

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

王鹏鹏 před 2 roky
rodič
revize
ba672aba42

+ 44 - 6
mmse/src/main/java/com/yingyangfly/mmse/fragment/InputFragment.kt

@@ -9,6 +9,7 @@ import com.yingyang.mmse.databinding.FragmentInputBinding
 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.mmse.adapter.NumberAdapter
 
 /**
@@ -49,6 +50,30 @@ class InputFragment : BaseFragment<FragmentInputBinding>() {
         binding.rvNum.layoutManager = GridLayoutManager(mContext, 3)
         binding.rvNum.adapter = numberAdapter
         numberAdapter.setData(numberList)
+        numberAdapter.onNumClickListener = { bean, type ->
+            when (type) {
+                "0" -> {
+                    stringBuffer.append(bean)
+                    binding.tvYear.text = stringBuffer.toString()
+
+                }
+                "1" -> {
+                    if (stringBuffer.toString().isNullOrEmpty().not()) {
+                        val size = stringBuffer.toString().length - 1
+                        stringBuffer.deleteCharAt(size)
+                        binding.tvYear.text = stringBuffer.toString()
+                    }
+                }
+                "2" -> {
+                    if (dao != null) {
+                        if (question != null) {
+                            question!!.inputString = stringBuffer.toString()
+                            dao?.update(question!!)
+                        }
+                    }
+                }
+            }
+        }
     }
 
     override fun initListener() {
@@ -66,13 +91,22 @@ class InputFragment : BaseFragment<FragmentInputBinding>() {
             }
             //下一页
             btnNext.setOnSingleClickListener { view ->
-                nextQuestionId++
-                if (nextQuestionId < 6) {
-                    loadData()
+                if (binding.tvYear.text.toString().isNullOrEmpty()) {
+                    val str = "请输入" + question!!.reviewItem
+                    str.toast()
                 } else {
-                    val bundle = bundleOf("questionId" to nextQuestionId)
-                    val controller = Navigation.findNavController(view)
-                    controller.navigate(R.id.action_inputFragment_to_judgmentFragment, bundle)
+                    if (question != null) {
+                        question!!.inputString = stringBuffer.toString()
+                        dao?.update(question!!)
+                    }
+                    nextQuestionId++
+                    if (nextQuestionId < 6) {
+                        loadData()
+                    } else {
+                        val bundle = bundleOf("questionId" to nextQuestionId)
+                        val controller = Navigation.findNavController(view)
+                        controller.navigate(R.id.action_inputFragment_to_judgmentFragment, bundle)
+                    }
                 }
             }
         }
@@ -92,6 +126,10 @@ class InputFragment : BaseFragment<FragmentInputBinding>() {
      */
     private fun loadData() {
         if (dao != null) {
+            if (stringBuffer.toString().isNullOrEmpty().not()) {
+                val length = stringBuffer.length
+                stringBuffer.delete(0, length)
+            }
             question = dao?.getQuestion(nextQuestionId)
             if (question != null) {
                 binding.data = question

+ 3 - 6
mmse/src/main/java/com/yingyangfly/mmse/fragment/YearFragment.kt

@@ -67,12 +67,9 @@ class YearFragment : BaseFragment<FragmentYearBinding>() {
                     val str = "请输入$toastInfo"
                     str.toast()
                 } else {
-                    if (dao != null) {
-                        val question = dao?.getQuestion(1)
-                        if (question != null) {
-                            question.inputString = stringBuffer.toString()
-                            dao?.update(question)
-                        }
+                    if (question != null) {
+                        question!!.inputString = stringBuffer.toString()
+                        dao?.update(question!!)
                     }
                     val bundle = bundleOf("questionId" to 2)
                     val controller = Navigation.findNavController(view)