|
@@ -8,6 +8,7 @@ import com.yingyang.mmse.R
|
|
|
import com.yingyang.mmse.databinding.FragmentCountBinding
|
|
|
import com.yingyangfly.baselib.base.BaseFragment
|
|
|
import com.yingyangfly.baselib.ext.setOnSingleClickListener
|
|
|
+import com.yingyangfly.baselib.ext.toast
|
|
|
import com.yingyangfly.mmse.adapter.NumberAdapter
|
|
|
|
|
|
/**
|
|
@@ -15,11 +16,17 @@ import com.yingyangfly.mmse.adapter.NumberAdapter
|
|
|
*/
|
|
|
class CountFragment : BaseFragment<FragmentCountBinding>() {
|
|
|
|
|
|
+ /**
|
|
|
+ * 问题id
|
|
|
+ */
|
|
|
+ var questionId = 0
|
|
|
+
|
|
|
var choiceItems = ""
|
|
|
private val numberList = mutableListOf<String>()
|
|
|
private val adapter by lazy { NumberAdapter() }
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
+ questionId = arguments?.getInt("questionId") ?: 14
|
|
|
choiceItems = arguments?.getString("choiceItems") ?: ""
|
|
|
super.onCreate(savedInstanceState)
|
|
|
}
|
|
@@ -53,12 +60,14 @@ class CountFragment : BaseFragment<FragmentCountBinding>() {
|
|
|
}
|
|
|
|
|
|
btnNext.setOnSingleClickListener {
|
|
|
- val bundle = bundleOf("questionId" to 22)
|
|
|
- val controller = Navigation.findNavController(it)
|
|
|
- controller.navigate(
|
|
|
- R.id.action_countFragment_to_recognitionImageFragment,
|
|
|
- bundle
|
|
|
- )
|
|
|
+ if (judge()) {
|
|
|
+ val bundle = bundleOf("questionId" to 22)
|
|
|
+ val controller = Navigation.findNavController(it)
|
|
|
+ controller.navigate(
|
|
|
+ R.id.action_countFragment_to_recognitionImageFragment,
|
|
|
+ bundle
|
|
|
+ )
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -76,6 +85,114 @@ class CountFragment : BaseFragment<FragmentCountBinding>() {
|
|
|
* 加载数据
|
|
|
*/
|
|
|
private fun loadData() {
|
|
|
+ if (dao != null) {
|
|
|
+ val firstquestion = dao?.getQuestion(questionId)
|
|
|
+ if (firstquestion != null) {
|
|
|
+ binding.tvResultOne.text = if (firstquestion.inputString.isNullOrEmpty()) {
|
|
|
+ ""
|
|
|
+ } else {
|
|
|
+ firstquestion.inputString
|
|
|
+ }
|
|
|
+ }
|
|
|
+ val secondQuestionnId = questionId + 1
|
|
|
+ val secondQuestion = dao?.getQuestion(secondQuestionnId)
|
|
|
+ if (secondQuestion != null) {
|
|
|
+ binding.tvResultTwo.text = if (secondQuestion.inputString.isNullOrEmpty()) {
|
|
|
+ ""
|
|
|
+ } else {
|
|
|
+ secondQuestion.inputString
|
|
|
+ }
|
|
|
+ }
|
|
|
+ val thirdQuestionId = questionId + 2
|
|
|
+ val thirdQuestion = dao?.getQuestion(thirdQuestionId)
|
|
|
+ if (thirdQuestion != null) {
|
|
|
+ binding.tvResultThree.text = if (thirdQuestion.inputString.isNullOrEmpty()) {
|
|
|
+ ""
|
|
|
+ } else {
|
|
|
+ thirdQuestion.inputString
|
|
|
+ }
|
|
|
+ }
|
|
|
+ val fourthQuestionId = questionId + 3
|
|
|
+ val fourthQuestion = dao?.getQuestion(fourthQuestionId)
|
|
|
+ if (fourthQuestion != null) {
|
|
|
+ binding.tvResultFour.text = if (fourthQuestion.inputString.isNullOrEmpty()) {
|
|
|
+ ""
|
|
|
+ } else {
|
|
|
+ fourthQuestion.inputString
|
|
|
+ }
|
|
|
+ }
|
|
|
+ val fifthQuestionId = questionId + 4
|
|
|
+ val fifthQuestion = dao?.getQuestion(fifthQuestionId)
|
|
|
+ if (fifthQuestion != null) {
|
|
|
+ binding.tvResultFive.text = if (fifthQuestion.inputString.isNullOrEmpty()) {
|
|
|
+ ""
|
|
|
+ } else {
|
|
|
+ fifthQuestion.inputString
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * 非空判断
|
|
|
+ */
|
|
|
+ private fun judge(): Boolean {
|
|
|
+ if (dao != null) {
|
|
|
+ if (binding.tvResultOne.text.toString().isNullOrEmpty()) {
|
|
|
+ "请输入第一道题目的答案".toast()
|
|
|
+ return false
|
|
|
+ } else {
|
|
|
+ val firstquestion = dao?.getQuestion(questionId)
|
|
|
+ if (firstquestion != null) {
|
|
|
+ firstquestion.inputString = binding.tvResultOne.text.toString()
|
|
|
+ dao?.update(firstquestion)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (binding.tvResultTwo.text.toString().isNullOrEmpty()) {
|
|
|
+ "请输入第二道题目的答案".toast()
|
|
|
+ return false
|
|
|
+ } else {
|
|
|
+ val secondQuestionnId = questionId + 1
|
|
|
+ val secondQuestion = dao?.getQuestion(secondQuestionnId)
|
|
|
+ if (secondQuestion != null) {
|
|
|
+ secondQuestion.inputString = binding.tvResultTwo.text.toString()
|
|
|
+ dao?.update(secondQuestion)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (binding.tvResultThree.text.toString().isNullOrEmpty()) {
|
|
|
+ "请输入第三道题目的答案".toast()
|
|
|
+ return false
|
|
|
+ } else {
|
|
|
+ val thirdQuestionId = questionId + 2
|
|
|
+ val thirdQuestion = dao?.getQuestion(thirdQuestionId)
|
|
|
+ if (thirdQuestion != null) {
|
|
|
+ thirdQuestion.inputString = binding.tvResultThree.text.toString()
|
|
|
+ dao?.update(thirdQuestion)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (binding.tvResultFour.text.toString().isNullOrEmpty()) {
|
|
|
+ "请输入第四道题目的答案".toast()
|
|
|
+ return false
|
|
|
+ } else {
|
|
|
+ val fourthQuestionId = questionId + 3
|
|
|
+ val fourthQuestion = dao?.getQuestion(fourthQuestionId)
|
|
|
+ if (fourthQuestion != null) {
|
|
|
+ fourthQuestion.inputString = binding.tvResultFour.text.toString()
|
|
|
+ dao?.update(fourthQuestion)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (binding.tvResultFive.text.toString().isNullOrEmpty()) {
|
|
|
+ "请输入第五道题目的答案".toast()
|
|
|
+ return false
|
|
|
+ } else {
|
|
|
+ val fifthQuestionId = questionId + 4
|
|
|
+ val fifthQuestion = dao?.getQuestion(fifthQuestionId)
|
|
|
+ if (fifthQuestion != null) {
|
|
|
+ fifthQuestion.inputString = binding.tvResultFive.text.toString()
|
|
|
+ dao?.update(fifthQuestion)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true
|
|
|
}
|
|
|
}
|