罗明文
15 小时以前 442124baa483f8d1c4aaca7ff81e15dd3f122363
app/src/main/java/com/dollearn/student/ui/home/QAFragment.kt
@@ -21,8 +21,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_q_a.*
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.jetbrains.anko.support.v4.dip
class QAFragment:BaseFragment(), AudioUtils.OnAudioStatusUpdateListener {
@@ -77,6 +80,7 @@
    override fun onFirstVisibleToUser() {
        EventBus.getDefault().register(this)
        player.setOnAudioStatusUpdateListener(this)
        player.stopPlayMusic()
        handler = object : Handler(Looper.getMainLooper()){
@@ -208,14 +212,20 @@
                },2000)
            }
        }
        isAutoPlaying = 1
        voiceViews.filterIndexed { index, constraintLayout ->
            val subject = list[index]
            constraintLayout.isEnabled&&subject.isQuestion == 1
        }.firstOrNull()?.callOnClick()
    }
    @Subscribe
    fun onEvent(e: EmptyEvent){
        if (e.code == Const.EventCode.RECOVERD){
            if (act.fragments[act.vp.currentItem] == this){ //自动播放
                isAutoPlaying = 1
                voiceViews.filterIndexed { index, constraintLayout ->
                    val subject = list[index]
                    constraintLayout.isEnabled&&subject.isQuestion == 1
                }.firstOrNull()?.callOnClick()
            }
        }
    }
    /**
     * 恢复答案和题目ui
@@ -225,6 +235,13 @@
        showVoiceUi()
        list.forEach { it.completed = false }
        recoverAnswer()
        if (act.fragments[act.vp.currentItem] == this&&act.recoverd) { //自动播放
            isAutoPlaying = 1
            voiceViews.filterIndexed { index, constraintLayout ->
                val subject = list[index]
                constraintLayout.isEnabled&&subject.isQuestion == 1
            }.firstOrNull()?.callOnClick()
        }
    }
    /**
@@ -444,5 +461,6 @@
    override fun onDestroy() {
        super.onDestroy()
        handler?.removeCallbacksAndMessages(null)
        EventBus.getDefault().unregister(this)
    }
}