| | |
| | | |
| | | import android.os.CountDownTimer |
| | | import android.util.Log |
| | | import android.widget.SeekBar |
| | | import androidx.core.os.bundleOf |
| | | import cn.sinata.xldutils.gone |
| | | import cn.sinata.xldutils.utils.SPUtils |
| | |
| | | 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 |
| | |
| | | import com.sinata.xqmuse.ui.TransparentStatusBarActivity |
| | | import com.sinata.xqmuse.utils.Const |
| | | import com.sinata.xqmuse.utils.event.EmptyEvent |
| | | import com.sinata.xqmuse.utils.event.IntEvent |
| | | import com.sinata.xqmuse.utils.interfaces.StringCallback |
| | | import com.umeng.socialize.bean.SHARE_MEDIA |
| | | import kotlinx.android.synthetic.main.activity_voice_detail.* |
| | | import org.greenrobot.eventbus.EventBus |
| | | import org.greenrobot.eventbus.Subscribe |
| | | import org.jetbrains.anko.toast |
| | | |
| | | class VoiceDetailActivity:TransparentStatusBarActivity() { |
| | | override fun setContentView() = R.layout.activity_voice_detail |
| | |
| | | } |
| | | |
| | | 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() |
| | |
| | | val volumeDialog = VolumeDialog() |
| | | volumeDialog.showAllowingStateLoss(supportFragmentManager,"vol") |
| | | } |
| | | |
| | | sb_voice.setOnSeekBarChangeListener(object :SeekBar.OnSeekBarChangeListener{ |
| | | override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { |
| | | } |
| | | |
| | | override fun onStartTrackingTouch(seekBar: SeekBar?) { |
| | | if (ThinkAudioService.playing){ //播放中,让其暂停,并让按钮无法点击 |
| | | iv_play.isEnabled = false |
| | | EventBus.getDefault().post(EmptyEvent(Const.EventCode.PAUSE_OR_RESUME_THINK)) |
| | | } |
| | | } |
| | | |
| | | override fun onStopTrackingTouch(seekBar: SeekBar?) { |
| | | 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 |
| | | if (MainActivity.voice?.id == id&&MainActivity.playing) //是本音频并且播放中 |
| | | iv_play.setImageResource(R.mipmap.player_pause) |
| | | else |
| | | iv_play.setImageResource(R.mipmap.play_detail) |
| | | 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) |
| | | if (MainActivity.voice?.id == id&&MainActivity.finishTime!=0L)//有倒计时存在 |
| | | startTimer() |
| | | sb_voice.max = seconds |
| | | if (ThinkAudioService.voice?.id == id){ //主页播放的正是本音频 |
| | | if (ThinkAudioService.finishTime!=0L)//有倒计时存在 |
| | | startTimer() |
| | | if (ThinkAudioService.playing) //如果在播放中,按钮变为暂停 |
| | | iv_play.setImageResource(R.mipmap.player_pause) |
| | | //恢复进度 |
| | | 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) |
| | | iv_play.keepScreenOn = true |
| | | } |
| | | |
| | | private fun startTimer(){ |
| | | 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 |
| | | }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() |
| | | } |
| | | } |
| | | |