|
@@ -3,6 +3,7 @@ package com.yingyangfly.moca.omputation
|
|
|
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
|
|
@@ -31,7 +32,7 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>(), View.OnT
|
|
|
private val numberList = mutableListOf<String>()
|
|
|
private val adapter by lazy { NumberAdapter() }
|
|
|
|
|
|
- private var firstquestion: QuestionsBean? = null
|
|
|
+ private var firstQuestion: QuestionsBean? = null
|
|
|
private var secondQuestion: QuestionsBean? = null
|
|
|
private var thirdQuestion: QuestionsBean? = null
|
|
|
private var fourthQuestion: QuestionsBean? = null
|
|
@@ -82,7 +83,7 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>(), View.OnT
|
|
|
delete()
|
|
|
}
|
|
|
"2" -> {
|
|
|
- save()
|
|
|
+ save(view)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -104,7 +105,7 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>(), View.OnT
|
|
|
|
|
|
private fun setOnFocusChangeListener() {
|
|
|
binding {
|
|
|
- editResultOne.setOnFocusChangeListener { v, hasFocus ->
|
|
|
+ editResultOne.setOnFocusChangeListener { _, hasFocus ->
|
|
|
questionOne = hasFocus
|
|
|
questionTwo = false
|
|
|
questionThree = false
|
|
@@ -112,7 +113,7 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>(), View.OnT
|
|
|
questionFive = false
|
|
|
}
|
|
|
|
|
|
- editResultTwo.setOnFocusChangeListener { v, hasFocus ->
|
|
|
+ editResultTwo.setOnFocusChangeListener { _, hasFocus ->
|
|
|
questionOne = false
|
|
|
questionTwo = hasFocus
|
|
|
questionThree = false
|
|
@@ -120,7 +121,7 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>(), View.OnT
|
|
|
questionFive = false
|
|
|
}
|
|
|
|
|
|
- editResultThree.setOnFocusChangeListener { v, hasFocus ->
|
|
|
+ editResultThree.setOnFocusChangeListener { _, hasFocus ->
|
|
|
questionOne = false
|
|
|
questionTwo = false
|
|
|
questionThree = hasFocus
|
|
@@ -128,7 +129,7 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>(), View.OnT
|
|
|
questionFive = false
|
|
|
}
|
|
|
|
|
|
- editResultFour.setOnFocusChangeListener { v, hasFocus ->
|
|
|
+ editResultFour.setOnFocusChangeListener { _, hasFocus ->
|
|
|
questionOne = false
|
|
|
questionTwo = false
|
|
|
questionThree = false
|
|
@@ -136,7 +137,7 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>(), View.OnT
|
|
|
questionFive = false
|
|
|
}
|
|
|
|
|
|
- editResultFive.setOnFocusChangeListener { v, hasFocus ->
|
|
|
+ editResultFive.setOnFocusChangeListener { _, hasFocus ->
|
|
|
questionOne = false
|
|
|
questionTwo = false
|
|
|
questionThree = false
|
|
@@ -148,6 +149,7 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>(), View.OnT
|
|
|
|
|
|
override fun onResume() {
|
|
|
super.onResume()
|
|
|
+ binding.editResultOne.requestFocus()
|
|
|
loadData()
|
|
|
}
|
|
|
|
|
@@ -156,15 +158,15 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>(), View.OnT
|
|
|
*/
|
|
|
private fun loadData() {
|
|
|
if (questionsDao != null) {
|
|
|
- firstquestion = questionsDao?.getQuestion(questionId)
|
|
|
- if (firstquestion != null && firstquestion!!.inputString.isNullOrEmpty().not()) {
|
|
|
+ firstQuestion = questionsDao?.getQuestion(questionId)
|
|
|
+ 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, firstQuestion!!.inputString.length - 1)
|
|
|
}
|
|
|
- stringBufferOne.append(firstquestion!!.inputString)
|
|
|
- binding.editResultOne.setText(firstquestion!!.inputString)
|
|
|
- binding.editResultOne.setSelection(firstquestion!!.inputString.length)
|
|
|
+ stringBufferOne.append(firstQuestion!!.inputString)
|
|
|
+ binding.editResultOne.setText(firstQuestion!!.inputString)
|
|
|
+ binding.editResultOne.setSelection(firstQuestion!!.inputString.length)
|
|
|
}
|
|
|
}
|
|
|
val secondQuestionId = questionId + 1
|
|
@@ -227,12 +229,12 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>(), View.OnT
|
|
|
"请输入第一道题目的答案".toast()
|
|
|
return false
|
|
|
} else {
|
|
|
- if (firstquestion != null) {
|
|
|
- firstquestion?.inputString = binding.editResultOne.text.toString().trim()
|
|
|
- firstquestion!!.reviewId = firstquestion!!.id
|
|
|
- firstquestion!!.reviewAnswer = binding.editResultOne.text.toString().trim()
|
|
|
- firstquestion!!.correct = ""
|
|
|
- questionsDao?.update(firstquestion!!)
|
|
|
+ if (firstQuestion != null) {
|
|
|
+ firstQuestion?.inputString = binding.editResultOne.text.toString().trim()
|
|
|
+ firstQuestion!!.reviewId = firstQuestion!!.id
|
|
|
+ firstQuestion!!.reviewAnswer = binding.editResultOne.text.toString().trim()
|
|
|
+ firstQuestion!!.correct = ""
|
|
|
+ questionsDao?.update(firstQuestion!!)
|
|
|
}
|
|
|
}
|
|
|
if (binding.editResultTwo.text.toString().trim().isEmpty()) {
|
|
@@ -387,51 +389,86 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>(), View.OnT
|
|
|
/**
|
|
|
* 保存数据
|
|
|
*/
|
|
|
- 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 {
|
|
|
+ binding.editResultOne.post {
|
|
|
+ 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!!)
|
|
|
+ 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 {
|
|
|
+ binding.editResultTwo.post {
|
|
|
+ if (secondQuestion != null) {
|
|
|
+ secondQuestion!!.inputString = binding.editResultTwo.toString().trim()
|
|
|
+ secondQuestion!!.reviewId = secondQuestion!!.id
|
|
|
+ secondQuestion!!.reviewAnswer = binding.editResultTwo.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 {
|
|
|
+ binding.editResultThree.post {
|
|
|
+ if (thirdQuestion != null) {
|
|
|
+ thirdQuestion!!.inputString = binding.editResultThree.toString().trim()
|
|
|
+ thirdQuestion!!.reviewId = thirdQuestion!!.id
|
|
|
+ thirdQuestion!!.reviewAnswer = binding.editResultThree.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 {
|
|
|
+ binding.editResultFour.post {
|
|
|
+ if (fourthQuestion != null) {
|
|
|
+ fourthQuestion!!.inputString = binding.editResultFour.toString().trim()
|
|
|
+ fourthQuestion!!.reviewId = fourthQuestion!!.id
|
|
|
+ fourthQuestion!!.reviewAnswer = binding.editResultFour.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 {
|
|
|
+ binding.editResultFive.post {
|
|
|
+ if (fifthQuestion != null) {
|
|
|
+ fifthQuestion!!.inputString = binding.editResultFive.toString().trim()
|
|
|
+ fifthQuestion!!.reviewId = fifthQuestion!!.id
|
|
|
+ fifthQuestion!!.reviewAnswer = binding.editResultFive.toString().trim()
|
|
|
+ fifthQuestion!!.correct = ""
|
|
|
+ questionsDao?.update(fifthQuestion!!)
|
|
|
+ pageNext(view)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|