|
@@ -1,6 +1,11 @@
|
|
|
package com.yingyangfly.moca.omputation
|
|
|
|
|
|
+import android.annotation.SuppressLint
|
|
|
+import android.os.Build
|
|
|
import android.os.Bundle
|
|
|
+import android.view.MotionEvent
|
|
|
+import android.view.View
|
|
|
+import androidx.annotation.RequiresApi
|
|
|
import androidx.core.os.bundleOf
|
|
|
import androidx.navigation.Navigation
|
|
|
import androidx.recyclerview.widget.GridLayoutManager
|
|
@@ -8,21 +13,21 @@ import com.yingyang.moca.R
|
|
|
import com.yingyang.moca.databinding.FragmentComputationBinding
|
|
|
import com.yingyangfly.baselib.base.BaseFragment
|
|
|
import com.yingyangfly.baselib.db.QuestionsBean
|
|
|
-import com.yingyangfly.baselib.ext.setOnSingleClickListener
|
|
|
+import com.yingyangfly.baselib.ext.getEndAnimation
|
|
|
+import com.yingyangfly.baselib.ext.getScaleAnimation
|
|
|
import com.yingyangfly.baselib.ext.toast
|
|
|
import com.yingyangfly.moca.adapter.NumberAdapter
|
|
|
|
|
|
/**
|
|
|
* 计算题
|
|
|
*/
|
|
|
-class ComputationFragment : BaseFragment<FragmentComputationBinding>() {
|
|
|
+class ComputationFragment : BaseFragment<FragmentComputationBinding>(), 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() }
|
|
|
|
|
@@ -32,7 +37,7 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>() {
|
|
|
private var fourthQuestion: QuestionsBean? = null
|
|
|
private var fifthQuestion: QuestionsBean? = null
|
|
|
|
|
|
- private var questionOne = false
|
|
|
+ private var questionOne = true
|
|
|
private var questionTwo = false
|
|
|
private var questionThree = false
|
|
|
private var questionFour = false
|
|
@@ -50,8 +55,14 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>() {
|
|
|
super.onCreate(savedInstanceState)
|
|
|
}
|
|
|
|
|
|
+ @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
|
|
|
override fun initViews() {
|
|
|
binding {
|
|
|
+ editResultOne.showSoftInputOnFocus = false
|
|
|
+ editResultTwo.showSoftInputOnFocus = false
|
|
|
+ editResultThree.showSoftInputOnFocus = false
|
|
|
+ editResultFour.showSoftInputOnFocus = false
|
|
|
+ editResultFive.showSoftInputOnFocus = false
|
|
|
numberList.clear()
|
|
|
for (i in 1..9) {
|
|
|
numberList.add(i.toString())
|
|
@@ -78,74 +89,63 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @SuppressLint("ClickableViewAccessibility")
|
|
|
override fun initListener() {
|
|
|
+ setOnFocusChangeListener()
|
|
|
binding {
|
|
|
- btnPrevious.setOnSingleClickListener {
|
|
|
- val controller = Navigation.findNavController(it)
|
|
|
- val bundle = bundleOf("questionId" to 51)
|
|
|
- controller.navigate(
|
|
|
- R.id.action_computationFragment_to_numberRecordsFragment,
|
|
|
- bundle
|
|
|
- )
|
|
|
- }
|
|
|
+ btnPrevious.setOnTouchListener(this@ComputationFragment)
|
|
|
+ btnNext.setOnTouchListener(this@ComputationFragment)
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- btnNext.setOnSingleClickListener {
|
|
|
- if (judge()) {
|
|
|
- val controller = Navigation.findNavController(it)
|
|
|
- val bundle = bundleOf("questionId" to 57)
|
|
|
- controller.navigate(
|
|
|
- R.id.action_computationFragment_to_listenSpeakFragment,
|
|
|
- bundle
|
|
|
- )
|
|
|
- }
|
|
|
- }
|
|
|
+ override fun initData() {
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
+ private fun setOnFocusChangeListener() {
|
|
|
+ binding {
|
|
|
editResultOne.setOnFocusChangeListener { v, hasFocus ->
|
|
|
questionOne = hasFocus
|
|
|
- binding.editResultOne.postDelayed(
|
|
|
- { closeKeyBord(binding.editResultOne, mContext) },
|
|
|
- 300
|
|
|
- )
|
|
|
+ questionTwo = false
|
|
|
+ questionThree = false
|
|
|
+ questionFour = false
|
|
|
+ questionFive = false
|
|
|
}
|
|
|
|
|
|
editResultTwo.setOnFocusChangeListener { v, hasFocus ->
|
|
|
+ questionOne = false
|
|
|
questionTwo = hasFocus
|
|
|
- binding.editResultTwo.postDelayed(
|
|
|
- { closeKeyBord(binding.editResultTwo, mContext) },
|
|
|
- 300
|
|
|
- )
|
|
|
+ questionThree = false
|
|
|
+ questionFour = false
|
|
|
+ questionFive = false
|
|
|
}
|
|
|
|
|
|
editResultThree.setOnFocusChangeListener { v, hasFocus ->
|
|
|
+ questionOne = false
|
|
|
+ questionTwo = false
|
|
|
questionThree = hasFocus
|
|
|
- binding.editResultThree.postDelayed(
|
|
|
- { closeKeyBord(binding.editResultThree, mContext) },
|
|
|
- 300
|
|
|
- )
|
|
|
+ questionFour = false
|
|
|
+ questionFive = false
|
|
|
}
|
|
|
|
|
|
editResultFour.setOnFocusChangeListener { v, hasFocus ->
|
|
|
+ questionOne = false
|
|
|
+ questionTwo = false
|
|
|
+ questionThree = false
|
|
|
questionFour = hasFocus
|
|
|
- binding.editResultFour.postDelayed(
|
|
|
- { closeKeyBord(binding.editResultFour, mContext) },
|
|
|
- 300
|
|
|
- )
|
|
|
+ questionFive = false
|
|
|
}
|
|
|
|
|
|
editResultFive.setOnFocusChangeListener { v, hasFocus ->
|
|
|
+ questionOne = false
|
|
|
+ questionTwo = false
|
|
|
+ questionThree = false
|
|
|
+ questionFour = false
|
|
|
questionFive = hasFocus
|
|
|
- binding.editResultFive.postDelayed(
|
|
|
- { closeKeyBord(binding.editResultFive, mContext) },
|
|
|
- 300
|
|
|
- )
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- override fun initData() {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
override fun onResume() {
|
|
|
super.onResume()
|
|
|
loadData()
|
|
@@ -155,15 +155,11 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>() {
|
|
|
* 加载数据
|
|
|
*/
|
|
|
private fun loadData() {
|
|
|
- binding.editResultOne.requestFocus()
|
|
|
- binding.editResultOne.isFocusable = true
|
|
|
- binding.editResultOne.isFocusableInTouchMode = true
|
|
|
- binding.editResultOne.postDelayed({ closeKeyBord(binding.editResultOne, mContext) }, 300)
|
|
|
if (dao != null) {
|
|
|
firstquestion = dao?.getQuestion(questionId)
|
|
|
if (firstquestion != null && firstquestion!!.inputString.isNullOrEmpty().not()) {
|
|
|
binding.editResultOne.post {
|
|
|
- if (stringBufferOne.toString().isNullOrEmpty().not()) {
|
|
|
+ if (stringBufferOne.toString().isEmpty().not()) {
|
|
|
stringBufferOne.delete(0, firstquestion!!.inputString.length - 1)
|
|
|
}
|
|
|
stringBufferOne.append(firstquestion!!.inputString)
|
|
@@ -171,11 +167,11 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>() {
|
|
|
binding.editResultOne.setSelection(firstquestion!!.inputString.length)
|
|
|
}
|
|
|
}
|
|
|
- val secondQuestionnId = questionId + 1
|
|
|
- secondQuestion = dao?.getQuestion(secondQuestionnId)
|
|
|
+ val secondQuestionId = questionId + 1
|
|
|
+ secondQuestion = dao?.getQuestion(secondQuestionId)
|
|
|
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)
|
|
@@ -187,7 +183,7 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>() {
|
|
|
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)
|
|
@@ -199,7 +195,7 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>() {
|
|
|
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)
|
|
@@ -211,7 +207,7 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>() {
|
|
|
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)
|
|
@@ -227,15 +223,8 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>() {
|
|
|
*/
|
|
|
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
|
|
|
- binding.editResultOne.isFocusableInTouchMode = true
|
|
|
- binding.editResultOne.postDelayed(
|
|
|
- { closeKeyBord(binding.editResultOne, mContext) },
|
|
|
- 300
|
|
|
- )
|
|
|
return false
|
|
|
} else {
|
|
|
if (firstquestion != null) {
|
|
@@ -246,15 +235,8 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>() {
|
|
|
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
|
|
|
- binding.editResultTwo.isFocusableInTouchMode = true
|
|
|
- binding.editResultTwo.postDelayed(
|
|
|
- { closeKeyBord(binding.editResultOne, mContext) },
|
|
|
- 300
|
|
|
- )
|
|
|
return false
|
|
|
} else {
|
|
|
if (secondQuestion != null) {
|
|
@@ -265,17 +247,8 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>() {
|
|
|
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
|
|
|
- binding.editResultThree.isFocusableInTouchMode = true
|
|
|
- binding.editResultThree.postDelayed({
|
|
|
- closeKeyBord(
|
|
|
- binding.editResultOne,
|
|
|
- mContext
|
|
|
- )
|
|
|
- }, 300)
|
|
|
return false
|
|
|
} else {
|
|
|
if (thirdQuestion != null) {
|
|
@@ -286,17 +259,8 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>() {
|
|
|
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
|
|
|
- binding.editResultFour.isFocusableInTouchMode = true
|
|
|
- binding.editResultFour.postDelayed({
|
|
|
- closeKeyBord(
|
|
|
- binding.editResultOne,
|
|
|
- mContext
|
|
|
- )
|
|
|
- }, 300)
|
|
|
return false
|
|
|
} else {
|
|
|
if (fourthQuestion != null) {
|
|
@@ -307,17 +271,8 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>() {
|
|
|
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
|
|
|
- binding.editResultFive.isFocusableInTouchMode = true
|
|
|
- binding.editResultFive.postDelayed({
|
|
|
- closeKeyBord(
|
|
|
- binding.editResultOne,
|
|
|
- mContext
|
|
|
- )
|
|
|
- }, 300)
|
|
|
return false
|
|
|
} else {
|
|
|
if (fifthQuestion != null) {
|
|
@@ -379,7 +334,7 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>() {
|
|
|
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())
|
|
@@ -389,7 +344,7 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>() {
|
|
|
}
|
|
|
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())
|
|
@@ -399,7 +354,7 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>() {
|
|
|
}
|
|
|
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())
|
|
@@ -409,7 +364,7 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>() {
|
|
|
}
|
|
|
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())
|
|
@@ -419,7 +374,7 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>() {
|
|
|
}
|
|
|
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())
|
|
@@ -482,4 +437,55 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>() {
|
|
|
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @SuppressLint("ClickableViewAccessibility")
|
|
|
+ override fun onTouch(v: View, event: MotionEvent): Boolean {
|
|
|
+ when (event.action) {
|
|
|
+ MotionEvent.ACTION_DOWN -> {
|
|
|
+ if (v.id == R.id.btnPrevious || v.id == R.id.btnNext) {
|
|
|
+ v.startAnimation(getScaleAnimation())
|
|
|
+ }
|
|
|
+ }
|
|
|
+ MotionEvent.ACTION_UP -> {
|
|
|
+ v.startAnimation(getEndAnimation())
|
|
|
+ if (v.id == R.id.btnPrevious) {
|
|
|
+ pageUp(v)
|
|
|
+ } else if (v.id == R.id.btnNext) {
|
|
|
+ pageNext(v)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ MotionEvent.ACTION_CANCEL -> {
|
|
|
+ if (v.id == R.id.btnPrevious || v.id == R.id.btnNext) {
|
|
|
+ v.startAnimation(getEndAnimation())
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 上一页
|
|
|
+ */
|
|
|
+ private fun pageUp(v: View) {
|
|
|
+ val controller = Navigation.findNavController(v)
|
|
|
+ val bundle = bundleOf("questionId" to 51)
|
|
|
+ controller.navigate(
|
|
|
+ R.id.action_computationFragment_to_numberRecordsFragment,
|
|
|
+ bundle
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 下一页
|
|
|
+ */
|
|
|
+ private fun pageNext(v: View) {
|
|
|
+ if (judge()) {
|
|
|
+ val controller = Navigation.findNavController(v)
|
|
|
+ val bundle = bundleOf("questionId" to 57)
|
|
|
+ controller.navigate(
|
|
|
+ R.id.action_computationFragment_to_listenSpeakFragment,
|
|
|
+ bundle
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|