优化
This commit is contained in:
@@ -7,7 +7,8 @@ object EventBus {
|
||||
const val BOOKSHELF_REFRESH = "bookshelfRefresh"
|
||||
const val ALOUD_STATE = "aloud_state"
|
||||
const val TTS_PROGRESS = "ttsStart"
|
||||
const val TTS_DS = "ttsDs"
|
||||
const val AUDIO_DS = "audioDs"
|
||||
const val READ_ALOUD_DS = "readAloudDs"
|
||||
const val BATTERY_CHANGED = "batteryChanged"
|
||||
const val TIME_CHANGED = "timeChanged"
|
||||
const val UP_CONFIG = "upConfig"
|
||||
@@ -17,13 +18,11 @@ object EventBus {
|
||||
const val AUDIO_PROGRESS = "audioProgress"
|
||||
const val AUDIO_SIZE = "audioSize"
|
||||
const val AUDIO_SPEED = "audioSpeed"
|
||||
const val AUDIO_ERROR = "audioError"
|
||||
const val NOTIFY_MAIN = "notifyMain"
|
||||
const val WEB_SERVICE = "webService"
|
||||
const val UP_DOWNLOAD = "upDownload"
|
||||
const val SAVE_CONTENT = "saveContent"
|
||||
const val CHECK_SOURCE = "checkSource"
|
||||
const val CHECK_SOURCE_MESSAGE = "checkSourceMessage"
|
||||
const val CHECK_SOURCE_DONE = "checkSourceDone"
|
||||
const val TIP_COLOR = "tipColor"
|
||||
const val SOURCE_CHANGED = "sourceChanged"
|
||||
|
||||
@@ -76,6 +76,7 @@ class AudioPlayService : BaseService(),
|
||||
initMediaSession()
|
||||
initBroadcastReceiver()
|
||||
upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PLAYING)
|
||||
doDs()
|
||||
}
|
||||
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
@@ -273,7 +274,7 @@ class AudioPlayService : BaseService(),
|
||||
* 定时
|
||||
*/
|
||||
private fun doDs() {
|
||||
postEvent(EventBus.TTS_DS, timeMinute)
|
||||
postEvent(EventBus.AUDIO_DS, timeMinute)
|
||||
upNotification()
|
||||
dsJob?.cancel()
|
||||
dsJob = launch {
|
||||
@@ -287,7 +288,7 @@ class AudioPlayService : BaseService(),
|
||||
AudioPlay.stop(this@AudioPlayService)
|
||||
}
|
||||
}
|
||||
postEvent(EventBus.TTS_DS, timeMinute)
|
||||
postEvent(EventBus.AUDIO_DS, timeMinute)
|
||||
upNotification()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,7 +206,7 @@ abstract class BaseReadAloudService : BaseService(),
|
||||
*/
|
||||
@Synchronized
|
||||
private fun doDs() {
|
||||
postEvent(EventBus.TTS_DS, timeMinute)
|
||||
postEvent(EventBus.READ_ALOUD_DS, timeMinute)
|
||||
upNotification()
|
||||
dsJob?.cancel()
|
||||
dsJob = launch {
|
||||
@@ -220,7 +220,7 @@ abstract class BaseReadAloudService : BaseService(),
|
||||
ReadAloud.stop(this@BaseReadAloudService)
|
||||
}
|
||||
}
|
||||
postEvent(EventBus.TTS_DS, timeMinute)
|
||||
postEvent(EventBus.READ_ALOUD_DS, timeMinute)
|
||||
upNotification()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.legado.app.ui.book.audio
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Activity
|
||||
import android.icu.text.SimpleDateFormat
|
||||
import android.os.Build
|
||||
@@ -210,6 +211,7 @@ class AudioPlayActivity :
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
override fun observeLiveBus() {
|
||||
observeEvent<Boolean>(EventBus.MEDIA_BUTTON) {
|
||||
if (it) {
|
||||
@@ -239,6 +241,10 @@ class AudioPlayActivity :
|
||||
binding.tvSpeed.text = String.format("%.1fX", it)
|
||||
binding.tvSpeed.visible()
|
||||
}
|
||||
observeEventSticky<Int>(EventBus.AUDIO_DS) {
|
||||
binding.tvTimer.text = "${it}m"
|
||||
binding.tvTimer.visible(it > 0)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -184,7 +184,7 @@ class ReadAloudDialog : BaseDialogFragment(R.layout.dialog_read_aloud) {
|
||||
|
||||
override fun observeLiveBus() {
|
||||
observeEvent<Int>(EventBus.ALOUD_STATE) { upPlayState() }
|
||||
observeEvent<Int>(EventBus.TTS_DS) { binding.seekTimer.progress = it }
|
||||
observeEvent<Int>(EventBus.READ_ALOUD_DS) { binding.seekTimer.progress = it }
|
||||
}
|
||||
|
||||
interface CallBack {
|
||||
|
||||
Reference in New Issue
Block a user