pull/461/head
gedoor 4 years ago
parent de0ca874d9
commit 357d696d31
  1. 15
      app/src/main/java/io/legado/app/help/DefaultData.kt
  2. 4
      app/src/main/java/io/legado/app/help/ReadBookConfig.kt
  3. 2
      app/src/main/java/io/legado/app/help/ThemeConfig.kt
  4. 2
      app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt
  5. 2
      app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineViewModel.kt
  6. 5
      app/src/main/java/io/legado/app/ui/book/read/config/TocRegexViewModel.kt
  7. 1
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt
  8. 8
      app/src/main/java/io/legado/app/ui/main/MainViewModel.kt

@ -12,7 +12,7 @@ object DefaultData {
const val httpTtsFileName = "httpTTS.json"
const val txtTocRuleFileName = "txtTocRule.json"
val defaultHttpTTS by lazy {
val httpTTS by lazy {
val json =
String(
App.INSTANCE.assets.open("defaultData${File.separator}$httpTtsFileName")
@ -21,7 +21,7 @@ object DefaultData {
GSON.fromJsonArray<HttpTTS>(json)!!
}
val defaultReadConfigs by lazy {
val readConfigs by lazy {
val json = String(
App.INSTANCE.assets.open("defaultData${File.separator}${ReadBookConfig.configFileName}")
.readBytes()
@ -29,7 +29,7 @@ object DefaultData {
GSON.fromJsonArray<ReadBookConfig.Config>(json)!!
}
val defaultTxtTocRules by lazy {
val txtTocRules by lazy {
val json = String(
App.INSTANCE.assets.open("defaultData${File.separator}$txtTocRuleFileName")
.readBytes()
@ -37,11 +37,18 @@ object DefaultData {
GSON.fromJsonArray<TxtTocRule>(json)!!
}
val defaultThemeConfigs by lazy {
val themeConfigs by lazy {
val json = String(
App.INSTANCE.assets.open("defaultData${File.separator}${ThemeConfig.configFileName}")
.readBytes()
)
GSON.fromJsonArray<ThemeConfig.Config>(json)!!
}
fun importDefaultTocRules() {
App.db.txtTocRule().deleteDefault()
txtTocRules.let {
App.db.txtTocRule().insert(*it.toTypedArray())
}
}
}

@ -64,7 +64,7 @@ object ReadBookConfig {
e.printStackTrace()
}
}
(configs ?: DefaultData.defaultReadConfigs).let {
(configs ?: DefaultData.readConfigs).let {
configList.clear()
configList.addAll(it)
}
@ -126,7 +126,7 @@ object ReadBookConfig {
}
private fun resetAll() {
DefaultData.defaultReadConfigs.let {
DefaultData.readConfigs.let {
configList.clear()
configList.addAll(it)
save()

@ -16,7 +16,7 @@ object ThemeConfig {
val configFilePath = FileUtils.getPath(App.INSTANCE.filesDir, configFileName)
val configList: ArrayList<Config> by lazy {
val cList = getConfigs() ?: DefaultData.defaultThemeConfigs
val cList = getConfigs() ?: DefaultData.themeConfigs
ArrayList(cList)
}

@ -278,7 +278,7 @@ class AnalyzeTxtFile {
private fun getTocRules(): List<TxtTocRule> {
var rules = App.db.txtTocRule().enabled
if (rules.isEmpty()) {
rules = DefaultData.defaultTxtTocRules.apply {
rules = DefaultData.txtTocRules.apply {
App.db.txtTocRule().insert(*this.toTypedArray())
}.filter {
it.enable

@ -13,7 +13,7 @@ class SpeakEngineViewModel(application: Application) : BaseViewModel(application
fun importDefault() {
execute {
DefaultData.defaultHttpTTS.let {
DefaultData.httpTTS.let {
App.db.httpTTSDao().insert(*it.toTypedArray())
}
}

@ -22,10 +22,7 @@ class TocRegexViewModel(application: Application) : BaseViewModel(application) {
fun importDefault() {
execute {
App.db.txtTocRule().deleteDefault()
DefaultData.defaultTxtTocRules.let {
App.db.txtTocRule().insert(*it.toTypedArray())
}
DefaultData.importDefaultTocRules()
}
}

@ -106,6 +106,7 @@ class MainActivity : VMBaseActivity<MainViewModel>(R.layout.activity_main),
val log = String(assets.open("updateLog.md").readBytes())
TextDialog.show(supportFragmentManager, log, TextDialog.MD, 5000, true)
}
viewModel.upVersion()
}
}

@ -162,10 +162,16 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
execute {
FileUtils.deleteFile(FileUtils.getPath(context.cacheDir, "Fonts"))
if (App.db.httpTTSDao().count == 0) {
DefaultData.defaultHttpTTS.let {
DefaultData.httpTTS.let {
App.db.httpTTSDao().insert(*it.toTypedArray())
}
}
}
}
fun upVersion() {
execute {
DefaultData.importDefaultTocRules()
}
}
}
Loading…
Cancel
Save