| | |
| | | import com.share.utils.ShareUtils |
| | | import com.sinata.xqmuse.MainActivity |
| | | import com.sinata.xqmuse.R |
| | | import com.sinata.xqmuse.ThinkAudioService |
| | | import com.sinata.xqmuse.dialog.CommentDialog |
| | | import com.sinata.xqmuse.dialog.ShareDialog |
| | | import com.sinata.xqmuse.dialog.TimeSettingDialog |
| | |
| | | } |
| | | |
| | | iv_play.setOnClickListener { |
| | | if (MainActivity.voice?.id == voiceDetail?.id){ |
| | | if (ThinkAudioService.voice?.id == voiceDetail?.id){ |
| | | EventBus.getDefault().post(EmptyEvent(Const.EventCode.PAUSE_OR_RESUME_THINK)) |
| | | if (MainActivity.playing) //播放中 |
| | | if (ThinkAudioService.playing) //播放中 |
| | | iv_play.setImageResource(R.mipmap.player_pause) |
| | | else |
| | | iv_play.setImageResource(R.mipmap.play_detail) |
| | | }else{ |
| | | if (MainActivity.playing) |
| | | if (ThinkAudioService.playing) |
| | | EventBus.getDefault().post(EmptyEvent(Const.EventCode.FINISH_THINK)) |
| | | MainActivity.voice = voiceDetail |
| | | ThinkAudioService.voice = voiceDetail |
| | | EventBus.getDefault().post(EmptyEvent(Const.EventCode.START_THINK)) |
| | | iv_play.setImageResource(R.mipmap.player_pause) |
| | | } |
| | |
| | | timeSettingDialog.callback = object :StringCallback{ |
| | | override fun onResult(rst: String) { |
| | | Log.e(Const.Tag,"设置倒计时$rst") |
| | | MainActivity.finishTime = System.currentTimeMillis()+rst.toLong()*60*1000 |
| | | ThinkAudioService.finishTime = System.currentTimeMillis()+rst.toLong()*60*1000 |
| | | EventBus.getDefault().post(EmptyEvent(Const.EventCode.THINK_TIMER)) |
| | | startTimer() |
| | | } |
| | |
| | | } |
| | | |
| | | iv_recycle.setOnClickListener { |
| | | MainActivity.isRecycle = !MainActivity.isRecycle |
| | | iv_recycle.setImageResource(if (MainActivity.isRecycle) R.mipmap.danquxunhuan else R.mipmap.ic_recycle) |
| | | whiteToast(if (MainActivity.isRecycle) "当前播放模式已设置为单曲循环" else "当前播放模式已设置为顺序播放") |
| | | SPUtils.instance().put(Const.User.IS_RECYCLE,MainActivity.isRecycle).apply() |
| | | ThinkAudioService.isRecycle = !ThinkAudioService.isRecycle |
| | | iv_recycle.setImageResource(if (ThinkAudioService.isRecycle) R.mipmap.danquxunhuan else R.mipmap.ic_recycle) |
| | | whiteToast(if (ThinkAudioService.isRecycle) "当前播放模式已设置为单曲循环" else "当前播放模式已设置为顺序播放") |
| | | SPUtils.instance().put(Const.User.IS_RECYCLE,ThinkAudioService.isRecycle).apply() |
| | | } |
| | | tv_comment.setOnClickListener { |
| | | val commentDialog = CommentDialog() |
| | |
| | | } |
| | | |
| | | override fun onStartTrackingTouch(seekBar: SeekBar?) { |
| | | if (MainActivity.playing){ //播放中,让其暂停,并让按钮无法点击 |
| | | if (ThinkAudioService.playing){ //播放中,让其暂停,并让按钮无法点击 |
| | | iv_play.isEnabled = false |
| | | EventBus.getDefault().post(EmptyEvent(Const.EventCode.PAUSE_OR_RESUME_THINK)) |
| | | } |
| | | } |
| | | |
| | | override fun onStopTrackingTouch(seekBar: SeekBar?) { |
| | | if (!MainActivity.playing){//暂停时,让其播放并让按钮恢复可点击 |
| | | if (!ThinkAudioService.playing){//暂停时,让其播放并让按钮恢复可点击 |
| | | EventBus.getDefault().post(IntEvent(Const.EventCode.THINK_SEEK_PROGRESS,seekBar?.progress?:0)) |
| | | iv_play.isEnabled = true |
| | | } |
| | |
| | | |
| | | override fun initView() { |
| | | titleBar.gone() |
| | | MainActivity.isRecycle = SPUtils.instance().getBoolean(Const.User.IS_RECYCLE,false) |
| | | iv_recycle.setImageResource(if (MainActivity.isRecycle) R.mipmap.danquxunhuan else R.mipmap.ic_recycle) |
| | | ThinkAudioService.isRecycle = SPUtils.instance().getBoolean(Const.User.IS_RECYCLE,false) |
| | | iv_recycle.setImageResource(if (ThinkAudioService.isRecycle) R.mipmap.danquxunhuan else R.mipmap.ic_recycle) |
| | | voiceDetail?.apply { |
| | | iv_collect.setImageResource(if (favorite == 1) R.mipmap.collected else R.mipmap.uncollect) |
| | | iv_bg.setImageURI(backgroundUrl) |
| | | tv_name.text = meditationTitle |
| | | tv_subtitle.text = detailDescription |
| | | tv_comment.text = questionCount |
| | | val seconds = (if (MainActivity.voice?.id == id) meditationSecondList?.getOrNull(MainActivity.index) else meditationSecondList?.firstOrNull() )?: 0 |
| | | val seconds = (if (ThinkAudioService.voice?.id == id) meditationSecondList?.getOrNull(ThinkAudioService.index) else meditationSecondList?.firstOrNull() )?: 0 |
| | | tv_total.text = "%02d:%02d".format(seconds/60,seconds%60) |
| | | sb_voice.max = seconds |
| | | if (MainActivity.voice?.id == id){ //主页播放的正是本音频 |
| | | if (MainActivity.finishTime!=0L)//有倒计时存在 |
| | | if (ThinkAudioService.voice?.id == id){ //主页播放的正是本音频 |
| | | if (ThinkAudioService.finishTime!=0L)//有倒计时存在 |
| | | startTimer() |
| | | if (MainActivity.playing) //如果在播放中,按钮变为暂停 |
| | | if (ThinkAudioService.playing) //如果在播放中,按钮变为暂停 |
| | | iv_play.setImageResource(R.mipmap.player_pause) |
| | | //恢复进度 |
| | | tv_progress.text = "%02d:%02d".format(MainActivity.currentPosition/1000/60,MainActivity.currentPosition/1000%60) |
| | | sb_voice.progress = (MainActivity.currentPosition/1000).toInt() |
| | | tv_progress.text = "%02d:%02d".format(ThinkAudioService.currentPosition/1000/60,ThinkAudioService.currentPosition/1000%60) |
| | | sb_voice.progress = (ThinkAudioService.currentPosition/1000).toInt() |
| | | } |
| | | } |
| | | EventBus.getDefault().register(this) |
| | |
| | | if (countDownTimer!=null) |
| | | countDownTimer!!.cancel() |
| | | tv_timer.visible() |
| | | val offset = MainActivity.finishTime - System.currentTimeMillis() |
| | | val offset = ThinkAudioService.finishTime - System.currentTimeMillis() |
| | | countDownTimer = object :CountDownTimer(offset,1000){ |
| | | override fun onTick(millisUntilFinished: Long) { |
| | | tv_timer.text = "%02d:%02d".format(millisUntilFinished/1000/60,millisUntilFinished/1000%60) |
| | |
| | | tv_progress.text = "00:00" |
| | | tv_timer.gone() |
| | | countDownTimer?.cancel() |
| | | }else if (e.code == Const.EventCode.GOT_THINK_DURATION&&MainActivity.voice?.id == voiceDetail?.id){ |
| | | tv_total.text = "%02d:%02d".format(MainActivity.currentDuration/60,MainActivity.currentDuration%60) |
| | | sb_voice.max = MainActivity.currentDuration |
| | | }else if (e.code == Const.EventCode.GOT_THINK_POSITION&&MainActivity.voice?.id == voiceDetail?.id){ |
| | | tv_progress.text = "%02d:%02d".format(MainActivity.currentPosition/1000/60,MainActivity.currentPosition/1000%60) |
| | | sb_voice.progress = (MainActivity.currentPosition/1000).toInt() |
| | | }else if (e.code == Const.EventCode.GOT_THINK_DURATION&&ThinkAudioService.voice?.id == voiceDetail?.id){ |
| | | tv_total.text = "%02d:%02d".format(ThinkAudioService.currentDuration/60,ThinkAudioService.currentDuration%60) |
| | | sb_voice.max = ThinkAudioService.currentDuration |
| | | }else if (e.code == Const.EventCode.GOT_THINK_POSITION&&ThinkAudioService.voice?.id == voiceDetail?.id){ |
| | | tv_progress.text = "%02d:%02d".format(ThinkAudioService.currentPosition/1000/60,ThinkAudioService.currentPosition/1000%60) |
| | | sb_voice.progress = (ThinkAudioService.currentPosition/1000).toInt() |
| | | } |
| | | } |
| | | |