| | |
| | | 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_choose_voice.* |
| | | import org.greenrobot.eventbus.EventBus |
| | | import org.greenrobot.eventbus.Subscribe |
| | | import org.jetbrains.anko.backgroundResource |
| | | import org.jetbrains.anko.support.v4.toast |
| | | |
| | |
| | | private var playing = false //播放中,不能有任何操作 |
| | | |
| | | private val nameViews by lazy { arrayListOf(tv_1,tv_2,tv_3,tv_4) } |
| | | private val bgs by lazy { arrayListOf(cl_1,cl_2,cl_3,cl_4) } |
| | | private val endViews by lazy { arrayListOf(cl_voice_end_1,cl_voice_end_2,cl_voice_end_3,cl_voice_end_4) } |
| | | |
| | | private val act by lazy { (requireActivity() as ChooseVoiceActivity) } |
| | | |
| | | private var nowVoiceView:View? = null |
| | | |
| | | // private val isShowText by lazy { SPUtils.instance().getBoolean(Const.IS_SHOW_TEXT,true) } |
| | | private val isShowText = false |
| | | |
| | | private var isAutoPlaying = false //true 自动播放流程 |
| | | |
| | | var right = true //true进入下一题为全对,false 一旦答错过就置为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) |
| | |
| | | iv_3.setImageURI(originList[2].img) |
| | | iv_4.setImageURI(originList[3].img) |
| | | } |
| | | showSubImage() |
| | | initClick() |
| | | showSubImage() |
| | | |
| | | } |
| | | |
| | | private fun initClick() { |
| | |
| | | } |
| | | |
| | | rl_check_1.clickDelay { |
| | | if (playing) |
| | | if (playing||data!!.subjectList[group].filter { it.completed }.size == data!!.subjectList[group].size) |
| | | return@clickDelay |
| | | if (rl_check_2.visibility == View.VISIBLE&&rl_check_3.visibility == View.VISIBLE){ |
| | | dot_1.visible() |
| | |
| | | nowVoiceView = cl_voice1 |
| | | handler?.sendEmptyMessage(PLAY_RIGHT) |
| | | }else{ |
| | | right = false |
| | | handler?.sendEmptyMessage(PLAY_ERROR) |
| | | iv_error_1.visible() |
| | | dot_1.postDelayed({ |
| | |
| | | } |
| | | |
| | | rl_check_2.clickDelay { |
| | | if (playing) |
| | | if (playing||data!!.subjectList[group].filter { it.completed }.size == data!!.subjectList[group].size) |
| | | return@clickDelay |
| | | if (rl_check_1.visibility == View.VISIBLE&&rl_check_3.visibility == View.VISIBLE) { |
| | | dot_2.visible() |
| | |
| | | |
| | | } |
| | | rl_check_3.clickDelay { |
| | | if (playing) |
| | | if (playing||data!!.subjectList[group].filter { it.completed }.size == data!!.subjectList[group].size) |
| | | return@clickDelay |
| | | if (rl_check_2.visibility == View.VISIBLE&&rl_check_3.visibility == View.VISIBLE) { |
| | | dot_3.visible() |
| | |
| | | val shuffledList = list.shuffled() |
| | | voiceList.clear() |
| | | voiceList.addAll(shuffledList) |
| | | nameViews.forEachIndexed { index, textView -> |
| | | if (index == currentIndex){ |
| | | textView.text = originList[index].name |
| | | textView.backgroundResource = R.color.textColor99 |
| | | }else{ |
| | | textView.text = "" |
| | | textView.backgroundResource = R.color.page_bg |
| | | nameViews.forEachIndexed { index, textView -> |
| | | if (index == currentIndex){ |
| | | bgs[index].backgroundResource = R.drawable.bg_orange_8dp |
| | | if (isShowText){ |
| | | textView.text = originList[index].name |
| | | textView.backgroundResource = R.color.textColor99 |
| | | } |
| | | }else{ |
| | | bgs[index].backgroundResource = R.drawable.bg_white_8dp_padding |
| | | textView.text = "" |
| | | textView.backgroundResource = R.color.page_bg |
| | | } |
| | | } |
| | | } |
| | | //设置动画飞行路径 3对4 |
| | | val rightVoiceIndex = voiceList.indexOf(imageNow.correct) |
| | | var start = 0 |
| | |
| | | |
| | | override fun onTransitionCompleted(p0: MotionLayout?, p1: Int) { |
| | | endViews[currentIndex].visible() |
| | | |
| | | } |
| | | |
| | | override fun onTransitionTrigger(p0: MotionLayout?, p1: Int, p2: Boolean, p3: Float) { |
| | | } |
| | | }) |
| | | |
| | | if (act.fragments[act.vp.currentItem] == this&&act.recoverd){ //自动播放 |
| | | isAutoPlaying = true |
| | | cl_voice1.callOnClick() |
| | | } |
| | | |
| | | } |
| | | |
| | | @Subscribe |
| | | fun onEvent(e:EmptyEvent){ |
| | | if (e.code == Const.EventCode.RECOVERD){ |
| | | if (act.fragments[act.vp.currentItem] == this){ //自动播放 |
| | | isAutoPlaying = true |
| | | cl_voice1.callOnClick() |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | fun recover(){ |
| | | Log.e(TAG,"回到上一题,恢复答题前的状态") |
| | | right = true |
| | | motion.progress = 0f |
| | | currentIndex = 0 |
| | | endViews.forEach { it.gone() } |
| | |
| | | iv1_1.visible() |
| | | iv2_1.visible() |
| | | iv_playing_1.gone() |
| | | } |
| | | if (voiceIndex == 1){ |
| | | if (isAutoPlaying) |
| | | cl_voice2.callOnClick() |
| | | }else if (voiceIndex == 1){ |
| | | rl_check_2.visible() |
| | | iv1_2.visible() |
| | | iv2_2.visible() |
| | | iv_playing_2.gone() |
| | | } |
| | | if (voiceIndex == 2){ |
| | | if (isAutoPlaying) |
| | | cl_voice3.callOnClick() |
| | | }else if (voiceIndex == 2){ |
| | | rl_check_3.visible() |
| | | iv1_3.visible() |
| | | iv2_3.visible() |
| | | iv_playing_3.gone() |
| | | if (isAutoPlaying) |
| | | isAutoPlaying = false |
| | | } |
| | | if (voiceIndex == 3){ |
| | | iv1_1_end.visible() |
| | |
| | | if (data!!.subjectList[group][currentIndex].completed){ //本题已答对 |
| | | Log.e(TAG,"选对答案后的播放结束3秒后进入下一图") |
| | | if (currentIndex == 3){ |
| | | handler?.sendEmptyMessageDelayed(TO_NEXT,3000) |
| | | handler?.sendEmptyMessageDelayed(TO_NEXT,500)//万俊杰:缩短为0.5秒 |
| | | }else{ |
| | | currentIndex++ |
| | | showSubImage() |
| | |
| | | player.stopPlayMusic() |
| | | } |
| | | |
| | | override fun onDestroy() { |
| | | super.onDestroy() |
| | | EventBus.getDefault().unregister(this) |
| | | handler?.removeCallbacksAndMessages(null) |
| | | } |
| | | } |