| | |
| | | import com.dollearn.student.utils.AudioUtils |
| | | import com.dollearn.student.utils.Const |
| | | import com.dollearn.student.utils.extention.clickDelay |
| | | import com.dollearn.student.utils.glide.GlideUtil |
| | | import kotlinx.android.synthetic.main.fragment_listen.* |
| | | import org.jetbrains.anko.imageResource |
| | | |
| | |
| | | private val randomList by lazy { data?.subjectList!![group].shuffled() }//随机排序后的题目 |
| | | |
| | | private val resultViewList by lazy { arrayListOf(result_1,result_2,result_3,result_4) } |
| | | |
| | | var right = true //true进入下一题为全对,false 一旦答错过就置为false,此时进入下一题,本题算做错误 |
| | | |
| | | override fun onFirstVisibleToUser() { |
| | | player.setOnAudioStatusUpdateListener(this) |
| | |
| | | data?.apply { |
| | | val originList = subjectList[group] |
| | | correctVoice = originList[index].correct |
| | | iv_1.setImageURI(randomList[0].img) |
| | | iv_2.setImageURI(randomList[1].img) |
| | | iv_3.setImageURI(randomList[2].img) |
| | | iv_4.setImageURI(randomList[3].img) |
| | | GlideUtil.load(requireContext(),randomList[0].img,iv_1,0) |
| | | GlideUtil.load(requireContext(),randomList[1].img,iv_2,0) |
| | | GlideUtil.load(requireContext(),randomList[2].img,iv_3,0) |
| | | GlideUtil.load(requireContext(),randomList[3].img,iv_4,0) |
| | | // iv_1.setImageURI(randomList[0].img) |
| | | // iv_2.setImageURI(randomList[1].img) |
| | | // iv_3.setImageURI(randomList[2].img) |
| | | // iv_4.setImageURI(randomList[3].img) |
| | | resultViewList.forEachIndexed { index, imageView -> |
| | | imageView.imageResource = if (randomList[index].correct == correctVoice){ |
| | | motion.setTransition(R.id.start,if (index == 0) R.id.end_1 else if (index == 1) R.id.end_2 else if (index == 2) R.id.end_3 else R.id.end_4) |
| | |
| | | } |
| | | } |
| | | |
| | | handler?.sendEmptyMessageDelayed(PLAY_VOICE,1500) //进入题目2秒后播放,这里写1.5秒 预算进网络语音加载时间 |
| | | handler?.sendEmptyMessageDelayed(PLAY_VOICE,200) //2025.4.8 立即播放 |
| | | |
| | | initClick() |
| | | } |
| | |
| | | Log.e(TAG,"回到上一题,恢复答题前的状态") |
| | | hasListen = false |
| | | hasRight = false |
| | | handler?.sendEmptyMessageDelayed(PLAY_VOICE,1500) //进入题目2秒后播放,这里写1.5秒 预算进网络语音加载时间 |
| | | cl_1.progress = 0f |
| | | cl_2.progress = 0f |
| | | cl_3.progress = 0f |
| | | cl_4.progress = 0f |
| | | motion.progress = 0f |
| | | right = true |
| | | handler?.sendEmptyMessageDelayed(PLAY_VOICE,200) //改为立即播放 |
| | | cl_1?.progress = 0f |
| | | cl_2?.progress = 0f |
| | | cl_3?.progress = 0f |
| | | cl_4?.progress = 0f |
| | | motion?.progress = 0f |
| | | } |
| | | |
| | | companion object{ |
| | |
| | | private fun setResultAnimation(v:MotionLayout,index: Int){ |
| | | v.clickDelay { |
| | | if (!hasListen) { |
| | | myToast("请先听题") |
| | | // myToast("请先听题") |
| | | return@clickDelay |
| | | } |
| | | if (playing) |
| | |
| | | v.transitionToEnd() |
| | | if (randomList[index].correct != correctVoice){ //答案不对,结束后消失 |
| | | hasListen = false |
| | | right = false |
| | | handler?.sendEmptyMessage(PLAY_ERROR) |
| | | v.setTransitionListener(object :MotionLayout.TransitionListener{ |
| | | override fun onTransitionStarted(p0: MotionLayout?, p1: Int, p2: Int) { |
| | |
| | | iv_playing.gone() |
| | | if (hasRight&&!playing){ //选对答案后的播放结束3秒后进入下一图 |
| | | Log.e(TAG,"选对答案后的播放结束3秒后进入下一图") |
| | | handler?.sendEmptyMessageDelayed(TO_NEXT,3000) |
| | | handler?.sendEmptyMessageDelayed(TO_NEXT,500) //万俊杰:缩短为0.5秒 |
| | | } |
| | | if (rightPlaying){ |
| | | rightPlaying = false |
| | | hasRight = true |
| | | handler?.sendEmptyMessage(PLAY_VOICE) |
| | | }else if (errorPlaying) |
| | | }else if (errorPlaying){ |
| | | errorPlaying = false |
| | | cl_voice.callOnClick() |
| | | } |
| | | else if (!hasRight) |
| | | hasListen = true |
| | | } |
| | |
| | | super.onPause() |
| | | player.stopPlayMusic() |
| | | } |
| | | |
| | | override fun onDestroy() { |
| | | super.onDestroy() |
| | | handler?.removeCallbacksAndMessages(null) |
| | | } |
| | | } |