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 2287586ba..6f372a2e8 100644 --- a/app/src/main/java/io/legado/app/model/AudioPlay.kt +++ b/app/src/main/java/io/legado/app/model/AudioPlay.kt @@ -150,6 +150,7 @@ object AudioPlay { appCtx.startService(intent) } else { AudioPlayService.timeMinute = minute + postEvent(EventBus.AUDIO_DS, minute) } } 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 7b1ea4f39..4511704df 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 @@ -5,6 +5,7 @@ import android.app.Activity import android.icu.text.SimpleDateFormat import android.os.Build import android.os.Bundle +import android.view.Gravity import android.view.Menu import android.view.MenuItem import android.widget.SeekBar @@ -164,7 +165,7 @@ class AudioPlayActivity : AudioPlay.adjustSpeed(this@AudioPlayActivity, -0.1f) } binding.ivTimer.setOnClickListener { - timerSliderPopup.showAsDropDown(binding.tvSubTitle) + timerSliderPopup.showAsDropDown(it, 0, (-100).dpToPx(), Gravity.TOP) } } 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 e08cac88d..f8025039f 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 @@ -6,12 +6,13 @@ import android.view.View import android.view.ViewGroup import android.widget.PopupWindow import android.widget.SeekBar +import io.legado.app.R 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(context: Context) : +class TimerSliderPopup(private val context: Context) : PopupWindow(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) { private val binding = PopupSeekBarBinding.inflate(LayoutInflater.from(context)) @@ -20,14 +21,15 @@ class TimerSliderPopup(context: Context) : contentView = binding.root isTouchable = true - isOutsideTouchable = true - isFocusable = false + isOutsideTouchable = false + isFocusable = true binding.seekBar.max = 180 - + setProcessTextValue(binding.seekBar.progress) binding.seekBar.setOnSeekBarChangeListener(object : SeekBarChangeListener { override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { + setProcessTextValue(progress) if (fromUser) { AudioPlay.setTimer(progress) } @@ -36,9 +38,18 @@ class TimerSliderPopup(context: Context) : }) } - override fun showAsDropDown(anchor: View?) { - super.showAsDropDown(anchor) + override fun showAsDropDown(anchor: View?, xoff: Int, yoff: Int, gravity: Int) { + super.showAsDropDown(anchor, xoff, yoff, gravity) + binding.seekBar.progress = AudioPlayService.timeMinute + } + + override fun showAtLocation(parent: View?, gravity: Int, x: Int, y: Int) { + super.showAtLocation(parent, gravity, x, y) binding.seekBar.progress = AudioPlayService.timeMinute } + private fun setProcessTextValue(process: Int) { + binding.tvSeekValue.text = context.getString(R.string.timer_m, process) + } + } \ 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 index c47d4037b..ef0eee190 100644 --- a/app/src/main/res/layout/popup_seek_bar.xml +++ b/app/src/main/res/layout/popup_seek_bar.xml @@ -1,13 +1,21 @@ - + android:padding="8dp" + android:orientation="vertical" + android:gravity="center_horizontal"> + + - \ No newline at end of file + \ No newline at end of file