|
@@ -1,16 +1,20 @@
|
|
|
package com.yingyangfly.mmse.fragment
|
|
|
|
|
|
+import android.annotation.SuppressLint
|
|
|
import android.graphics.Bitmap
|
|
|
import android.graphics.drawable.BitmapDrawable
|
|
|
import android.graphics.drawable.Drawable
|
|
|
import android.os.Bundle
|
|
|
+import android.view.MotionEvent
|
|
|
+import android.view.View
|
|
|
import androidx.core.os.bundleOf
|
|
|
import androidx.navigation.Navigation
|
|
|
import com.yingyang.mmse.R
|
|
|
import com.yingyang.mmse.databinding.FragmentRecognitionImageBinding
|
|
|
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.utils.ImageUtil
|
|
|
import com.yingyangfly.mmse.adapter.ChoiceAdapter
|
|
|
|
|
@@ -18,7 +22,8 @@ import com.yingyangfly.mmse.adapter.ChoiceAdapter
|
|
|
/**
|
|
|
* 识图功能
|
|
|
*/
|
|
|
-class RecognitionImageFragment : BaseFragment<FragmentRecognitionImageBinding>() {
|
|
|
+class RecognitionImageFragment : BaseFragment<FragmentRecognitionImageBinding>(),
|
|
|
+ View.OnTouchListener {
|
|
|
|
|
|
/**
|
|
|
* 问题id
|
|
@@ -46,43 +51,11 @@ class RecognitionImageFragment : BaseFragment<FragmentRecognitionImageBinding>()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @SuppressLint("ClickableViewAccessibility")
|
|
|
override fun initListener() {
|
|
|
binding {
|
|
|
- btnPrevious.setOnSingleClickListener {
|
|
|
- if (questionId == 30) {
|
|
|
- val bundle = bundleOf("questionId" to questionId)
|
|
|
- val controller = Navigation.findNavController(it)
|
|
|
- controller.navigate(
|
|
|
- R.id.action_recognitionImageFragment_to_drawDesignsFragment,
|
|
|
- bundle
|
|
|
- )
|
|
|
- } else {
|
|
|
- val bundle = bundleOf("questionId" to 21)
|
|
|
- val controller = Navigation.findNavController(it)
|
|
|
- controller.navigate(
|
|
|
- R.id.action_recognitionImageFragment_to_countFragment,
|
|
|
- bundle
|
|
|
- )
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- btnNext.setOnSingleClickListener {
|
|
|
- if (questionId == 30) {
|
|
|
- val bundle = bundleOf("questionId" to 19)
|
|
|
- val controller = Navigation.findNavController(it)
|
|
|
- controller.navigate(
|
|
|
- R.id.action_recognitionImageFragment_to_memoryWordsFragment,
|
|
|
- bundle
|
|
|
- )
|
|
|
- } else {
|
|
|
- val bundle = bundleOf("questionId" to 24)
|
|
|
- val controller = Navigation.findNavController(it)
|
|
|
- controller.navigate(
|
|
|
- R.id.action_recognitionImageFragment_to_judgmentRecordFragment,
|
|
|
- bundle
|
|
|
- )
|
|
|
- }
|
|
|
- }
|
|
|
+ btnPrevious.setOnTouchListener(this@RecognitionImageFragment)
|
|
|
+ btnNext.setOnTouchListener(this@RecognitionImageFragment)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -101,10 +74,10 @@ class RecognitionImageFragment : BaseFragment<FragmentRecognitionImageBinding>()
|
|
|
private fun loadData() {
|
|
|
choiceItemList.clear()
|
|
|
if (dao != null) {
|
|
|
- val firstquestion = dao?.getQuestion(questionId)
|
|
|
- if (firstquestion != null) {
|
|
|
- binding.firstData = firstquestion
|
|
|
- choiceItemList.add(firstquestion)
|
|
|
+ val firstQuestion = dao?.getQuestion(questionId)
|
|
|
+ if (firstQuestion != null) {
|
|
|
+ binding.firstData = firstQuestion
|
|
|
+ choiceItemList.add(firstQuestion)
|
|
|
}
|
|
|
val secondQuestionId = questionId + 1
|
|
|
val secondQuestion = dao?.getQuestion(secondQuestionId)
|
|
@@ -122,4 +95,71 @@ class RecognitionImageFragment : BaseFragment<FragmentRecognitionImageBinding>()
|
|
|
}
|
|
|
adapter.setData(choiceItemList)
|
|
|
}
|
|
|
+
|
|
|
+ @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) {
|
|
|
+ if (questionId == 30) {
|
|
|
+ val bundle = bundleOf("questionId" to questionId)
|
|
|
+ val controller = Navigation.findNavController(v)
|
|
|
+ controller.navigate(
|
|
|
+ R.id.action_recognitionImageFragment_to_drawDesignsFragment,
|
|
|
+ bundle
|
|
|
+ )
|
|
|
+ } else {
|
|
|
+ val bundle = bundleOf("questionId" to 21)
|
|
|
+ val controller = Navigation.findNavController(v)
|
|
|
+ controller.navigate(
|
|
|
+ R.id.action_recognitionImageFragment_to_countFragment,
|
|
|
+ bundle
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 下一页
|
|
|
+ */
|
|
|
+ private fun pageNext(v: View) {
|
|
|
+ if (questionId == 30) {
|
|
|
+ val bundle = bundleOf("questionId" to 19)
|
|
|
+ val controller = Navigation.findNavController(v)
|
|
|
+ controller.navigate(
|
|
|
+ R.id.action_recognitionImageFragment_to_memoryWordsFragment,
|
|
|
+ bundle
|
|
|
+ )
|
|
|
+ } else {
|
|
|
+ val bundle = bundleOf("questionId" to 24)
|
|
|
+ val controller = Navigation.findNavController(v)
|
|
|
+ controller.navigate(
|
|
|
+ R.id.action_recognitionImageFragment_to_judgmentRecordFragment,
|
|
|
+ bundle
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|