| | |
| | | import com.dollearn.student.utils.Const |
| | | import com.dollearn.student.utils.extention.clickDelay |
| | | import kotlinx.android.synthetic.main.fragment_include.* |
| | | import org.jetbrains.anko.support.v4.dip |
| | | import org.jetbrains.anko.support.v4.startActivity |
| | | |
| | | class IncludeFragment : BaseFragment(), AudioUtils.OnAudioStatusUpdateListener { |
| | |
| | | private val act by lazy { requireActivity() as IncludeActivity } |
| | | |
| | | private var voiceIndex = -1 //点击播放的声音序号 0-5取值 |
| | | private val voiceViews by lazy { arrayListOf(cl_voice1,cl_voice2,cl_voice3,cl_voice4,cl_voice5,cl_voice6) } |
| | | private val voiceViews by lazy { arrayListOf(cl_voice1_real,cl_voice2_real,cl_voice3_real,cl_voice4_real,cl_voice5_real,cl_voice6_real) } |
| | | private var playing = false |
| | | |
| | | private val answerImg = arrayListOf<String>() //随机答案图片 |
| | |
| | | super.handleMessage(msg) |
| | | when(msg.what){ |
| | | PLAY_VOICE->{ |
| | | playing = true |
| | | player.startPlayMusic(requireContext(),data!!.subjectList[group][voiceIndex].correct) |
| | | } |
| | | TO_NEXT->{ |
| | |
| | | } |
| | | } |
| | | PLAY_RIGHT->{ |
| | | playing = true |
| | | rightPlaying = true |
| | | player.startPlayMusic(requireContext(),rightVoice) |
| | | } |
| | | PLAY_ERROR->{ |
| | | playing = true |
| | | errorPlaying = true |
| | | player.startPlayMusic(requireContext(),errorVoice) |
| | | } |
| | |
| | | } |
| | | data?.apply { |
| | | val originList = subjectList[group] |
| | | iv_1.setImageURI(originList[0].img) |
| | | iv_2.setImageURI(originList[1].img) |
| | | iv_4.setImageURI(originList[3].img) |
| | | answerImg.clear() |
| | | answerImg.add(originList[2].img) |
| | | answerImg.add(originList[4].img) |
| | | answerImg.add(originList[5].img) |
| | | cl_voice1_real.postDelayed({ |
| | | iv_1.setImageURI(originList[0].img) |
| | | iv_2.setImageURI(originList[1].img) |
| | | iv_4.setImageURI(originList[3].img) |
| | | if (cl_1.width > dip(203)){ |
| | | voiceViews.forEach { |
| | | it.layoutParams.width = dip(159) |
| | | it.layoutParams.height = dip(52) |
| | | it.requestLayout() |
| | | } |
| | | } |
| | | voiceViews.forEach { it.visible() } |
| | | },500) |
| | | } |
| | | voiceViews.forEachIndexed { index, constraintLayout -> |
| | | if (index == 0) |
| | |
| | | |
| | | private fun initClick() { |
| | | voiceViews.forEachIndexed { index, constraintLayout -> |
| | | constraintLayout.clickDelay { |
| | | constraintLayout.setOnClickListener { |
| | | if (!playing){ |
| | | if (index!=0&&!data!!.subjectList[group][index-1].listend){ |
| | | myToast("请按顺序听语音") |
| | | return@clickDelay |
| | | return@setOnClickListener |
| | | } |
| | | voiceIndex = index |
| | | handler?.sendEmptyMessage(PLAY_VOICE) |
| | |
| | | } |
| | | |
| | | cl_answer_1.clickDelay { |
| | | if (currentImage == 0) |
| | | if (currentImage == 0||!data!!.subjectList[group][currentImage].listend) |
| | | return@clickDelay |
| | | val subject = data!!.subjectList[group][currentImage] |
| | | if (!subject.listend||subject.completed){ |
| | | return@clickDelay |
| | | } |
| | | act.totalCount++ |
| | | data!!.subjectList[group][currentImage].listend = false |
| | | if (answerImg[0] == subject.img){ |
| | | nowVoiceView = voiceViews[currentImage] |
| | | act.rightCount++ |
| | |
| | | } |
| | | |
| | | cl_answer_2.clickDelay { |
| | | if (currentImage == 0) |
| | | if (currentImage == 0||!data!!.subjectList[group][currentImage].listend) |
| | | return@clickDelay |
| | | val subject = data!!.subjectList[group][currentImage] |
| | | if (!subject.listend||subject.completed){ |
| | |
| | | } |
| | | act.totalCount++ |
| | | |
| | | data!!.subjectList[group][currentImage].listend = false |
| | | if (answerImg[1] == subject.img){ |
| | | nowVoiceView = voiceViews[currentImage] |
| | | act.rightCount++ |
| | |
| | | } |
| | | |
| | | cl_answer_3.clickDelay { |
| | | if (currentImage == 0) |
| | | if (currentImage == 0||!data!!.subjectList[group][currentImage].listend) |
| | | return@clickDelay |
| | | val subject = data!!.subjectList[group][currentImage] |
| | | if (!subject.listend||subject.completed){ |
| | |
| | | } |
| | | act.totalCount++ |
| | | |
| | | data!!.subjectList[group][currentImage].listend = false |
| | | if (answerImg[2] == subject.img){ |
| | | nowVoiceView = voiceViews[currentImage] |
| | | act.rightCount++ |
| | |
| | | override fun onFinishPlay() { |
| | | playing = false |
| | | val subject = data!!.subjectList[group][voiceIndex] |
| | | subject.listend = true |
| | | when(voiceIndex){ |
| | | 0->{ |
| | | iv1_1.visible() |
| | |
| | | } |
| | | } |
| | | } |
| | | showVoiceEnable() |
| | | |
| | | if (errorPlaying) |
| | | errorPlaying = false |
| | | if (rightPlaying) { |
| | | else if (rightPlaying) { |
| | | rightPlaying = false |
| | | data!!.subjectList[group][currentImage].completed = true |
| | | nowVoiceView?.callOnClick() |
| | | } |
| | | }else |
| | | subject.listend = true |
| | | showVoiceEnable() |
| | | } |
| | | |
| | | override fun onPause() { |
| | | super.onPause() |
| | | player.stopPlayMusic() |
| | | } |
| | | |
| | | override fun onDestroy() { |
| | | super.onDestroy() |
| | | handler?.removeCallbacksAndMessages(null) |
| | | } |
| | | } |