| | |
| | | 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_include.* |
| | | import org.greenrobot.eventbus.EventBus |
| | | import org.greenrobot.eventbus.Subscribe |
| | | import org.jetbrains.anko.support.v4.dip |
| | | import org.jetbrains.anko.support.v4.startActivity |
| | | |
| | |
| | | |
| | | private var nowVoiceView: View? = null |
| | | |
| | | 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_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() |
| | | } |
| | | } |
| | | // 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) |
| | | } |
| | |
| | | constraintLayout.isEnabled = data!!.subjectList[group][index].listend |
| | | } |
| | | } |
| | | showVoiceEnable() |
| | | initClick() |
| | | showVoiceEnable() |
| | | } |
| | | |
| | | private fun initClick() { |
| | |
| | | motion.transitionToEnd() |
| | | showResultAnim() |
| | | }else{ |
| | | right = false |
| | | handler?.sendEmptyMessage(PLAY_ERROR) |
| | | iv_error_1.visible() |
| | | iv_error_1.postDelayed({ |
| | |
| | | motion.transitionToEnd() |
| | | showResultAnim() |
| | | }else{ |
| | | right = false |
| | | handler?.sendEmptyMessage(PLAY_ERROR) |
| | | iv_error_2.visible() |
| | | iv_error_2.postDelayed({ |
| | |
| | | motion.transitionToEnd() |
| | | showResultAnim() |
| | | }else{ |
| | | right = false |
| | | handler?.sendEmptyMessage(PLAY_ERROR) |
| | | iv_error_3.visible() |
| | | iv_error_3.postDelayed({ |
| | |
| | | }) |
| | | } |
| | | |
| | | @Subscribe |
| | | fun onEvent(e: EmptyEvent){ |
| | | if (e.code == Const.EventCode.RECOVERD){ |
| | | if (act.fragments[act.vp.currentItem] == this){ //自动播放 |
| | | isAutoPlaying = true |
| | | voiceViews[0].callOnClick() |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 回到上一题,恢复状态 |
| | | */ |
| | | fun recover(){ |
| | | Log.e(TAG,"回到上一题,恢复答题前的状态") |
| | | right = true |
| | | isAutoPlaying = false |
| | | motion.progress = 0f |
| | | clearAnswerImg() |
| | | currentImage = 0 |
| | |
| | | it.listend = false |
| | | } |
| | | showVoiceEnable() |
| | | if (act.fragments[act.vp.currentItem] == this&&act.recoverd) { //自动播放 |
| | | isAutoPlaying = true |
| | | voiceViews[0].callOnClick() |
| | | } |
| | | } |
| | | |
| | | companion object{ |
| | |
| | | }else{ |
| | | hideAnswerImg() |
| | | Log.e(TAG,"本题全部答对,3秒后进入下一图") |
| | | handler?.sendEmptyMessageDelayed(TO_NEXT,3000) |
| | | handler?.sendEmptyMessageDelayed(TO_NEXT,500) //万俊杰:缩短为0.5秒 |
| | | } |
| | | } |
| | | } |
| | |
| | | rightPlaying = false |
| | | data!!.subjectList[group][currentImage].completed = true |
| | | nowVoiceView?.callOnClick() |
| | | }else |
| | | }else{ |
| | | subject.listend = true |
| | | if (isAutoPlaying) |
| | | when(voiceIndex){ |
| | | 0-> voiceViews[1].callOnClick() |
| | | 1-> voiceViews[2].callOnClick() |
| | | 3-> voiceViews[4].callOnClick() |
| | | 2,4,5-> isAutoPlaying = false |
| | | } |
| | | else if (subject.completed){ |
| | | when(voiceIndex){ |
| | | 2->{ |
| | | isAutoPlaying = true |
| | | voiceViews[3].callOnClick() |
| | | } |
| | | 4->{ |
| | | voiceViews[5].callOnClick() |
| | | } |
| | | } |
| | | } |
| | | } |
| | | showVoiceEnable() |
| | | } |
| | | |
| | |
| | | override fun onDestroy() { |
| | | super.onDestroy() |
| | | handler?.removeCallbacksAndMessages(null) |
| | | EventBus.getDefault().unregister(this) |
| | | } |
| | | } |