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/ChooseVoiceFragment.kt | 213 ++++++++++++++++++++++++++++++++++------------------- 1 files changed, 137 insertions(+), 76 deletions(-) diff --git a/app/src/main/java/com/dollearn/student/ui/home/ChooseVoiceFragment.kt b/app/src/main/java/com/dollearn/student/ui/home/ChooseVoiceFragment.kt index 7c1086e..d72618f 100644 --- a/app/src/main/java/com/dollearn/student/ui/home/ChooseVoiceFragment.kt +++ b/app/src/main/java/com/dollearn/student/ui/home/ChooseVoiceFragment.kt @@ -9,10 +9,12 @@ import androidx.core.os.bundleOf import cn.sinata.xldutils.fragment.BaseFragment import cn.sinata.xldutils.gone +import cn.sinata.xldutils.utils.SPUtils import cn.sinata.xldutils.utils.myToast import cn.sinata.xldutils.visible import com.dollearn.student.R import com.dollearn.student.utils.AudioUtils +import com.dollearn.student.utils.Const import com.dollearn.student.utils.extention.clickDelay import kotlinx.android.synthetic.main.fragment_choose_voice.* import org.jetbrains.anko.backgroundResource @@ -27,6 +29,15 @@ private val PLAY_VOICE = 1 private val TO_NEXT = 10 + + private val PLAY_ERROR = 3 + private val PLAY_RIGHT = 4 + + private val errorVoice by lazy { SPUtils.instance().getString(Const.EV) } + private val rightVoice by lazy { SPUtils.instance().getString(Const.RV) } + + private var rightPlaying = false + private var errorPlaying = false private var voiceList = arrayListOf<String>() //本题音频,每题有3个音频 private val player by lazy { AudioUtils() } @@ -45,6 +56,8 @@ private val act by lazy { (requireActivity() as ChooseVoiceActivity) } + private var nowVoiceView:View? = null + override fun onFirstVisibleToUser() { player.setOnAudioStatusUpdateListener(this) player.stopPlayMusic() @@ -58,6 +71,14 @@ TO_NEXT->{ if (isAdded&&!playing) (requireActivity() as ChooseVoiceActivity).next() + } + PLAY_RIGHT->{ + rightPlaying = true + player.startPlayMusic(requireContext(),rightVoice) + } + PLAY_ERROR->{ + errorPlaying = true + player.startPlayMusic(requireContext(),errorVoice) } } } @@ -98,57 +119,81 @@ rl_check_1.clickDelay { if (playing) return@clickDelay - dot_1.visible() - act.totalCount++ - if (voiceList[0] == data!!.subjectList[group][currentIndex].correct){ - act.rightCount++ - data!!.subjectList[group][currentIndex].completed = true - motion.transitionToEnd() - cl_voice1.callOnClick() - }else{ - iv_error_1.visible() - dot_1.postDelayed({ - iv_error_1.gone() - dot_1.gone() - },2000) - } + if (rl_check_2.visibility == View.VISIBLE&&rl_check_3.visibility == View.VISIBLE){ + dot_1.visible() + act.totalCount++ + if (voiceList[0] == data!!.subjectList[group][currentIndex].correct){ + act.rightCount++ + motion.transitionToEnd() + nowVoiceView = cl_voice1 + handler?.sendEmptyMessage(PLAY_RIGHT) + }else{ + handler?.sendEmptyMessage(PLAY_ERROR) + iv_error_1.visible() + dot_1.postDelayed({ + iv_error_1.gone() + dot_1.gone() + rl_check_1.gone() + rl_check_2.gone() + rl_check_3.gone() + },2000) + } + }else + myToast("请听完题") } rl_check_2.clickDelay { if (playing) return@clickDelay - dot_2.visible() - act.totalCount++ - if (voiceList[1] == data!!.subjectList[group][currentIndex].correct){ - act.rightCount++ - data!!.subjectList[group][currentIndex].completed = true - motion.transitionToEnd() - cl_voice2.callOnClick() - }else{ - iv_error_2.visible() - dot_1.postDelayed({ - dot_2.gone() - iv_error_2.gone() - },2000) - } + if (rl_check_1.visibility == View.VISIBLE&&rl_check_3.visibility == View.VISIBLE) { + dot_2.visible() + act.totalCount++ + if (voiceList[1] == data!!.subjectList[group][currentIndex].correct){ + act.rightCount++ + motion.transitionToEnd() + nowVoiceView = cl_voice2 + handler?.sendEmptyMessage(PLAY_RIGHT) + }else{ + + handler?.sendEmptyMessage(PLAY_ERROR) + iv_error_2.visible() + dot_1.postDelayed({ + dot_2.gone() + iv_error_2.gone() + rl_check_1.gone() + rl_check_2.gone() + rl_check_3.gone() + },2000) + } + }else + myToast("请听完题") + } rl_check_3.clickDelay { if (playing) return@clickDelay - dot_3.visible() - act.totalCount++ - if (voiceList[2] == data!!.subjectList[group][currentIndex].correct){ - data!!.subjectList[group][currentIndex].completed = true - act.rightCount++ - motion.transitionToEnd() - cl_voice3.callOnClick() - }else{ - iv_error_3.visible() - dot_1.postDelayed({ - iv_error_3.gone() - dot_3.gone() - },2000) - } + if (rl_check_2.visibility == View.VISIBLE&&rl_check_3.visibility == View.VISIBLE) { + dot_3.visible() + act.totalCount++ + if (voiceList[2] == data!!.subjectList[group][currentIndex].correct){ + act.rightCount++ + nowVoiceView = cl_voice3 + handler?.sendEmptyMessage(PLAY_RIGHT) + motion.transitionToEnd() + }else{ + handler?.sendEmptyMessage(PLAY_ERROR) + iv_error_3.visible() + dot_1.postDelayed({ + iv_error_3.gone() + dot_3.gone() + rl_check_1.gone() + rl_check_2.gone() + rl_check_3.gone() + },2000) + } + }else + myToast("请听完题") + } cl_voice_end_1.clickDelay { @@ -292,40 +337,42 @@ override fun onStartPlay() { playing = true - if (voiceIndex == 0){ - iv1_1.gone() - iv2_1.gone() - iv_playing_1.visible() - } - if (voiceIndex == 1){ - iv1_2.gone() - iv2_2.gone() - iv_playing_2.visible() - } - if (voiceIndex == 2){ - iv1_3.gone() - iv2_3.gone() - iv_playing_3.visible() - } - if (voiceIndex == 3){ - iv1_1_end.gone() - iv2_1_end.gone() - iv_playing_1_end.visible() - } - if (voiceIndex == 4){ - iv1_2_end.gone() - iv2_2_end.gone() - iv_playing_2_end.visible() - } - if (voiceIndex == 5){ - iv1_3_end.gone() - iv2_3_end.gone() - iv_playing_3_end.visible() - } - if (voiceIndex == 6){ - iv1_4_end.gone() - iv2_4_end.gone() - iv_playing_4_end.visible() + if (!errorPlaying&&!rightPlaying){ + if (voiceIndex == 0){ + iv1_1.gone() + iv2_1.gone() + iv_playing_1.visible() + } + if (voiceIndex == 1){ + iv1_2.gone() + iv2_2.gone() + iv_playing_2.visible() + } + if (voiceIndex == 2){ + iv1_3.gone() + iv2_3.gone() + iv_playing_3.visible() + } + if (voiceIndex == 3){ + iv1_1_end.gone() + iv2_1_end.gone() + iv_playing_1_end.visible() + } + if (voiceIndex == 4){ + iv1_2_end.gone() + iv2_2_end.gone() + iv_playing_2_end.visible() + } + if (voiceIndex == 5){ + iv1_3_end.gone() + iv2_3_end.gone() + iv_playing_3_end.visible() + } + if (voiceIndex == 6){ + iv1_4_end.gone() + iv2_4_end.gone() + iv_playing_4_end.visible() + } } } @@ -379,5 +426,19 @@ showSubImage() } } + + if (rightPlaying){ + rightPlaying = false + data!!.subjectList[group][currentIndex].completed = true + nowVoiceView?.callOnClick() + } + if (errorPlaying) + errorPlaying = false } + + override fun onPause() { + super.onPause() + player.stopPlayMusic() + } + } \ No newline at end of file -- Gitblit v1.7.1