|
@@ -15,7 +15,6 @@ import com.yingyangfly.baselib.base.BaseFragment
|
|
|
import com.yingyangfly.baselib.db.QuestionsBean
|
|
|
import com.yingyangfly.baselib.ext.getEndAnimation
|
|
|
import com.yingyangfly.baselib.ext.getScaleAnimation
|
|
|
-import com.yingyangfly.baselib.ext.setOnSingleClickListener
|
|
|
import com.yingyangfly.baselib.ext.toast
|
|
|
import com.yingyangfly.mmse.adapter.NumberAdapter
|
|
|
|
|
@@ -27,13 +26,12 @@ class CountFragment : BaseFragment<FragmentCountBinding>(), View.OnTouchListener
|
|
|
/**
|
|
|
* 问题id
|
|
|
*/
|
|
|
- var questionId = 0
|
|
|
-
|
|
|
- var choiceItems = ""
|
|
|
+ private var questionId = 0
|
|
|
+ private var choiceItems = ""
|
|
|
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
|
|
@@ -113,22 +111,22 @@ class CountFragment : BaseFragment<FragmentCountBinding>(), View.OnTouchListener
|
|
|
*/
|
|
|
private fun loadData() {
|
|
|
if (dao != null) {
|
|
|
- firstquestion = dao?.getQuestion(questionId)
|
|
|
- if (firstquestion != null && firstquestion!!.inputString.isNullOrEmpty().not()) {
|
|
|
+ firstQuestion = dao?.getQuestion(questionId)
|
|
|
+ if (firstQuestion != null && firstQuestion!!.inputString.isNullOrEmpty().not()) {
|
|
|
binding.editResultOne.post {
|
|
|
- if (stringBufferOne.toString().isNullOrEmpty().not()) {
|
|
|
- stringBufferOne.delete(0, firstquestion!!.inputString.length - 1)
|
|
|
+ if (stringBufferOne.toString().isEmpty().not()) {
|
|
|
+ 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 secondQuestionnId = questionId + 1
|
|
|
secondQuestion = dao?.getQuestion(secondQuestionnId)
|
|
|
if (secondQuestion != null && secondQuestion!!.inputString.isNullOrEmpty().not()) {
|
|
|
binding.editResultTwo.post {
|
|
|
- if (stringBufferTwo.toString().isNullOrEmpty().not()) {
|
|
|
+ if (stringBufferTwo.toString().isEmpty().not()) {
|
|
|
stringBufferTwo.delete(0, secondQuestion!!.inputString.length - 1)
|
|
|
}
|
|
|
stringBufferTwo.append(secondQuestion!!.inputString)
|
|
@@ -140,7 +138,7 @@ class CountFragment : BaseFragment<FragmentCountBinding>(), View.OnTouchListener
|
|
|
thirdQuestion = dao?.getQuestion(thirdQuestionId)
|
|
|
if (thirdQuestion != null && thirdQuestion!!.inputString.isNullOrEmpty().not()) {
|
|
|
binding.editResultThree.post {
|
|
|
- if (stringBufferThree.toString().isNullOrEmpty().not()) {
|
|
|
+ if (stringBufferThree.toString().isEmpty().not()) {
|
|
|
stringBufferThree.delete(0, thirdQuestion!!.inputString.length - 1)
|
|
|
}
|
|
|
stringBufferThree.append(thirdQuestion!!.inputString)
|
|
@@ -152,7 +150,7 @@ class CountFragment : BaseFragment<FragmentCountBinding>(), View.OnTouchListener
|
|
|
fourthQuestion = dao?.getQuestion(fourthQuestionId)
|
|
|
if (fourthQuestion != null && fourthQuestion!!.inputString.isNullOrEmpty().not()) {
|
|
|
binding.editResultFour.post {
|
|
|
- if (stringBufferFour.toString().isNullOrEmpty().not()) {
|
|
|
+ if (stringBufferFour.toString().isEmpty().not()) {
|
|
|
stringBufferFour.delete(0, fourthQuestion!!.inputString.length - 1)
|
|
|
}
|
|
|
stringBufferFour.append(fourthQuestion!!.inputString)
|
|
@@ -164,7 +162,7 @@ class CountFragment : BaseFragment<FragmentCountBinding>(), View.OnTouchListener
|
|
|
fifthQuestion = dao?.getQuestion(fifthQuestionId)
|
|
|
if (fifthQuestion != null && fifthQuestion!!.inputString.isNullOrEmpty().not()) {
|
|
|
binding.editResultFive.post {
|
|
|
- if (stringBufferFive.toString().isNullOrEmpty().not()) {
|
|
|
+ if (stringBufferFive.toString().isEmpty().not()) {
|
|
|
stringBufferFive.delete(0, fifthQuestion!!.inputString.length - 1)
|
|
|
}
|
|
|
stringBufferFive.append(fifthQuestion!!.inputString)
|
|
@@ -180,7 +178,7 @@ class CountFragment : BaseFragment<FragmentCountBinding>(), View.OnTouchListener
|
|
|
*/
|
|
|
private fun judge(): Boolean {
|
|
|
if (dao != null) {
|
|
|
- if (binding.editResultOne.text.toString().trim().isNullOrEmpty()) {
|
|
|
+ if (binding.editResultOne.text.toString().trim().isEmpty()) {
|
|
|
"请输入第一道题目的答案".toast()
|
|
|
binding.editResultOne.requestFocus()
|
|
|
binding.editResultOne.isFocusable = true
|
|
@@ -191,15 +189,15 @@ class CountFragment : BaseFragment<FragmentCountBinding>(), View.OnTouchListener
|
|
|
)
|
|
|
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 = ""
|
|
|
- dao?.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 = ""
|
|
|
+ dao?.update(firstQuestion!!)
|
|
|
}
|
|
|
}
|
|
|
- if (binding.editResultTwo.text.toString().trim().isNullOrEmpty()) {
|
|
|
+ if (binding.editResultTwo.text.toString().trim().isEmpty()) {
|
|
|
"请输入第二道题目的答案".toast()
|
|
|
binding.editResultTwo.requestFocus()
|
|
|
binding.editResultTwo.isFocusable = true
|
|
@@ -218,7 +216,7 @@ class CountFragment : BaseFragment<FragmentCountBinding>(), View.OnTouchListener
|
|
|
dao?.update(secondQuestion!!)
|
|
|
}
|
|
|
}
|
|
|
- if (binding.editResultThree.text.toString().trim().isNullOrEmpty()) {
|
|
|
+ if (binding.editResultThree.text.toString().trim().isEmpty()) {
|
|
|
"请输入第三道题目的答案".toast()
|
|
|
binding.editResultThree.requestFocus()
|
|
|
binding.editResultThree.isFocusable = true
|
|
@@ -239,7 +237,7 @@ class CountFragment : BaseFragment<FragmentCountBinding>(), View.OnTouchListener
|
|
|
dao?.update(thirdQuestion!!)
|
|
|
}
|
|
|
}
|
|
|
- if (binding.editResultFour.text.toString().trim().isNullOrEmpty()) {
|
|
|
+ if (binding.editResultFour.text.toString().trim().isEmpty()) {
|
|
|
"请输入第四道题目的答案".toast()
|
|
|
binding.editResultFour.requestFocus()
|
|
|
binding.editResultFour.isFocusable = true
|
|
@@ -260,7 +258,7 @@ class CountFragment : BaseFragment<FragmentCountBinding>(), View.OnTouchListener
|
|
|
dao?.update(fourthQuestion!!)
|
|
|
}
|
|
|
}
|
|
|
- if (binding.editResultFive.text.toString().trim().isNullOrEmpty()) {
|
|
|
+ if (binding.editResultFive.text.toString().trim().isEmpty()) {
|
|
|
"请输入第五道题目的答案".toast()
|
|
|
binding.editResultFive.requestFocus()
|
|
|
binding.editResultFive.isFocusable = true
|
|
@@ -332,7 +330,7 @@ class CountFragment : BaseFragment<FragmentCountBinding>(), View.OnTouchListener
|
|
|
private fun delete() {
|
|
|
if (questionOne) {
|
|
|
binding.editResultOne.post {
|
|
|
- if (stringBufferOne.toString().isNullOrEmpty().not()) {
|
|
|
+ if (stringBufferOne.toString().isEmpty().not()) {
|
|
|
val size = stringBufferOne.toString().length - 1
|
|
|
stringBufferOne.deleteCharAt(size)
|
|
|
binding.editResultOne.setText(stringBufferOne.toString())
|
|
@@ -342,7 +340,7 @@ class CountFragment : BaseFragment<FragmentCountBinding>(), View.OnTouchListener
|
|
|
}
|
|
|
if (questionTwo) {
|
|
|
binding.editResultTwo.post {
|
|
|
- if (stringBufferTwo.toString().isNullOrEmpty().not()) {
|
|
|
+ if (stringBufferTwo.toString().isEmpty().not()) {
|
|
|
val size = stringBufferTwo.toString().length - 1
|
|
|
stringBufferTwo.deleteCharAt(size)
|
|
|
binding.editResultTwo.setText(stringBufferTwo.toString())
|
|
@@ -352,7 +350,7 @@ class CountFragment : BaseFragment<FragmentCountBinding>(), View.OnTouchListener
|
|
|
}
|
|
|
if (questionThree) {
|
|
|
binding.editResultThree.post {
|
|
|
- if (stringBufferThree.toString().isNullOrEmpty().not()) {
|
|
|
+ if (stringBufferThree.toString().isEmpty().not()) {
|
|
|
val size = stringBufferThree.toString().length - 1
|
|
|
stringBufferThree.deleteCharAt(size)
|
|
|
binding.editResultThree.setText(stringBufferThree.toString())
|
|
@@ -362,7 +360,7 @@ class CountFragment : BaseFragment<FragmentCountBinding>(), View.OnTouchListener
|
|
|
}
|
|
|
if (questionFour) {
|
|
|
binding.editResultFour.post {
|
|
|
- if (stringBufferFour.toString().isNullOrEmpty().not()) {
|
|
|
+ if (stringBufferFour.toString().isEmpty().not()) {
|
|
|
val size = stringBufferFour.toString().length - 1
|
|
|
stringBufferFour.deleteCharAt(size)
|
|
|
binding.editResultFour.setText(stringBufferFour.toString())
|
|
@@ -372,7 +370,7 @@ class CountFragment : BaseFragment<FragmentCountBinding>(), View.OnTouchListener
|
|
|
}
|
|
|
if (questionFive) {
|
|
|
binding.editResultFive.post {
|
|
|
- if (stringBufferFive.toString().isNullOrEmpty().not()) {
|
|
|
+ if (stringBufferFive.toString().isEmpty().not()) {
|
|
|
val size = stringBufferFive.toString().length - 1
|
|
|
stringBufferFive.deleteCharAt(size)
|
|
|
binding.editResultFive.setText(stringBufferFive.toString())
|
|
@@ -388,12 +386,12 @@ class CountFragment : BaseFragment<FragmentCountBinding>(), View.OnTouchListener
|
|
|
private fun save() {
|
|
|
if (dao != null) {
|
|
|
if (questionOne) {
|
|
|
- if (firstquestion != null) {
|
|
|
- firstquestion!!.inputString = binding.editResultOne.toString().trim()
|
|
|
- firstquestion!!.reviewId = firstquestion!!.id
|
|
|
- firstquestion!!.reviewAnswer = binding.editResultOne.toString().trim()
|
|
|
- firstquestion!!.correct = ""
|
|
|
- dao?.update(firstquestion!!)
|
|
|
+ if (firstQuestion != null) {
|
|
|
+ firstQuestion!!.inputString = binding.editResultOne.toString().trim()
|
|
|
+ firstQuestion!!.reviewId = firstQuestion!!.id
|
|
|
+ firstQuestion!!.reviewAnswer = binding.editResultOne.toString().trim()
|
|
|
+ firstQuestion!!.correct = ""
|
|
|
+ dao?.update(firstQuestion!!)
|
|
|
}
|
|
|
}
|
|
|
if (questionTwo) {
|
|
@@ -436,6 +434,7 @@ class CountFragment : BaseFragment<FragmentCountBinding>(), View.OnTouchListener
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @SuppressLint("ClickableViewAccessibility")
|
|
|
override fun onTouch(v: View, event: MotionEvent): Boolean {
|
|
|
when (event.action) {
|
|
|
MotionEvent.ACTION_DOWN -> {
|