pull/464/head
Robot 4 years ago
commit 27f5b79274
  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/ReadBookActivity.kt
  6. 2
      app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineViewModel.kt
  7. 5
      app/src/main/java/io/legado/app/ui/book/read/config/TocRegexViewModel.kt
  8. 1
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt
  9. 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 httpTtsFileName = "httpTTS.json"
const val txtTocRuleFileName = "txtTocRule.json" const val txtTocRuleFileName = "txtTocRule.json"
val defaultHttpTTS by lazy { val httpTTS by lazy {
val json = val json =
String( String(
App.INSTANCE.assets.open("defaultData${File.separator}$httpTtsFileName") App.INSTANCE.assets.open("defaultData${File.separator}$httpTtsFileName")
@ -21,7 +21,7 @@ object DefaultData {
GSON.fromJsonArray<HttpTTS>(json)!! GSON.fromJsonArray<HttpTTS>(json)!!
} }
val defaultReadConfigs by lazy { val readConfigs by lazy {
val json = String( val json = String(
App.INSTANCE.assets.open("defaultData${File.separator}${ReadBookConfig.configFileName}") App.INSTANCE.assets.open("defaultData${File.separator}${ReadBookConfig.configFileName}")
.readBytes() .readBytes()
@ -29,7 +29,7 @@ object DefaultData {
GSON.fromJsonArray<ReadBookConfig.Config>(json)!! GSON.fromJsonArray<ReadBookConfig.Config>(json)!!
} }
val defaultTxtTocRules by lazy { val txtTocRules by lazy {
val json = String( val json = String(
App.INSTANCE.assets.open("defaultData${File.separator}$txtTocRuleFileName") App.INSTANCE.assets.open("defaultData${File.separator}$txtTocRuleFileName")
.readBytes() .readBytes()
@ -37,11 +37,18 @@ object DefaultData {
GSON.fromJsonArray<TxtTocRule>(json)!! GSON.fromJsonArray<TxtTocRule>(json)!!
} }
val defaultThemeConfigs by lazy { val themeConfigs by lazy {
val json = String( val json = String(
App.INSTANCE.assets.open("defaultData${File.separator}${ThemeConfig.configFileName}") App.INSTANCE.assets.open("defaultData${File.separator}${ThemeConfig.configFileName}")
.readBytes() .readBytes()
) )
GSON.fromJsonArray<ThemeConfig.Config>(json)!! 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() e.printStackTrace()
} }
} }
(configs ?: DefaultData.defaultReadConfigs).let { (configs ?: DefaultData.readConfigs).let {
configList.clear() configList.clear()
configList.addAll(it) configList.addAll(it)
} }
@ -126,7 +126,7 @@ object ReadBookConfig {
} }
private fun resetAll() { private fun resetAll() {
DefaultData.defaultReadConfigs.let { DefaultData.readConfigs.let {
configList.clear() configList.clear()
configList.addAll(it) configList.addAll(it)
save() save()

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

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

@ -832,7 +832,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
positions[1] + 1, positions[1] + 1,
positions[4] positions[4]
) )
//todo: consider change page, jump to scroll position //consider change page, jump to scroll position
-1 -> page_view.curPage.selectEndMoveIndex(1, 0, positions[4]) -1 -> page_view.curPage.selectEndMoveIndex(1, 0, positions[4])
} }
page_view.isTextSelected = true page_view.isTextSelected = true

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

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

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

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