lmw
1 天以前 967492f43278adf716cb3cb39d209ad9ae59590f
app/src/main/java/com/dollearn/student/ui/home/MatchFragment.kt
@@ -15,8 +15,11 @@
import com.dollearn.student.R
import com.dollearn.student.utils.AudioUtils
import com.dollearn.student.utils.Const
import com.dollearn.student.utils.event.EmptyEvent
import com.dollearn.student.utils.extention.clickDelay
import kotlinx.android.synthetic.main.fragment_match.*
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.jetbrains.anko.imageResource
@@ -56,9 +59,16 @@
    private val completedVoice = arrayListOf<String>() //已经选了的音频 飞到图片上了
    var right = true //true进入下一题为全对,false 一旦答错过就置为false,此时进入下一题,本题算做错误
    var isAutoPlaying = false
    override fun onFirstVisibleToUser() {
        player.setOnAudioStatusUpdateListener(this)
        player.stopPlayMusic()
        EventBus.getDefault().register(this)
        handler = object : Handler(Looper.getMainLooper()){
            override fun handleMessage(msg: Message) {
                super.handleMessage(msg)
@@ -105,7 +115,6 @@
                if (!playing){
                    voiceIndex = index
                    handler?.sendEmptyMessage(PLAY_VOICE)
                    motion.transitionToEnd()
                }
            }
        }
@@ -182,6 +191,7 @@
                motion.transitionToEnd()
                handler?.sendEmptyMessage(PLAY_RIGHT)
            }else{
                right = false
                result_1.imageResource = R.mipmap.zhifushibai
                handler?.sendEmptyMessage(PLAY_ERROR)
            }
@@ -467,11 +477,22 @@
        })
    }
    @Subscribe
    fun onEvent(e: EmptyEvent){
        if (e.code == Const.EventCode.RECOVERD){
            if (act.fragments[act.vp.currentItem] == this){ //自动播放
                isAutoPlaying = true
                cl_voice_1.callOnClick()
            }
        }
    }
    /**
     * 回到上一题,恢复状态
     */
    fun recover(){
        Log.e(TAG,"回到上一题,恢复答题前的状态")
        right = true
        motion.progress = 0f
        data!!.subjectList[group].forEach {
            it.completed = false
@@ -486,6 +507,10 @@
        cl_voice_end_2.gone()
        cl_voice_end_3.gone()
        cl_voice_end_4.gone()
        if (act.fragments[act.vp.currentItem] == this&&act.recoverd) { //自动播放
            isAutoPlaying = true
            cl_voice_1.callOnClick()
        }
    }
    companion object{
@@ -648,5 +673,7 @@
    override fun onDestroy() {
        super.onDestroy()
        handler?.removeCallbacksAndMessages(null)
        EventBus.getDefault().unregister(this)
    }
}