优化 #5685
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
package io.legado.app.ui.book.audio
|
package io.legado.app.ui.book.audio
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
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.Gravity
|
||||||
@@ -44,6 +43,7 @@ import io.legado.app.utils.sendToClip
|
|||||||
import io.legado.app.utils.showDialogFragment
|
import io.legado.app.utils.showDialogFragment
|
||||||
import io.legado.app.utils.startActivity
|
import io.legado.app.utils.startActivity
|
||||||
import io.legado.app.utils.startActivityForBook
|
import io.legado.app.utils.startActivityForBook
|
||||||
|
import io.legado.app.utils.toDurationTime
|
||||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||||
import io.legado.app.utils.visible
|
import io.legado.app.utils.visible
|
||||||
import kotlinx.coroutines.Dispatchers.IO
|
import kotlinx.coroutines.Dispatchers.IO
|
||||||
@@ -67,13 +67,6 @@ class AudioPlayActivity :
|
|||||||
private var adjustProgress = false
|
private var adjustProgress = false
|
||||||
private var playMode = AudioPlay.PlayMode.LIST_END_STOP
|
private var playMode = AudioPlay.PlayMode.LIST_END_STOP
|
||||||
|
|
||||||
private val progressTimeFormat by lazy {
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
|
||||||
SimpleDateFormat("mm:ss", Locale.getDefault())
|
|
||||||
} else {
|
|
||||||
java.text.SimpleDateFormat("mm:ss", Locale.getDefault())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private val tocActivityResult = registerForActivityResult(TocActivityResult()) {
|
private val tocActivityResult = registerForActivityResult(TocActivityResult()) {
|
||||||
it?.let {
|
it?.let {
|
||||||
if (it.first != AudioPlay.book?.durChapterIndex
|
if (it.first != AudioPlay.book?.durChapterIndex
|
||||||
@@ -164,7 +157,7 @@ class AudioPlayActivity :
|
|||||||
}
|
}
|
||||||
binding.playerProgress.setOnSeekBarChangeListener(object : SeekBarChangeListener {
|
binding.playerProgress.setOnSeekBarChangeListener(object : SeekBarChangeListener {
|
||||||
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
|
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
|
||||||
binding.tvDurTime.text = progressTimeFormat.format(progress.toLong())
|
binding.tvDurTime.text = progress.toDurationTime()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStartTrackingTouch(seekBar: SeekBar) {
|
override fun onStartTrackingTouch(seekBar: SeekBar) {
|
||||||
@@ -291,11 +284,11 @@ class AudioPlayActivity :
|
|||||||
}
|
}
|
||||||
observeEventSticky<Int>(EventBus.AUDIO_SIZE) {
|
observeEventSticky<Int>(EventBus.AUDIO_SIZE) {
|
||||||
binding.playerProgress.max = it
|
binding.playerProgress.max = it
|
||||||
binding.tvAllTime.text = progressTimeFormat.format(it.toLong())
|
binding.tvAllTime.text = it.toDurationTime()
|
||||||
}
|
}
|
||||||
observeEventSticky<Int>(EventBus.AUDIO_PROGRESS) {
|
observeEventSticky<Int>(EventBus.AUDIO_PROGRESS) {
|
||||||
if (!adjustProgress) binding.playerProgress.progress = it
|
if (!adjustProgress) binding.playerProgress.progress = it
|
||||||
binding.tvDurTime.text = progressTimeFormat.format(it.toLong())
|
binding.tvDurTime.text = it.toDurationTime()
|
||||||
}
|
}
|
||||||
observeEventSticky<Int>(EventBus.AUDIO_BUFFER_PROGRESS) {
|
observeEventSticky<Int>(EventBus.AUDIO_BUFFER_PROGRESS) {
|
||||||
binding.playerProgress.secondaryProgress = it
|
binding.playerProgress.secondaryProgress = it
|
||||||
|
|||||||
@@ -36,4 +36,17 @@ fun Long.toTimeAgo(): String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return start + end
|
return start + end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Int.toDurationTime(): String {
|
||||||
|
val totalSeconds = this / 1000
|
||||||
|
val hours = totalSeconds / 3600
|
||||||
|
val minutes = (totalSeconds % 3600) / 60
|
||||||
|
val seconds = totalSeconds % 60
|
||||||
|
|
||||||
|
return if (hours > 0) {
|
||||||
|
"%d:%02d:%02d".format(hours, minutes, seconds)
|
||||||
|
} else {
|
||||||
|
"%02d:%02d".format(minutes, seconds)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user