罗明文
15 小时以前 442124baa483f8d1c4aaca7ff81e15dd3f122363
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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)
        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) {
                }
            })
        }
    }
}