| | |
| | | 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_q_a.* |
| | | import org.greenrobot.eventbus.EventBus |
| | | import org.greenrobot.eventbus.Subscribe |
| | | import org.jetbrains.anko.support.v4.dip |
| | | |
| | | class QAFragment:BaseFragment(), AudioUtils.OnAudioStatusUpdateListener { |
| | |
| | | private val voiceViews by lazy { arrayListOf(cl_voice_1,cl_voice_2,cl_voice_3,cl_voice_4) } //语音蓝条 |
| | | private val v1Views by lazy { arrayListOf(iv1_1,iv1_2,iv1_3,iv1_4,iv1_answer_1,iv1_answer_2,iv1_answer_3) } |
| | | private val v2Views by lazy { arrayListOf(iv2_1,iv2_2,iv2_3,iv2_4,iv2_answer_1,iv2_answer_2,iv2_answer_3) } |
| | | private val v3Views by lazy { arrayListOf(iv3_1,iv3_2,iv3_3,iv3_4) } |
| | | private val resultViews by lazy { arrayListOf(iv_right_1,iv_right_2,iv_right_3,iv_right_4) } |
| | | private val playingViews by lazy { arrayListOf(iv_playing_1,iv_playing_2,iv_playing_3,iv_playing_4,iv_playing_answer_1,iv_playing_answer_2,iv_playing_answer_3) } |
| | | |
| | |
| | | |
| | | private var nowVoiceView: View? = null |
| | | |
| | | private var isAutoPlaying = 0 |
| | | |
| | | var right = true //true进入下一题为全对,false 一旦答错过就置为false,此时进入下一题,本题算做错误 |
| | | |
| | | |
| | | override fun onFirstVisibleToUser() { |
| | | EventBus.getDefault().register(this) |
| | | player.setOnAudioStatusUpdateListener(this) |
| | | player.stopPlayMusic() |
| | | handler = object : Handler(Looper.getMainLooper()){ |
| | |
| | | act.rightCount++ |
| | | Log.e(TAG,"选择正确") |
| | | transAnimation(cl_answer_1,voiceViews[questionIndex]) |
| | | resultViews[questionIndex].visible() |
| | | resultViews[questionIndex].postDelayed({ |
| | | resultViews[questionIndex].gone() |
| | | },3000) |
| | | val resultView = resultViews[questionIndex] |
| | | resultView.visible() |
| | | resultView.postDelayed({ |
| | | resultView.gone() |
| | | },2000) |
| | | nowVoiceView = voiceViews[questionIndex] |
| | | handler?.sendEmptyMessage(PLAY_RIGHT) |
| | | }else{ |
| | | right = false |
| | | recoverAnswer() |
| | | handler?.sendEmptyMessage(PLAY_ERROR) |
| | | dot_1.visible() |
| | |
| | | dot_1.postDelayed({ |
| | | dot_1.gone() |
| | | iv_error_1.gone() |
| | | },3000) |
| | | },2000) |
| | | } |
| | | } |
| | | rl_check_2.clickDelay { |
| | |
| | | act.rightCount++ |
| | | Log.e(TAG,"选择正确") |
| | | transAnimation(cl_answer_2,voiceViews[questionIndex]) |
| | | resultViews[questionIndex].visible() |
| | | resultViews[questionIndex].postDelayed({ |
| | | resultViews[questionIndex].gone() |
| | | },3000) |
| | | val resultView = resultViews[questionIndex] |
| | | resultView.visible() |
| | | resultView.postDelayed({ |
| | | resultView.gone() |
| | | },2000) |
| | | nowVoiceView = voiceViews[questionIndex] |
| | | handler?.sendEmptyMessage(PLAY_RIGHT) |
| | | }else{ |
| | |
| | | dot_2.postDelayed({ |
| | | dot_2.gone() |
| | | iv_error_2.gone() |
| | | },3000) |
| | | },2000) |
| | | } |
| | | } |
| | | rl_check_3.clickDelay { |
| | |
| | | act.rightCount++ |
| | | Log.e(TAG,"选择正确") |
| | | transAnimation(cl_answer_3,voiceViews[questionIndex]) |
| | | resultViews[questionIndex].visible() |
| | | resultViews[questionIndex].postDelayed({ |
| | | resultViews[questionIndex].gone() |
| | | },3000) |
| | | val resultView = resultViews[questionIndex] |
| | | resultView.visible() |
| | | resultView.postDelayed({ |
| | | resultView.gone() |
| | | },2000) |
| | | nowVoiceView = voiceViews[questionIndex] |
| | | handler?.sendEmptyMessage(PLAY_RIGHT) |
| | | }else{ |
| | |
| | | dot_3.postDelayed({ |
| | | dot_3.gone() |
| | | iv_error_3.gone() |
| | | },3000) |
| | | },2000) |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Subscribe |
| | | fun onEvent(e: EmptyEvent){ |
| | | if (e.code == Const.EventCode.RECOVERD){ |
| | | if (act.fragments[act.vp.currentItem] == this){ //自动播放 |
| | | isAutoPlaying = 1 |
| | | voiceViews.filterIndexed { index, constraintLayout -> |
| | | val subject = list[index] |
| | | constraintLayout.isEnabled&&subject.isQuestion == 1 |
| | | }.firstOrNull()?.callOnClick() |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 恢复答案和题目ui |
| | | */ |
| | | fun recover(){ |
| | | right = true |
| | | showVoiceUi() |
| | | list.forEach { it.completed = false } |
| | | recoverAnswer() |
| | | if (act.fragments[act.vp.currentItem] == this&&act.recoverd) { //自动播放 |
| | | isAutoPlaying = 1 |
| | | voiceViews.filterIndexed { index, constraintLayout -> |
| | | val subject = list[index] |
| | | constraintLayout.isEnabled&&subject.isQuestion == 1 |
| | | }.firstOrNull()?.callOnClick() |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | questionIndex = position |
| | | if (questionIndex == 0||questionIndex == 2){ |
| | | iv2_answer_1.setImageResource(R.mipmap.voice_question) |
| | | iv2_answer_2.setImageResource(R.mipmap.voice_question) |
| | | iv2_answer_3.setImageResource(R.mipmap.voice_question) |
| | | iv2_answer_1.setImageResource(R.mipmap.voice_question_2) |
| | | iv2_answer_2.setImageResource(R.mipmap.voice_question_2) |
| | | iv2_answer_3.setImageResource(R.mipmap.voice_question_2) |
| | | }else{ |
| | | iv2_answer_1.setImageResource(R.mipmap.voice_answer) |
| | | iv2_answer_2.setImageResource(R.mipmap.voice_answer) |
| | | iv2_answer_3.setImageResource(R.mipmap.voice_answer) |
| | | iv2_answer_1.setImageResource(R.mipmap.voice_answer_2) |
| | | iv2_answer_2.setImageResource(R.mipmap.voice_answer_2) |
| | | iv2_answer_3.setImageResource(R.mipmap.voice_answer_2) |
| | | } |
| | | rl_check_1.visible() |
| | | rl_check_2.visible() |
| | |
| | | val x = PropertyValuesHolder.ofFloat("translationX",0f,offx.toFloat()) |
| | | val y = PropertyValuesHolder.ofFloat("translationY",0f,offy.toFloat()) |
| | | val animator = ObjectAnimator.ofPropertyValuesHolder(v, x, y) |
| | | animator.duration = 1000 |
| | | animator.duration = 500 |
| | | animator.interpolator = LinearInterpolator() |
| | | animator.start() |
| | | animator.addListener(object :Animator.AnimatorListener{ |
| | |
| | | } |
| | | } |
| | | |
| | | if (list.filter { it.completed }.size == 2){ //全部作答,3秒后下一题 |
| | | handler?.sendEmptyMessageDelayed(TO_NEXT,3000) |
| | | if (isAutoPlaying in 1..2){ |
| | | if (voiceIndex in 0..3){ |
| | | cl_answer_1.callOnClick() |
| | | }else if (voiceIndex == 4) |
| | | cl_answer_2.callOnClick() |
| | | else if (voiceIndex == 5) |
| | | cl_answer_3.callOnClick() |
| | | else if (voiceIndex == 6){ |
| | | isAutoPlaying = if (isAutoPlaying == 1) 0 else -1 |
| | | } |
| | | } |
| | | |
| | | if (errorPlaying) |
| | | errorPlaying = false |
| | | if (rightPlaying){ |
| | | else if (rightPlaying){ |
| | | rightPlaying = false |
| | | nowVoiceView?.callOnClick() |
| | | list[questionIndex].completed = true |
| | | recoverAnswer() |
| | | }else if (list.filter { it.completed }.size == 2){ //全部作答,3秒后下一题 |
| | | handler?.sendEmptyMessageDelayed(TO_NEXT,500) //万俊杰:缩短为0.5秒 |
| | | }else if (list.filter { it.completed }.size == 1&& isAutoPlaying == 0){//答完一题,自动播放下一题 |
| | | isAutoPlaying = 2 |
| | | voiceViews.filterIndexed { index, constraintLayout -> |
| | | val subject = list[index] |
| | | constraintLayout.isEnabled&&subject.isQuestion == 1 |
| | | }.lastOrNull()?.callOnClick() |
| | | } |
| | | } |
| | | |
| | |
| | | super.onPause() |
| | | player.stopPlayMusic() |
| | | } |
| | | |
| | | override fun onDestroy() { |
| | | super.onDestroy() |
| | | handler?.removeCallbacksAndMessages(null) |
| | | EventBus.getDefault().unregister(this) |
| | | } |
| | | } |