|
@@ -1,19 +1,25 @@
|
|
|
package com.yingyangfly.moca.alternatingconnection
|
|
|
|
|
|
+import android.annotation.SuppressLint
|
|
|
import android.text.TextUtils
|
|
|
+import android.view.MotionEvent
|
|
|
+import android.view.View
|
|
|
import androidx.core.os.bundleOf
|
|
|
import androidx.navigation.Navigation
|
|
|
import com.yingyang.moca.R
|
|
|
import com.yingyang.moca.databinding.FragmentAlternatingConnectionBinding
|
|
|
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.toast
|
|
|
import com.yingyangfly.moca.entity.MyLine
|
|
|
|
|
|
/**
|
|
|
* 交替连线测验
|
|
|
*/
|
|
|
-class AlternatingConnectionFragment : BaseFragment<FragmentAlternatingConnectionBinding>() {
|
|
|
+class AlternatingConnectionFragment : BaseFragment<FragmentAlternatingConnectionBinding>(),
|
|
|
+ View.OnTouchListener {
|
|
|
|
|
|
/**
|
|
|
* 问题id
|
|
@@ -34,63 +40,12 @@ class AlternatingConnectionFragment : BaseFragment<FragmentAlternatingConnection
|
|
|
|
|
|
}
|
|
|
|
|
|
+ @SuppressLint("ClickableViewAccessibility")
|
|
|
override fun initListener() {
|
|
|
binding {
|
|
|
- btnPrevious.setOnClickListener {
|
|
|
- myLines.clear()
|
|
|
- firstChecked = true
|
|
|
- signatureView.clearData()
|
|
|
- tvFirst.isEnabled = true
|
|
|
- tvSeconds.isEnabled = true
|
|
|
- tvThird.isEnabled = true
|
|
|
- tvFourth.isEnabled = true
|
|
|
- tvFifth.isEnabled = true
|
|
|
- tvOne.isEnabled = true
|
|
|
- tvTwo.isEnabled = true
|
|
|
- tvThree.isEnabled = true
|
|
|
- tvFour.isEnabled = true
|
|
|
- tvFive.isEnabled = true
|
|
|
- tvFirst.isChecked = false
|
|
|
- tvSeconds.isChecked = false
|
|
|
- tvThird.isChecked = false
|
|
|
- tvFourth.isChecked = false
|
|
|
- tvFifth.isChecked = false
|
|
|
- tvOne.isChecked = false
|
|
|
- tvTwo.isChecked = false
|
|
|
- tvThree.isChecked = false
|
|
|
- tvThird.isChecked = false
|
|
|
- tvFour.isChecked = false
|
|
|
- tvFive.isChecked = false
|
|
|
- if (stringBuffer.toString().isNullOrEmpty().not()) {
|
|
|
- stringBuffer.delete(0, stringBuffer.toString().length)
|
|
|
- }
|
|
|
- }
|
|
|
- btnNext.setOnClickListener {
|
|
|
- if (stringBuffer.toString().isNullOrEmpty()) {
|
|
|
- "请连线".toast()
|
|
|
- } else {
|
|
|
- if (TextUtils.equals("1甲2乙3丙4丁5戊", stringBuffer.toString())) {
|
|
|
- if (question != null) {
|
|
|
- question?.score = question?.reviewScore
|
|
|
- question?.correct = "1"
|
|
|
- dao?.update(question!!)
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (question != null) {
|
|
|
- question?.score = "0"
|
|
|
- question?.correct = "0"
|
|
|
- dao?.update(question!!)
|
|
|
- }
|
|
|
- }
|
|
|
- val bundle = bundleOf("questionId" to 33)
|
|
|
- val controller = Navigation.findNavController(it)
|
|
|
- controller.navigate(
|
|
|
- R.id.action_alternatingconnectionFragment_to_signatureFragment,
|
|
|
- bundle
|
|
|
- )
|
|
|
- }
|
|
|
- }
|
|
|
- tvFirst.setOnCheckedChangeListener { buttonView, isChecked ->
|
|
|
+ btnPrevious.setOnTouchListener(this@AlternatingConnectionFragment)
|
|
|
+ btnNext.setOnTouchListener(this@AlternatingConnectionFragment)
|
|
|
+ tvFirst.setOnCheckedChangeListener { _, isChecked ->
|
|
|
if (isChecked) {
|
|
|
stringBuffer.append("甲")
|
|
|
tvFirst.isEnabled = false
|
|
@@ -114,7 +69,7 @@ class AlternatingConnectionFragment : BaseFragment<FragmentAlternatingConnection
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- tvOne.setOnCheckedChangeListener { buttonView, isChecked ->
|
|
|
+ tvOne.setOnCheckedChangeListener { _, isChecked ->
|
|
|
if (isChecked) {
|
|
|
stringBuffer.append("1")
|
|
|
tvOne.isEnabled = false
|
|
@@ -138,7 +93,7 @@ class AlternatingConnectionFragment : BaseFragment<FragmentAlternatingConnection
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- tvSeconds.setOnCheckedChangeListener { buttonView, isChecked ->
|
|
|
+ tvSeconds.setOnCheckedChangeListener { _, isChecked ->
|
|
|
if (isChecked) {
|
|
|
stringBuffer.append("乙")
|
|
|
tvSeconds.isEnabled = false
|
|
@@ -161,7 +116,7 @@ class AlternatingConnectionFragment : BaseFragment<FragmentAlternatingConnection
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- tvTwo.setOnCheckedChangeListener { buttonView, isChecked ->
|
|
|
+ tvTwo.setOnCheckedChangeListener { _, isChecked ->
|
|
|
if (isChecked) {
|
|
|
stringBuffer.append("2")
|
|
|
tvTwo.isEnabled = false
|
|
@@ -185,7 +140,7 @@ class AlternatingConnectionFragment : BaseFragment<FragmentAlternatingConnection
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- tvThird.setOnCheckedChangeListener { buttonView, isChecked ->
|
|
|
+ tvThird.setOnCheckedChangeListener { _, isChecked ->
|
|
|
if (isChecked) {
|
|
|
stringBuffer.append("丙")
|
|
|
tvThird.isEnabled = false
|
|
@@ -209,7 +164,7 @@ class AlternatingConnectionFragment : BaseFragment<FragmentAlternatingConnection
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- tvThree.setOnCheckedChangeListener { buttonView, isChecked ->
|
|
|
+ tvThree.setOnCheckedChangeListener { _, isChecked ->
|
|
|
if (isChecked) {
|
|
|
stringBuffer.append("3")
|
|
|
tvThree.isEnabled = false
|
|
@@ -233,7 +188,7 @@ class AlternatingConnectionFragment : BaseFragment<FragmentAlternatingConnection
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- tvFourth.setOnCheckedChangeListener { buttonView, isChecked ->
|
|
|
+ tvFourth.setOnCheckedChangeListener { _, isChecked ->
|
|
|
if (isChecked) {
|
|
|
stringBuffer.append("丁")
|
|
|
tvFourth.isEnabled = false
|
|
@@ -257,7 +212,7 @@ class AlternatingConnectionFragment : BaseFragment<FragmentAlternatingConnection
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- tvFour.setOnCheckedChangeListener { buttonView, isChecked ->
|
|
|
+ tvFour.setOnCheckedChangeListener { _, isChecked ->
|
|
|
if (isChecked) {
|
|
|
stringBuffer.append("4")
|
|
|
tvFour.isEnabled = false
|
|
@@ -281,7 +236,7 @@ class AlternatingConnectionFragment : BaseFragment<FragmentAlternatingConnection
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- tvFifth.setOnCheckedChangeListener { buttonView, isChecked ->
|
|
|
+ tvFifth.setOnCheckedChangeListener { _, isChecked ->
|
|
|
if (isChecked) {
|
|
|
stringBuffer.append("戊")
|
|
|
tvFifth.isEnabled = false
|
|
@@ -305,7 +260,7 @@ class AlternatingConnectionFragment : BaseFragment<FragmentAlternatingConnection
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- tvFive.setOnCheckedChangeListener { buttonView, isChecked ->
|
|
|
+ tvFive.setOnCheckedChangeListener { _, isChecked ->
|
|
|
if (isChecked) {
|
|
|
stringBuffer.append("5")
|
|
|
tvFive.isEnabled = false
|
|
@@ -348,4 +303,94 @@ class AlternatingConnectionFragment : BaseFragment<FragmentAlternatingConnection
|
|
|
question = dao?.getQuestion(questionId)
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @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) {
|
|
|
+ previous()
|
|
|
+ } else if (v.id == R.id.btnNext) {
|
|
|
+ nextPage(v)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ MotionEvent.ACTION_CANCEL -> {
|
|
|
+ if (v.id == R.id.btnPrevious || v.id == R.id.btnNext) {
|
|
|
+ v.startAnimation(getEndAnimation())
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 重置连线
|
|
|
+ */
|
|
|
+ private fun previous() {
|
|
|
+ myLines.clear()
|
|
|
+ firstChecked = true
|
|
|
+ binding {
|
|
|
+ signatureView.clearData()
|
|
|
+ tvFirst.isEnabled = true
|
|
|
+ tvSeconds.isEnabled = true
|
|
|
+ tvThird.isEnabled = true
|
|
|
+ tvFourth.isEnabled = true
|
|
|
+ tvFifth.isEnabled = true
|
|
|
+ tvOne.isEnabled = true
|
|
|
+ tvTwo.isEnabled = true
|
|
|
+ tvThree.isEnabled = true
|
|
|
+ tvFour.isEnabled = true
|
|
|
+ tvFive.isEnabled = true
|
|
|
+ tvFirst.isChecked = false
|
|
|
+ tvSeconds.isChecked = false
|
|
|
+ tvThird.isChecked = false
|
|
|
+ tvFourth.isChecked = false
|
|
|
+ tvFifth.isChecked = false
|
|
|
+ tvOne.isChecked = false
|
|
|
+ tvTwo.isChecked = false
|
|
|
+ tvThree.isChecked = false
|
|
|
+ tvThird.isChecked = false
|
|
|
+ tvFour.isChecked = false
|
|
|
+ tvFive.isChecked = false
|
|
|
+ if (stringBuffer.toString().isNullOrEmpty().not()) {
|
|
|
+ stringBuffer.delete(0, stringBuffer.toString().length)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 下一页
|
|
|
+ */
|
|
|
+ private fun nextPage(v: View) {
|
|
|
+ if (stringBuffer.toString().isNullOrEmpty()) {
|
|
|
+ "请连线".toast()
|
|
|
+ } else {
|
|
|
+ if (TextUtils.equals("1甲2乙3丙4丁5戊", stringBuffer.toString())) {
|
|
|
+ if (question != null) {
|
|
|
+ question?.score = question?.reviewScore
|
|
|
+ question?.correct = "1"
|
|
|
+ dao?.update(question!!)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (question != null) {
|
|
|
+ question?.score = "0"
|
|
|
+ question?.correct = "0"
|
|
|
+ dao?.update(question!!)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ val bundle = bundleOf("questionId" to 33)
|
|
|
+ val controller = Navigation.findNavController(v)
|
|
|
+ controller.navigate(
|
|
|
+ R.id.action_alternatingconnectionFragment_to_signatureFragment,
|
|
|
+ bundle
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|