feat: 优化

pull/243/head
gedoor 5 years ago
parent 542def704b
commit 0ee6317f92
  1. 14
      app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt
  2. 6
      app/src/main/java/io/legado/app/ui/book/read/config/TocRegexViewModel.kt

@ -278,18 +278,20 @@ class AnalyzeTxtFile {
} }
private fun getTocRules(): List<TxtTocRule> { private fun getTocRules(): List<TxtTocRule> {
val rules = App.db.txtTocRule().all val rules = App.db.txtTocRule().enabled
if (rules.isEmpty()) { if (rules.isEmpty()) {
return getDefaultRules() return getDefaultEnabledRules()
} }
return rules return rules
} }
fun getDefaultRules(): List<TxtTocRule> { fun getDefaultEnabledRules(): List<TxtTocRule> {
App.INSTANCE.assets.open("txtTocRule.json").readBytes().let { byteArray -> App.INSTANCE.assets.open("txtTocRule.json").readBytes().let { byteArray ->
GSON.fromJsonArray<TxtTocRule>(String(byteArray))?.let { GSON.fromJsonArray<TxtTocRule>(String(byteArray))?.let { txtTocRules ->
App.db.txtTocRule().insert(*it.toTypedArray()) App.db.txtTocRule().insert(*txtTocRules.toTypedArray())
return it return txtTocRules.filter {
it.enable
}
} }
} }
return emptyList() return emptyList()

@ -22,10 +22,8 @@ class TocRegexViewModel(application: Application) : BaseViewModel(application) {
fun importDefault() { fun importDefault() {
execute { execute {
AnalyzeTxtFile.getDefaultRules().let { App.db.txtTocRule().deleteDefault()
App.db.txtTocRule().deleteDefault() AnalyzeTxtFile.getDefaultEnabledRules()
App.db.txtTocRule().insert(*it.toTypedArray())
}
} }
} }

Loading…
Cancel
Save