This commit is contained in:
kunfei 2022-11-04 23:46:09 +08:00
parent 5b49c1c380
commit 44670a664f
5 changed files with 61 additions and 13 deletions

View File

@ -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<String>()
var coverData = MutableLiveData<String>()
@ -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)

View File

@ -57,7 +57,6 @@ class AudioPlayService : BaseService(),
@JvmStatic
var timeMinute: Int = 0
private set
var url: String = ""
private set

View File

@ -49,6 +49,7 @@ class AudioPlayActivity :
override val binding by viewBinding(ActivityAudioPlayBinding::inflate)
override val viewModel by viewModels<AudioPlayViewModel>()
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)
}
}

View File

@ -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
}
}

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/shape_card_view"
android:padding="8dp">
<io.legado.app.lib.theme.view.ThemeSeekBar
android:id="@+id/seek_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</FrameLayout>