| | |
| | | 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.activity.ImagePagerActivity |
| | | 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 org.jetbrains.anko.startActivity |
| | | 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) |
| | | view.visibility = if (data.right) View.VISIBLE else View.GONE |
| | | val iv_full = holder.bind<View>(R.id.iv_full) |
| | | iv_full.setOnClickListener { |
| | | act.showFullImage = true |
| | | act.startActivity<ImagePagerActivity>("url" to arrayListOf(data.img)) |
| | | } |
| | | 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.INVISIBLE |
| | | 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.completed = true |
| | | subject.right = true |
| | | act.transAnimation(view) |
| | | }else{ |
| | | act.handler?.sendEmptyMessage(act.PLAY_ERROR) //选择答案后,停止倒计时 |
| | | ivResult.setImageResource(R.mipmap.zhifushibai) |
| | | subject.completed = true |
| | | subject.right = false |
| | | } |
| | | 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) { |
| | | } |
| | | }) |
| | | } |
| | | } |
| | | } |