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 d1c016b90..a74c13402 100644 --- a/app/src/main/java/io/legado/app/help/DefaultData.kt +++ b/app/src/main/java/io/legado/app/help/DefaultData.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(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(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(json)!! } - val defaultThemeConfigs by lazy { + val themeConfigs by lazy { val json = String( App.INSTANCE.assets.open("defaultData${File.separator}${ThemeConfig.configFileName}") .readBytes() ) GSON.fromJsonArray(json)!! } + + fun importDefaultTocRules() { + App.db.txtTocRule().deleteDefault() + txtTocRules.let { + App.db.txtTocRule().insert(*it.toTypedArray()) + } + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt index faa36e9c0..6b388742f 100644 --- a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt +++ b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt @@ -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() diff --git a/app/src/main/java/io/legado/app/help/ThemeConfig.kt b/app/src/main/java/io/legado/app/help/ThemeConfig.kt index 4f92a039a..b4875ef8b 100644 --- a/app/src/main/java/io/legado/app/help/ThemeConfig.kt +++ b/app/src/main/java/io/legado/app/help/ThemeConfig.kt @@ -16,7 +16,7 @@ object ThemeConfig { val configFilePath = FileUtils.getPath(App.INSTANCE.filesDir, configFileName) val configList: ArrayList by lazy { - val cList = getConfigs() ?: DefaultData.defaultThemeConfigs + val cList = getConfigs() ?: DefaultData.themeConfigs ArrayList(cList) } diff --git a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt index e3c46ed43..5e3297026 100644 --- a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt @@ -278,7 +278,7 @@ class AnalyzeTxtFile { private fun getTocRules(): List { 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 diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 9b718510c..5414ba3e8 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -832,7 +832,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo positions[1] + 1, 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]) } page_view.isTextSelected = true 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 bc30c346b..81e4f03a2 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 @@ -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()) } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexViewModel.kt index cebc521b8..1c2d89370 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexViewModel.kt @@ -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() } } diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index e14f0035a..59a5bd79c 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -106,6 +106,7 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), val log = String(assets.open("updateLog.md").readBytes()) TextDialog.show(supportFragmentManager, log, TextDialog.MD, 5000, true) } + viewModel.upVersion() } } 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 904df39e4..a87ea2e32 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 @@ -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() + } + } } \ No newline at end of file