Merge pull request #2441 from 821938089/little-fix

一些优化
This commit is contained in:
Horis
2022-10-16 21:42:40 +08:00
committed by GitHub
6 changed files with 20 additions and 7 deletions
@@ -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"
@@ -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(
@@ -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
@@ -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() {
@@ -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 ->
@@ -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)
}
})