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 io.legado.app.utils.startService
import splitties.init.appCtx import splitties.init.appCtx
@Suppress("unused")
object AudioPlay { object AudioPlay {
var titleData = MutableLiveData<String>() var titleData = MutableLiveData<String>()
var coverData = MutableLiveData<String>() var coverData = MutableLiveData<String>()
@ -142,13 +143,17 @@ object AudioPlay {
} }
fun setTimer(minute: Int) { fun setTimer(minute: Int) {
if (AudioPlayService.isRun) {
val intent = Intent(appCtx, AudioPlayService::class.java) val intent = Intent(appCtx, AudioPlayService::class.java)
intent.action = IntentAction.setTimer intent.action = IntentAction.setTimer
intent.putExtra("minute", minute) intent.putExtra("minute", minute)
appCtx.startService(intent) appCtx.startService(intent)
} else {
AudioPlayService.timeMinute = minute
}
} }
fun addTimer(context: Context) { fun addTimer() {
val intent = Intent(appCtx, AudioPlayService::class.java) val intent = Intent(appCtx, AudioPlayService::class.java)
intent.action = IntentAction.addTimer intent.action = IntentAction.addTimer
appCtx.startService(intent) appCtx.startService(intent)

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

@ -49,6 +49,7 @@ class AudioPlayActivity :
override val binding by viewBinding(ActivityAudioPlayBinding::inflate) override val binding by viewBinding(ActivityAudioPlayBinding::inflate)
override val viewModel by viewModels<AudioPlayViewModel>() override val viewModel by viewModels<AudioPlayViewModel>()
private val timerSliderPopup by lazy { TimerSliderPopup(this) }
private var adjustProgress = false private var adjustProgress = false
private val progressTimeFormat by lazy { private val progressTimeFormat by lazy {
@ -163,11 +164,7 @@ class AudioPlayActivity :
AudioPlay.adjustSpeed(this@AudioPlayActivity, -0.1f) AudioPlay.adjustSpeed(this@AudioPlayActivity, -0.1f)
} }
binding.ivTimer.setOnClickListener { binding.ivTimer.setOnClickListener {
if (AudioPlayService.isRun) { timerSliderPopup.showAsDropDown(binding.tvSubTitle)
AudioPlay.addTimer(this)
} else {
toastOnUi(R.string.cannot_timed_non_playback)
}
} }
} }

@ -1,10 +1,44 @@
package io.legado.app.ui.book.audio 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.view.ViewGroup
import android.widget.PopupWindow 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 : class TimerSliderPopup(context: Context) :
PopupWindow(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT) { 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