From f6599802a3b25e05034769233928f5f7431a2f0a Mon Sep 17 00:00:00 2001 From: Horis <821938089@qq.com> Date: Sun, 16 Oct 2022 21:38:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/constant/PreferKey.kt | 1 + app/src/main/java/io/legado/app/help/JsExtensions.kt | 4 +++- app/src/main/java/io/legado/app/help/config/AppConfig.kt | 6 ++++++ .../java/io/legado/app/service/BaseReadAloudService.kt | 7 ++----- .../java/io/legado/app/ui/book/read/ReadBookViewModel.kt | 8 +++++++- .../io/legado/app/ui/book/read/config/ReadAloudDialog.kt | 1 + 6 files changed, 20 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt index a74c37bfa..84a190b07 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -116,6 +116,7 @@ object PreferKey { const val parallelExportBook = "parallelExportBook" const val progressBarBehavior = "progressBarBehavior" const val sourceEditMaxLine = "sourceEditMaxLine" + const val ttsTimer = "ttsTimer" const val cPrimary = "colorPrimary" const val cAccent = "colorAccent" diff --git a/app/src/main/java/io/legado/app/help/JsExtensions.kt b/app/src/main/java/io/legado/app/help/JsExtensions.kt index 7e150ff96..d7924c236 100644 --- a/app/src/main/java/io/legado/app/help/JsExtensions.kt +++ b/app/src/main/java/io/legado/app/help/JsExtensions.kt @@ -355,10 +355,12 @@ interface JsExtensions { fun hexDecodeToByteArray(hex: String): ByteArray? { return HexUtil.decodeHex(hex) } + /* hexString 解码为utf8String*/ fun hexDecodeToString(hex: String): String? { return HexUtil.decodeHexStr(hex) } + /* utf8 编码为hexString */ fun hexEncodeToString(utf8: String): String? { return HexUtil.encodeHexStr(utf8) @@ -675,7 +677,7 @@ interface JsExtensions { * java.createSymmetricCrypto(transformation, key, iv).encrypt(data) * java.createSymmetricCrypto(transformation, key, iv).encryptBase64(data) * java.createSymmetricCrypto(transformation, key, iv).encryptHex(data) - */ + */ /* 调用SymmetricCrypto key为null时使用随机密钥*/ fun createSymmetricCrypto( diff --git a/app/src/main/java/io/legado/app/help/config/AppConfig.kt b/app/src/main/java/io/legado/app/help/config/AppConfig.kt index 9a1881340..e46191b26 100644 --- a/app/src/main/java/io/legado/app/help/config/AppConfig.kt +++ b/app/src/main/java/io/legado/app/help/config/AppConfig.kt @@ -190,6 +190,12 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener { appCtx.putPrefInt(PreferKey.ttsSpeechRate, value) } + var ttsTimer: Int + get() = appCtx.getPrefInt(PreferKey.ttsTimer, 0) + set(value) { + appCtx.putPrefInt(PreferKey.ttsTimer, value) + } + val speechRatePlay: Int get() = if (ttsFlowSys) defaultSpeechRate else ttsSpeechRate var chineseConverterType: Int diff --git a/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt b/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt index 7547ad987..f0bb0d54c 100644 --- a/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt @@ -26,10 +26,7 @@ import io.legado.app.receiver.MediaButtonReceiver import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.ui.book.read.page.entities.TextChapter import io.legado.app.utils.* -import kotlinx.coroutines.Job -import kotlinx.coroutines.delay -import kotlinx.coroutines.isActive -import kotlinx.coroutines.launch +import kotlinx.coroutines.* import splitties.systemservices.audioManager import splitties.systemservices.powerManager @@ -92,7 +89,7 @@ abstract class BaseReadAloudService : BaseService(), initBroadcastReceiver() upNotification() upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PLAYING) - doDs() + setTimer(AppConfig.ttsTimer) } override fun onDestroy() { diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt index 2743662d7..1054936e1 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt @@ -156,7 +156,13 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { val oldBook = book.copy() val preUpdateJs = it.ruleToc?.preUpdateJs if (!preUpdateJs.isNullOrBlank()) { - AnalyzeRule(book, it).evalJS(preUpdateJs) + val source = it + kotlin.runCatching { + AnalyzeRule(book, it).evalJS(preUpdateJs) + }.onFailure { + ReadBook.upMsg("执行preUpdateJs规则失败") + AppLog.put("执行preUpdateJs规则失败 书源:${source.bookSourceName}", it) + } } WebBook.getChapterList(viewModelScope, it, book) .onSuccess(IO) { cList -> diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt index 8d4deac83..c799f9ddf 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt @@ -137,6 +137,7 @@ class ReadAloudDialog : BaseDialogFragment(R.layout.dialog_read_aloud) { } override fun onStopTrackingTouch(seekBar: SeekBar) { + AppConfig.ttsTimer = seekTimer.progress ReadAloud.setTimer(requireContext(), seekTimer.progress) } })