From 98faa1d5d540a7e4de4086ea11df3fd61b5c7ab9 Mon Sep 17 00:00:00 2001
From: lmw <125975490@qq.com>
Date: 星期三, 17 七月 2024 11:47:03 +0800
Subject: [PATCH] 将要取消游戏页面item的结果动画

---
 app/src/main/java/com/dollearn/student/ui/home/adapter/GameAdapter.kt |   61 ++++++++++++++++++++++++++++++
 1 files changed, 61 insertions(+), 0 deletions(-)

diff --git a/app/src/main/java/com/dollearn/student/ui/home/adapter/GameAdapter.kt b/app/src/main/java/com/dollearn/student/ui/home/adapter/GameAdapter.kt
index 21a4003..69b3e76 100644
--- a/app/src/main/java/com/dollearn/student/ui/home/adapter/GameAdapter.kt
+++ b/app/src/main/java/com/dollearn/student/ui/home/adapter/GameAdapter.kt
@@ -1,22 +1,83 @@
 package com.dollearn.student.ui.home.adapter
 
+import android.util.Log
 import android.view.View
+import android.widget.ImageView
+import androidx.constraintlayout.motion.widget.MotionLayout
+import androidx.constraintlayout.widget.ConstraintLayout
 import cn.sinata.xldutils.adapter.HFRecyclerAdapter
 import cn.sinata.xldutils.adapter.util.ViewHolder
 import com.dollearn.student.R
 import com.dollearn.student.network.entity.Subject
 import com.dollearn.student.ui.home.SuperListenActivity
+import com.dollearn.student.utils.Const
+import com.dollearn.student.utils.event.EmptyEvent
+import com.dollearn.student.utils.event.IntEvent
 import com.dollearn.student.utils.extention.clickDelay
 import com.facebook.drawee.view.SimpleDraweeView
+import kotlinx.android.synthetic.main.fragment_listen.*
+import org.greenrobot.eventbus.EventBus
+import org.jetbrains.anko.dip
 import java.util.ArrayList
 
 class GameAdapter(list: ArrayList<Subject>):HFRecyclerAdapter<Subject>(list, R.layout.item_game_1) {
+    var height:Int = 200 //行高
     override fun onBind(holder: ViewHolder, position: Int, data: Subject) {
+        val act = context as SuperListenActivity
         holder.bind<SimpleDraweeView>(R.id.iv_img).setImageURI(data.img)
         val view = holder.bind<View>(R.id.cl_voice_end_1)
+        val motion = holder.bind<MotionLayout>(R.id.motion)
+        motion.progress = 0f
+        val ivResult = holder.bind<ImageView>(R.id.result_1)
         view.visibility = if (data.right) View.VISIBLE else View.GONE
         view.clickDelay {
 //            (context as SuperListenActivity)
         }
+        val layoutParams = motion.layoutParams as ConstraintLayout.LayoutParams
+        layoutParams.height = height - act.dip(16)
+        motion.layoutParams = layoutParams
+        holder.itemView.setOnClickListener {
+            if (act.playing||act.index>act.voiceList.size-1)
+                return@setOnClickListener
+            if (act.state!=2)
+                return@setOnClickListener
+            Log.e(act.TAG,"点击图片:${act.list[position].name}")
+            Log.e(act.TAG,"音频position:${act.index}")
+            Log.e(act.TAG,"音频路径:${act.voiceList[act.index]}")
+
+            val subject = act.data!!.subjectList[act.data!!.subjectList.map { it.correct }.indexOf(act.voiceList[act.index])] //当前音频对应题目
+            Log.e(act.TAG,"正确答案:${subject.name}")
+
+            act.handler?.removeMessages(act.COUNT_DOWN) //选择答案后,停止倒计时
+            if (data.id == subject.id){
+                ivResult.setImageResource(R.mipmap.successs)
+                act.handler?.sendEmptyMessage(act.PLAY_RIGHT)
+                act.rightCount++
+                subject.right = true
+                notifyItemChanged(position)
+            }else{
+                act.handler?.sendEmptyMessage(act.PLAY_ERROR) //选择答案后,停止倒计时
+                ivResult.setImageResource(R.mipmap.zhifushibai)
+                subject.completed = true
+                subject.right = false
+                act.index++
+                act.startGame()
+            }
+            motion.transitionToEnd()
+            motion.setTransitionListener(object :MotionLayout.TransitionListener{
+                override fun onTransitionStarted(p0: MotionLayout?, p1: Int, p2: Int) {
+                }
+
+                override fun onTransitionChange(p0: MotionLayout?, p1: Int, p2: Int, p3: Float) {
+                }
+
+                override fun onTransitionCompleted(p0: MotionLayout?, p1: Int) {
+                    motion.progress = 0f
+                }
+
+                override fun onTransitionTrigger(p0: MotionLayout?, p1: Int, p2: Boolean, p3: Float) {
+                }
+            })
+        }
     }
 }

--
Gitblit v1.7.1