Merge pull request #2441 from 821938089/little-fix

一些优化
pull/2446/head
Horis 2 years ago committed by GitHub
commit 7f6862f8d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  2. 2
      app/src/main/java/io/legado/app/help/JsExtensions.kt
  3. 6
      app/src/main/java/io/legado/app/help/config/AppConfig.kt
  4. 7
      app/src/main/java/io/legado/app/service/BaseReadAloudService.kt
  5. 6
      app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt
  6. 1
      app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt

@ -116,6 +116,7 @@ object PreferKey {
const val parallelExportBook = "parallelExportBook" const val parallelExportBook = "parallelExportBook"
const val progressBarBehavior = "progressBarBehavior" const val progressBarBehavior = "progressBarBehavior"
const val sourceEditMaxLine = "sourceEditMaxLine" const val sourceEditMaxLine = "sourceEditMaxLine"
const val ttsTimer = "ttsTimer"
const val cPrimary = "colorPrimary" const val cPrimary = "colorPrimary"
const val cAccent = "colorAccent" const val cAccent = "colorAccent"

@ -355,10 +355,12 @@ interface JsExtensions {
fun hexDecodeToByteArray(hex: String): ByteArray? { fun hexDecodeToByteArray(hex: String): ByteArray? {
return HexUtil.decodeHex(hex) return HexUtil.decodeHex(hex)
} }
/* hexString 解码为utf8String*/ /* hexString 解码为utf8String*/
fun hexDecodeToString(hex: String): String? { fun hexDecodeToString(hex: String): String? {
return HexUtil.decodeHexStr(hex) return HexUtil.decodeHexStr(hex)
} }
/* utf8 编码为hexString */ /* utf8 编码为hexString */
fun hexEncodeToString(utf8: String): String? { fun hexEncodeToString(utf8: String): String? {
return HexUtil.encodeHexStr(utf8) return HexUtil.encodeHexStr(utf8)

@ -190,6 +190,12 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
appCtx.putPrefInt(PreferKey.ttsSpeechRate, value) 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 val speechRatePlay: Int get() = if (ttsFlowSys) defaultSpeechRate else ttsSpeechRate
var chineseConverterType: Int var chineseConverterType: Int

@ -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.ReadBookActivity
import io.legado.app.ui.book.read.page.entities.TextChapter import io.legado.app.ui.book.read.page.entities.TextChapter
import io.legado.app.utils.* import io.legado.app.utils.*
import kotlinx.coroutines.Job import kotlinx.coroutines.*
import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import splitties.systemservices.audioManager import splitties.systemservices.audioManager
import splitties.systemservices.powerManager import splitties.systemservices.powerManager
@ -92,7 +89,7 @@ abstract class BaseReadAloudService : BaseService(),
initBroadcastReceiver() initBroadcastReceiver()
upNotification() upNotification()
upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PLAYING) upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PLAYING)
doDs() setTimer(AppConfig.ttsTimer)
} }
override fun onDestroy() { override fun onDestroy() {

@ -156,7 +156,13 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
val oldBook = book.copy() val oldBook = book.copy()
val preUpdateJs = it.ruleToc?.preUpdateJs val preUpdateJs = it.ruleToc?.preUpdateJs
if (!preUpdateJs.isNullOrBlank()) { if (!preUpdateJs.isNullOrBlank()) {
val source = it
kotlin.runCatching {
AnalyzeRule(book, it).evalJS(preUpdateJs) AnalyzeRule(book, it).evalJS(preUpdateJs)
}.onFailure {
ReadBook.upMsg("执行preUpdateJs规则失败")
AppLog.put("执行preUpdateJs规则失败 书源:${source.bookSourceName}", it)
}
} }
WebBook.getChapterList(viewModelScope, it, book) WebBook.getChapterList(viewModelScope, it, book)
.onSuccess(IO) { cList -> .onSuccess(IO) { cList ->

@ -137,6 +137,7 @@ class ReadAloudDialog : BaseDialogFragment(R.layout.dialog_read_aloud) {
} }
override fun onStopTrackingTouch(seekBar: SeekBar) { override fun onStopTrackingTouch(seekBar: SeekBar) {
AppConfig.ttsTimer = seekTimer.progress
ReadAloud.setTimer(requireContext(), seekTimer.progress) ReadAloud.setTimer(requireContext(), seekTimer.progress)
} }
}) })

Loading…
Cancel
Save