From d241fd410d719c19c8e2c7e34ea2a0163af38ab6 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 29 Dec 2020 20:40:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E7=89=88=E6=9C=AC=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=9C=A8=E7=BA=BF=E6=9C=97=E8=AF=BB=E8=A7=84?= =?UTF-8?q?=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/help/DefaultData.kt | 6 ++++++ app/src/main/java/io/legado/app/help/LocalConfig.kt | 6 ++++++ .../app/ui/book/read/config/SpeakEngineViewModel.kt | 4 +--- app/src/main/java/io/legado/app/ui/main/MainViewModel.kt | 8 +++++++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/DefaultData.kt b/app/src/main/java/io/legado/app/help/DefaultData.kt index db14e1f29..b9708ba91 100644 --- a/app/src/main/java/io/legado/app/help/DefaultData.kt +++ b/app/src/main/java/io/legado/app/help/DefaultData.kt @@ -45,6 +45,12 @@ object DefaultData { GSON.fromJsonArray(json)!! } + fun importDefaultHttpTTS() { + httpTTS.let { + App.db.httpTTSDao.insert(*it.toTypedArray()) + } + } + fun importDefaultTocRules() { App.db.txtTocRule.deleteDefault() txtTocRules.let { diff --git a/app/src/main/java/io/legado/app/help/LocalConfig.kt b/app/src/main/java/io/legado/app/help/LocalConfig.kt index 084113293..ac0d3034d 100644 --- a/app/src/main/java/io/legado/app/help/LocalConfig.kt +++ b/app/src/main/java/io/legado/app/help/LocalConfig.kt @@ -63,4 +63,10 @@ object LocalConfig { val ruleHelpVersionIsLast: Boolean get() = isLastVersion(1, "ruleHelpVersion") + + val hasUpHttpTTS: Boolean + get() = isLastVersion(1, "httpTtsVersion") + + val hasUpTxtTocRule: Boolean + get() = isLastVersion(1, "txtTocRuleVersion") } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineViewModel.kt index b72f65343..bfcb8ae2b 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineViewModel.kt @@ -14,9 +14,7 @@ class SpeakEngineViewModel(application: Application) : BaseViewModel(application fun importDefault() { execute { - DefaultData.httpTTS.let { - App.db.httpTTSDao.insert(*it.toTypedArray()) - } + DefaultData.importDefaultHttpTTS() } } diff --git a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt index 239b0c9ff..242e94baa 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt @@ -9,6 +9,7 @@ import io.legado.app.data.entities.Book import io.legado.app.help.AppConfig import io.legado.app.help.BookHelp import io.legado.app.help.DefaultData +import io.legado.app.help.LocalConfig import io.legado.app.model.webBook.WebBook import io.legado.app.service.help.CacheBook import io.legado.app.utils.FileUtils @@ -148,7 +149,12 @@ class MainViewModel(application: Application) : BaseViewModel(application) { fun upVersion() { execute { - DefaultData.importDefaultTocRules() + if (LocalConfig.hasUpHttpTTS) { + DefaultData.importDefaultHttpTTS() + } + if (LocalConfig.hasUpTxtTocRule) { + DefaultData.importDefaultTocRules() + } } } } \ No newline at end of file