diff --git a/app/src/main/java/io/legado/app/model/AudioPlay.kt b/app/src/main/java/io/legado/app/model/AudioPlay.kt index d41aaac27..2287586ba 100644 --- a/app/src/main/java/io/legado/app/model/AudioPlay.kt +++ b/app/src/main/java/io/legado/app/model/AudioPlay.kt @@ -17,6 +17,7 @@ import io.legado.app.utils.postEvent import io.legado.app.utils.startService import splitties.init.appCtx +@Suppress("unused") object AudioPlay { var titleData = MutableLiveData() var coverData = MutableLiveData() @@ -142,13 +143,17 @@ object AudioPlay { } fun setTimer(minute: Int) { - val intent = Intent(appCtx, AudioPlayService::class.java) - intent.action = IntentAction.setTimer - intent.putExtra("minute", minute) - appCtx.startService(intent) + if (AudioPlayService.isRun) { + val intent = Intent(appCtx, AudioPlayService::class.java) + intent.action = IntentAction.setTimer + intent.putExtra("minute", minute) + appCtx.startService(intent) + } else { + AudioPlayService.timeMinute = minute + } } - fun addTimer(context: Context) { + fun addTimer() { val intent = Intent(appCtx, AudioPlayService::class.java) intent.action = IntentAction.addTimer appCtx.startService(intent) diff --git a/app/src/main/java/io/legado/app/service/AudioPlayService.kt b/app/src/main/java/io/legado/app/service/AudioPlayService.kt index f81ab1a2b..7fbaa4734 100644 --- a/app/src/main/java/io/legado/app/service/AudioPlayService.kt +++ b/app/src/main/java/io/legado/app/service/AudioPlayService.kt @@ -57,7 +57,6 @@ class AudioPlayService : BaseService(), @JvmStatic var timeMinute: Int = 0 - private set var url: String = "" private set diff --git a/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt b/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt index 609d8831b..7b1ea4f39 100644 --- a/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt @@ -49,6 +49,7 @@ class AudioPlayActivity : override val binding by viewBinding(ActivityAudioPlayBinding::inflate) override val viewModel by viewModels() + private val timerSliderPopup by lazy { TimerSliderPopup(this) } private var adjustProgress = false private val progressTimeFormat by lazy { @@ -163,11 +164,7 @@ class AudioPlayActivity : AudioPlay.adjustSpeed(this@AudioPlayActivity, -0.1f) } binding.ivTimer.setOnClickListener { - if (AudioPlayService.isRun) { - AudioPlay.addTimer(this) - } else { - toastOnUi(R.string.cannot_timed_non_playback) - } + timerSliderPopup.showAsDropDown(binding.tvSubTitle) } } diff --git a/app/src/main/java/io/legado/app/ui/book/audio/TimerSliderPopup.kt b/app/src/main/java/io/legado/app/ui/book/audio/TimerSliderPopup.kt index 3a5a498c0..e08cac88d 100644 --- a/app/src/main/java/io/legado/app/ui/book/audio/TimerSliderPopup.kt +++ b/app/src/main/java/io/legado/app/ui/book/audio/TimerSliderPopup.kt @@ -1,10 +1,44 @@ package io.legado.app.ui.book.audio +import android.content.Context +import android.view.LayoutInflater +import android.view.View import android.view.ViewGroup import android.widget.PopupWindow +import android.widget.SeekBar +import io.legado.app.databinding.PopupSeekBarBinding +import io.legado.app.model.AudioPlay +import io.legado.app.service.AudioPlayService +import io.legado.app.ui.widget.seekbar.SeekBarChangeListener -class TimerSliderPopup : - PopupWindow(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT) { +class TimerSliderPopup(context: Context) : + PopupWindow(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) { + private val binding = PopupSeekBarBinding.inflate(LayoutInflater.from(context)) + + init { + contentView = binding.root + + isTouchable = true + isOutsideTouchable = true + isFocusable = false + + binding.seekBar.max = 180 + + binding.seekBar.setOnSeekBarChangeListener(object : SeekBarChangeListener { + + override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { + if (fromUser) { + AudioPlay.setTimer(progress) + } + } + + }) + } + + override fun showAsDropDown(anchor: View?) { + super.showAsDropDown(anchor) + binding.seekBar.progress = AudioPlayService.timeMinute + } } \ No newline at end of file diff --git a/app/src/main/res/layout/popup_seek_bar.xml b/app/src/main/res/layout/popup_seek_bar.xml new file mode 100644 index 000000000..c47d4037b --- /dev/null +++ b/app/src/main/res/layout/popup_seek_bar.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file