From b13afc751dbbce24753d008f1f87d2c5e133a4ad Mon Sep 17 00:00:00 2001 From: lmw <125975490@qq.com> Date: 星期二, 09 七月 2024 15:19:26 +0800 Subject: [PATCH] fix bug --- app/src/main/java/com/dollearn/student/ui/home/adapter/GameAdapter.kt | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 57 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..28c77fe 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,79 @@ 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 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 java.util.ArrayList class GameAdapter(list: ArrayList<Subject>):HFRecyclerAdapter<Subject>(list, R.layout.item_game_1) { override fun onBind(holder: ViewHolder, position: Int, data: Subject) { 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 act = context as SuperListenActivity + 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.totalCount++ + + 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