pull/2533/head
kunfei 2 years ago
parent 5b49c1c380
commit 44670a664f
  1. 7
      app/src/main/java/io/legado/app/model/AudioPlay.kt
  2. 1
      app/src/main/java/io/legado/app/service/AudioPlayService.kt
  3. 7
      app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt
  4. 38
      app/src/main/java/io/legado/app/ui/book/audio/TimerSliderPopup.kt
  5. 13
      app/src/main/res/layout/popup_seek_bar.xml

@ -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) {
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)

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

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

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

@ -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>
Loading…
Cancel
Save