kunfei 4 ani în urmă
părinte
comite
df8039e796

+ 2 - 3
app/src/main/java/io/legado/app/constant/EventBus.kt

@@ -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"

+ 3 - 2
app/src/main/java/io/legado/app/service/AudioPlayService.kt

@@ -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()
             }
         }

+ 2 - 2
app/src/main/java/io/legado/app/service/BaseReadAloudService.kt

@@ -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()
             }
         }

+ 6 - 0
app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt

@@ -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)
+        }
     }
 
 }

+ 1 - 1
app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt

@@ -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 {

+ 22 - 7
app/src/main/res/layout/activity_audio_play.xml

@@ -2,10 +2,10 @@
 <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     xmlns:tools="http://schemas.android.com/tools"
-    android:orientation="vertical"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:background="@color/background"
+    android:orientation="vertical"
     tools:context=".ui.book.audio.AudioPlayActivity">
 
     <ImageView
@@ -28,15 +28,30 @@
         app:layout_constraintTop_toTopOf="parent"
         app:themeMode="dark" />
 
+    <TextView
+        android:id="@+id/tv_timer"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_margin="16dp"
+        android:background="@drawable/shape_fillet_btn_press"
+        android:paddingLeft="6dp"
+        android:paddingRight="6dp"
+        android:textColor="@color/md_white_1000"
+        android:visibility="invisible"
+        app:drawableLeftCompat="@drawable/ic_timer_black_24dp"
+        app:drawableTint="@color/md_white_1000"
+        app:layout_constraintLeft_toLeftOf="parent"
+        app:layout_constraintTop_toBottomOf="@id/title_bar" />
+
     <TextView
         android:id="@+id/tv_speed"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_margin="16dp"
         android:background="@drawable/shape_fillet_btn_press"
+        android:paddingLeft="6dp"
+        android:paddingRight="6dp"
         android:textColor="@color/md_white_1000"
-        android:paddingStart="3dp"
-        android:paddingEnd="3dp"
         android:visibility="invisible"
         app:layout_constraintRight_toRightOf="parent"
         app:layout_constraintTop_toBottomOf="@id/title_bar" />
@@ -58,12 +73,12 @@
         android:id="@+id/tv_sub_title"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
+        android:gravity="center"
         android:paddingStart="16dp"
-        android:paddingEnd="16dp"
         android:paddingTop="6dp"
+        android:paddingEnd="16dp"
         android:paddingBottom="6dp"
         android:textColor="@color/md_white_1000"
-        android:gravity="center"
         app:layout_constraintBottom_toTopOf="@+id/ll_player_progress" />
 
     <LinearLayout
@@ -106,10 +121,10 @@
         android:id="@+id/ll_play_menu"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:paddingLeft="24dp"
-        android:paddingRight="24dp"
         android:gravity="center_vertical"
         android:orientation="horizontal"
+        android:paddingLeft="24dp"
+        android:paddingRight="24dp"
         app:layout_constraintBottom_toBottomOf="parent">
 
         <ImageView