|
|
@@ -3,6 +3,7 @@ package com.yingyangfly.mmse.fragment
|
|
|
import android.annotation.SuppressLint
|
|
|
import android.os.Build
|
|
|
import android.os.Bundle
|
|
|
+import android.text.TextUtils
|
|
|
import android.view.MotionEvent
|
|
|
import android.view.View
|
|
|
import androidx.annotation.RequiresApi
|
|
|
@@ -73,7 +74,7 @@ class CountFragment : BaseFragment<FragmentCountBinding>(), View.OnTouchListener
|
|
|
rvInput.layoutManager = GridLayoutManager(mContext, 3)
|
|
|
rvInput.adapter = adapter
|
|
|
adapter.setData(numberList)
|
|
|
- adapter.onNumClickListener = { bean: String, type: String ->
|
|
|
+ adapter.onNumClickListener = { view, bean: String, type: String ->
|
|
|
when (type) {
|
|
|
"0" -> {
|
|
|
append(bean)
|
|
|
@@ -82,7 +83,7 @@ class CountFragment : BaseFragment<FragmentCountBinding>(), View.OnTouchListener
|
|
|
delete()
|
|
|
}
|
|
|
"2" -> {
|
|
|
- save()
|
|
|
+ save(view)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -107,7 +108,7 @@ class CountFragment : BaseFragment<FragmentCountBinding>(), View.OnTouchListener
|
|
|
*/
|
|
|
private fun setOnFocusChangeListener() {
|
|
|
binding {
|
|
|
- editResultOne.setOnFocusChangeListener { v, hasFocus ->
|
|
|
+ editResultOne.setOnFocusChangeListener { _, hasFocus ->
|
|
|
questionOne = hasFocus
|
|
|
questionTwo = false
|
|
|
questionThree = false
|
|
|
@@ -115,7 +116,7 @@ class CountFragment : BaseFragment<FragmentCountBinding>(), View.OnTouchListener
|
|
|
questionFive = false
|
|
|
}
|
|
|
|
|
|
- editResultTwo.setOnFocusChangeListener { v, hasFocus ->
|
|
|
+ editResultTwo.setOnFocusChangeListener { _, hasFocus ->
|
|
|
questionOne = false
|
|
|
questionTwo = hasFocus
|
|
|
questionThree = false
|
|
|
@@ -123,7 +124,7 @@ class CountFragment : BaseFragment<FragmentCountBinding>(), View.OnTouchListener
|
|
|
questionFive = false
|
|
|
}
|
|
|
|
|
|
- editResultThree.setOnFocusChangeListener { v, hasFocus ->
|
|
|
+ editResultThree.setOnFocusChangeListener { _, hasFocus ->
|
|
|
questionOne = false
|
|
|
questionTwo = false
|
|
|
questionThree = hasFocus
|
|
|
@@ -131,7 +132,7 @@ class CountFragment : BaseFragment<FragmentCountBinding>(), View.OnTouchListener
|
|
|
questionFive = false
|
|
|
}
|
|
|
|
|
|
- editResultFour.setOnFocusChangeListener { v, hasFocus ->
|
|
|
+ editResultFour.setOnFocusChangeListener { _, hasFocus ->
|
|
|
questionOne = false
|
|
|
questionTwo = false
|
|
|
questionThree = false
|
|
|
@@ -139,7 +140,7 @@ class CountFragment : BaseFragment<FragmentCountBinding>(), View.OnTouchListener
|
|
|
questionFive = false
|
|
|
}
|
|
|
|
|
|
- editResultFive.setOnFocusChangeListener { v, hasFocus ->
|
|
|
+ editResultFive.setOnFocusChangeListener { _, hasFocus ->
|
|
|
questionOne = false
|
|
|
questionTwo = false
|
|
|
questionThree = false
|
|
|
@@ -151,6 +152,7 @@ class CountFragment : BaseFragment<FragmentCountBinding>(), View.OnTouchListener
|
|
|
|
|
|
override fun onResume() {
|
|
|
super.onResume()
|
|
|
+ binding.editResultOne.requestFocus()
|
|
|
loadData()
|
|
|
}
|
|
|
|
|
|
@@ -163,7 +165,7 @@ class CountFragment : BaseFragment<FragmentCountBinding>(), View.OnTouchListener
|
|
|
if (firstQuestion != null && firstQuestion!!.inputString.isNullOrEmpty().not()) {
|
|
|
binding.editResultOne.post {
|
|
|
if (stringBufferOne.toString().isEmpty().not()) {
|
|
|
- stringBufferOne.delete(0, firstQuestion!!.inputString.length - 1)
|
|
|
+ stringBufferOne.delete(0, stringBufferOne.length)
|
|
|
}
|
|
|
stringBufferOne.append(firstQuestion!!.inputString)
|
|
|
binding.editResultOne.setText(firstQuestion!!.inputString)
|
|
|
@@ -175,7 +177,7 @@ class CountFragment : BaseFragment<FragmentCountBinding>(), View.OnTouchListener
|
|
|
if (secondQuestion != null && secondQuestion!!.inputString.isNullOrEmpty().not()) {
|
|
|
binding.editResultTwo.post {
|
|
|
if (stringBufferTwo.toString().isEmpty().not()) {
|
|
|
- stringBufferTwo.delete(0, secondQuestion!!.inputString.length - 1)
|
|
|
+ stringBufferTwo.delete(0, stringBufferTwo.length)
|
|
|
}
|
|
|
stringBufferTwo.append(secondQuestion!!.inputString)
|
|
|
binding.editResultTwo.setText(secondQuestion!!.inputString)
|
|
|
@@ -187,7 +189,7 @@ class CountFragment : BaseFragment<FragmentCountBinding>(), View.OnTouchListener
|
|
|
if (thirdQuestion != null && thirdQuestion!!.inputString.isNullOrEmpty().not()) {
|
|
|
binding.editResultThree.post {
|
|
|
if (stringBufferThree.toString().isEmpty().not()) {
|
|
|
- stringBufferThree.delete(0, thirdQuestion!!.inputString.length - 1)
|
|
|
+ stringBufferThree.delete(0, stringBufferThree.length)
|
|
|
}
|
|
|
stringBufferThree.append(thirdQuestion!!.inputString)
|
|
|
binding.editResultThree.setText(thirdQuestion!!.inputString)
|
|
|
@@ -199,7 +201,7 @@ class CountFragment : BaseFragment<FragmentCountBinding>(), View.OnTouchListener
|
|
|
if (fourthQuestion != null && fourthQuestion!!.inputString.isNullOrEmpty().not()) {
|
|
|
binding.editResultFour.post {
|
|
|
if (stringBufferFour.toString().isEmpty().not()) {
|
|
|
- stringBufferFour.delete(0, fourthQuestion!!.inputString.length - 1)
|
|
|
+ stringBufferFour.delete(0, stringBufferFour.length)
|
|
|
}
|
|
|
stringBufferFour.append(fourthQuestion!!.inputString)
|
|
|
binding.editResultFour.setText(fourthQuestion!!.inputString)
|
|
|
@@ -210,8 +212,8 @@ class CountFragment : BaseFragment<FragmentCountBinding>(), View.OnTouchListener
|
|
|
fifthQuestion = questionsDao?.getQuestion(fifthQuestionId)
|
|
|
if (fifthQuestion != null && fifthQuestion!!.inputString.isNullOrEmpty().not()) {
|
|
|
binding.editResultFive.post {
|
|
|
- if (stringBufferFive.toString().isEmpty().not()) {
|
|
|
- stringBufferFive.delete(0, fifthQuestion!!.inputString.length - 1)
|
|
|
+ if (TextUtils.isEmpty(stringBufferFive.toString()).not()) {
|
|
|
+ stringBufferFive.delete(0, stringBufferFive.length)
|
|
|
}
|
|
|
stringBufferFive.append(fifthQuestion!!.inputString)
|
|
|
binding.editResultFive.setText(fifthQuestion!!.inputString)
|
|
|
@@ -390,51 +392,103 @@ class CountFragment : BaseFragment<FragmentCountBinding>(), View.OnTouchListener
|
|
|
/**
|
|
|
* 保存数据
|
|
|
*/
|
|
|
- private fun save() {
|
|
|
+ private fun save(view: View) {
|
|
|
if (questionsDao != null) {
|
|
|
if (questionOne) {
|
|
|
- if (firstQuestion != null) {
|
|
|
- firstQuestion!!.inputString = binding.editResultOne.toString().trim()
|
|
|
- firstQuestion!!.reviewId = firstQuestion!!.id
|
|
|
- firstQuestion!!.reviewAnswer = binding.editResultOne.toString().trim()
|
|
|
- firstQuestion!!.correct = ""
|
|
|
- questionsDao?.update(firstQuestion!!)
|
|
|
+ if (TextUtils.isEmpty(binding.editResultOne.text.toString().trim())) {
|
|
|
+ "请输入第一道题目的答案".toast()
|
|
|
+ } else {
|
|
|
+ if (firstQuestion != null) {
|
|
|
+ binding.editResultOne.post {
|
|
|
+ firstQuestion!!.inputString =
|
|
|
+ binding.editResultOne.text.toString().trim()
|
|
|
+ firstQuestion!!.reviewId = firstQuestion!!.id
|
|
|
+ firstQuestion!!.reviewAnswer =
|
|
|
+ binding.editResultOne.text.toString().trim()
|
|
|
+ firstQuestion!!.correct = ""
|
|
|
+ questionsDao?.update(firstQuestion!!)
|
|
|
+ binding.editResultTwo.requestFocus()
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
if (questionTwo) {
|
|
|
- if (secondQuestion != null) {
|
|
|
- secondQuestion!!.inputString = binding.editResultTwo.toString().trim()
|
|
|
- secondQuestion!!.reviewId = secondQuestion!!.id
|
|
|
- secondQuestion!!.reviewAnswer = binding.editResultTwo.toString().trim()
|
|
|
- secondQuestion!!.correct = ""
|
|
|
- questionsDao?.update(secondQuestion!!)
|
|
|
+ if (TextUtils.isEmpty(binding.editResultTwo.text.toString().trim())) {
|
|
|
+ "请输入第二道题目的答案".toast()
|
|
|
+ } else {
|
|
|
+ if (secondQuestion != null) {
|
|
|
+ binding.editResultTwo.post {
|
|
|
+ secondQuestion!!.inputString =
|
|
|
+ binding.editResultTwo.text.toString().trim()
|
|
|
+ secondQuestion!!.reviewId = secondQuestion!!.id
|
|
|
+ secondQuestion!!.reviewAnswer =
|
|
|
+ binding.editResultTwo.text.toString().trim()
|
|
|
+ secondQuestion!!.correct = ""
|
|
|
+ questionsDao?.update(secondQuestion!!)
|
|
|
+ binding.editResultThree.requestFocus()
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
if (questionThree) {
|
|
|
- if (thirdQuestion != null) {
|
|
|
- thirdQuestion!!.inputString = binding.editResultThree.toString().trim()
|
|
|
- thirdQuestion!!.reviewId = thirdQuestion!!.id
|
|
|
- thirdQuestion!!.reviewAnswer = binding.editResultThree.toString().trim()
|
|
|
- thirdQuestion!!.correct = ""
|
|
|
- questionsDao?.update(thirdQuestion!!)
|
|
|
+ if (TextUtils.isEmpty(binding.editResultThree.text.toString().trim())) {
|
|
|
+ "请输入第三道题目的答案".toast()
|
|
|
+ } else {
|
|
|
+ if (thirdQuestion != null) {
|
|
|
+ binding.editResultThree.post {
|
|
|
+ thirdQuestion!!.inputString =
|
|
|
+ binding.editResultThree.text.toString().trim()
|
|
|
+ thirdQuestion!!.reviewId = thirdQuestion!!.id
|
|
|
+ thirdQuestion!!.reviewAnswer =
|
|
|
+ binding.editResultThree.text.toString().trim()
|
|
|
+ thirdQuestion!!.correct = ""
|
|
|
+ questionsDao?.update(thirdQuestion!!)
|
|
|
+ binding.editResultFour.requestFocus()
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
if (questionFour) {
|
|
|
- if (fourthQuestion != null) {
|
|
|
- fourthQuestion!!.inputString = binding.editResultFour.toString().trim()
|
|
|
- fourthQuestion!!.reviewId = fourthQuestion!!.id
|
|
|
- fourthQuestion!!.reviewAnswer = binding.editResultFour.toString().trim()
|
|
|
- fourthQuestion!!.correct = ""
|
|
|
- questionsDao?.update(fourthQuestion!!)
|
|
|
+ if (TextUtils.isEmpty(binding.editResultFour.text.toString().trim())) {
|
|
|
+ "请输入第四道题目的答案".toast()
|
|
|
+ } else {
|
|
|
+ if (fourthQuestion != null) {
|
|
|
+ binding.editResultFour.post {
|
|
|
+ fourthQuestion!!.inputString =
|
|
|
+ binding.editResultFour.text.toString().trim()
|
|
|
+ fourthQuestion!!.reviewId = fourthQuestion!!.id
|
|
|
+ fourthQuestion!!.reviewAnswer =
|
|
|
+ binding.editResultFour.text.toString().trim()
|
|
|
+ fourthQuestion!!.correct = ""
|
|
|
+ questionsDao?.update(fourthQuestion!!)
|
|
|
+ binding.editResultFive.requestFocus()
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
if (questionFive) {
|
|
|
- if (fifthQuestion != null) {
|
|
|
- fifthQuestion!!.inputString = binding.editResultFive.toString().trim()
|
|
|
- fifthQuestion!!.reviewId = fifthQuestion!!.id
|
|
|
- fifthQuestion!!.reviewAnswer = binding.editResultFive.toString().trim()
|
|
|
- fifthQuestion!!.correct = ""
|
|
|
- questionsDao?.update(fifthQuestion!!)
|
|
|
+ if (TextUtils.isEmpty(binding.editResultFive.text.toString().trim())) {
|
|
|
+ "请输入第五道题目的答案".toast()
|
|
|
+ } else {
|
|
|
+ if (fifthQuestion != null) {
|
|
|
+ binding.editResultFive.post {
|
|
|
+ fifthQuestion!!.inputString =
|
|
|
+ binding.editResultFive.text.toString().trim()
|
|
|
+ fifthQuestion!!.reviewId = fifthQuestion!!.id
|
|
|
+ fifthQuestion!!.reviewAnswer =
|
|
|
+ binding.editResultFive.text.toString().trim()
|
|
|
+ fifthQuestion!!.correct = ""
|
|
|
+ questionsDao?.update(fifthQuestion!!)
|
|
|
+ if (judge()) {
|
|
|
+ val bundle = bundleOf("questionId" to 22)
|
|
|
+ val controller = Navigation.findNavController(view)
|
|
|
+ controller.navigate(
|
|
|
+ R.id.action_countFragment_to_recognitionImageFragment,
|
|
|
+ bundle
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|