pull/2533/head
kunfei 2 years ago
parent 698e29b7d6
commit f60e74602e
  1. 1
      app/src/main/java/io/legado/app/model/AudioPlay.kt
  2. 3
      app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt
  3. 23
      app/src/main/java/io/legado/app/ui/book/audio/TimerSliderPopup.kt
  4. 14
      app/src/main/res/layout/popup_seek_bar.xml

@ -150,6 +150,7 @@ object AudioPlay {
appCtx.startService(intent) appCtx.startService(intent)
} else { } else {
AudioPlayService.timeMinute = minute AudioPlayService.timeMinute = minute
postEvent(EventBus.AUDIO_DS, minute)
} }
} }

@ -5,6 +5,7 @@ import android.app.Activity
import android.icu.text.SimpleDateFormat import android.icu.text.SimpleDateFormat
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.view.Gravity
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.widget.SeekBar import android.widget.SeekBar
@ -164,7 +165,7 @@ class AudioPlayActivity :
AudioPlay.adjustSpeed(this@AudioPlayActivity, -0.1f) AudioPlay.adjustSpeed(this@AudioPlayActivity, -0.1f)
} }
binding.ivTimer.setOnClickListener { binding.ivTimer.setOnClickListener {
timerSliderPopup.showAsDropDown(binding.tvSubTitle) timerSliderPopup.showAsDropDown(it, 0, (-100).dpToPx(), Gravity.TOP)
} }
} }

@ -6,12 +6,13 @@ 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 android.widget.SeekBar
import io.legado.app.R
import io.legado.app.databinding.PopupSeekBarBinding import io.legado.app.databinding.PopupSeekBarBinding
import io.legado.app.model.AudioPlay import io.legado.app.model.AudioPlay
import io.legado.app.service.AudioPlayService import io.legado.app.service.AudioPlayService
import io.legado.app.ui.widget.seekbar.SeekBarChangeListener 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) { PopupWindow(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) {
private val binding = PopupSeekBarBinding.inflate(LayoutInflater.from(context)) private val binding = PopupSeekBarBinding.inflate(LayoutInflater.from(context))
@ -20,14 +21,15 @@ class TimerSliderPopup(context: Context) :
contentView = binding.root contentView = binding.root
isTouchable = true isTouchable = true
isOutsideTouchable = true isOutsideTouchable = false
isFocusable = false isFocusable = true
binding.seekBar.max = 180 binding.seekBar.max = 180
setProcessTextValue(binding.seekBar.progress)
binding.seekBar.setOnSeekBarChangeListener(object : SeekBarChangeListener { binding.seekBar.setOnSeekBarChangeListener(object : SeekBarChangeListener {
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
setProcessTextValue(progress)
if (fromUser) { if (fromUser) {
AudioPlay.setTimer(progress) AudioPlay.setTimer(progress)
} }
@ -36,9 +38,18 @@ class TimerSliderPopup(context: Context) :
}) })
} }
override fun showAsDropDown(anchor: View?) { override fun showAsDropDown(anchor: View?, xoff: Int, yoff: Int, gravity: Int) {
super.showAsDropDown(anchor) 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 binding.seekBar.progress = AudioPlayService.timeMinute
} }
private fun setProcessTextValue(process: Int) {
binding.tvSeekValue.text = context.getString(R.string.timer_m, process)
}
} }

@ -1,13 +1,21 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@drawable/shape_card_view" android:background="@drawable/shape_card_view"
android:padding="8dp"> android:padding="8dp"
android:orientation="vertical"
android:gravity="center_horizontal">
<TextView
android:id="@+id/tv_seek_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/secondaryText" />
<io.legado.app.lib.theme.view.ThemeSeekBar <io.legado.app.lib.theme.view.ThemeSeekBar
android:id="@+id/seek_bar" android:id="@+id/seek_bar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" /> android:layout_height="wrap_content" />
</FrameLayout> </LinearLayout>
Loading…
Cancel
Save