备份键盘辅助配置

pull/1814/head
kunfei 3 years ago
parent 338c32c92c
commit 1779754ca3
  1. 7
      app/src/main/java/io/legado/app/help/DefaultData.kt
  2. 11
      app/src/main/java/io/legado/app/help/storage/Backup.kt
  3. 5
      app/src/main/java/io/legado/app/help/storage/Restore.kt

@ -16,13 +16,10 @@ import java.io.File
object DefaultData { object DefaultData {
const val httpTtsFileName = "httpTTS.json"
const val txtTocRuleFileName = "txtTocRule.json"
val httpTTS: List<HttpTTS> by lazy { val httpTTS: List<HttpTTS> by lazy {
val json = val json =
String( String(
appCtx.assets.open("defaultData${File.separator}$httpTtsFileName") appCtx.assets.open("defaultData${File.separator}httpTTS.json")
.readBytes() .readBytes()
) )
HttpTTS.fromJsonArray(json) HttpTTS.fromJsonArray(json)
@ -39,7 +36,7 @@ object DefaultData {
val txtTocRules: List<TxtTocRule> by lazy { val txtTocRules: List<TxtTocRule> by lazy {
val json = String( val json = String(
appCtx.assets.open("defaultData${File.separator}$txtTocRuleFileName") appCtx.assets.open("defaultData${File.separator}txtTocRule.json")
.readBytes() .readBytes()
) )
GSON.fromJsonArray<TxtTocRule>(json).getOrNull() ?: emptyList() GSON.fromJsonArray<TxtTocRule>(json).getOrNull() ?: emptyList()

@ -7,7 +7,6 @@ import io.legado.app.R
import io.legado.app.constant.AppLog import io.legado.app.constant.AppLog
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb import io.legado.app.data.appDb
import io.legado.app.help.DefaultData
import io.legado.app.help.config.ReadBookConfig import io.legado.app.help.config.ReadBookConfig
import io.legado.app.help.config.ThemeConfig import io.legado.app.help.config.ThemeConfig
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
@ -38,8 +37,9 @@ object Backup {
"readRecord.json", "readRecord.json",
"searchHistory.json", "searchHistory.json",
"sourceSub.json", "sourceSub.json",
DefaultData.txtTocRuleFileName, "txtTocRule.json",
DefaultData.httpTtsFileName, "httpTTS.json",
"keyboardAssists.json",
ReadBookConfig.configFileName, ReadBookConfig.configFileName,
ReadBookConfig.shareConfigFileName, ReadBookConfig.shareConfigFileName,
ThemeConfig.configFileName, ThemeConfig.configFileName,
@ -77,8 +77,9 @@ object Backup {
writeListToJson(appDb.readRecordDao.all, "readRecord.json", backupPath) writeListToJson(appDb.readRecordDao.all, "readRecord.json", backupPath)
writeListToJson(appDb.searchKeywordDao.all, "searchHistory.json", backupPath) writeListToJson(appDb.searchKeywordDao.all, "searchHistory.json", backupPath)
writeListToJson(appDb.ruleSubDao.all, "sourceSub.json", backupPath) writeListToJson(appDb.ruleSubDao.all, "sourceSub.json", backupPath)
writeListToJson(appDb.txtTocRuleDao.all, DefaultData.txtTocRuleFileName, backupPath) writeListToJson(appDb.txtTocRuleDao.all, "txtTocRule.json", backupPath)
writeListToJson(appDb.httpTTSDao.all, DefaultData.httpTtsFileName, backupPath) writeListToJson(appDb.httpTTSDao.all, "httpTTS.json", backupPath)
writeListToJson(appDb.keyboardAssistsDao.all, "keyboardAssists.json", backupPath)
GSON.toJson(ReadBookConfig.configList).let { GSON.toJson(ReadBookConfig.configList).let {
FileUtils.createFileIfNotExist(backupPath + File.separator + ReadBookConfig.configFileName) FileUtils.createFileIfNotExist(backupPath + File.separator + ReadBookConfig.configFileName)
.writeText(it) .writeText(it)

@ -11,7 +11,6 @@ import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb import io.legado.app.data.appDb
import io.legado.app.data.entities.* import io.legado.app.data.entities.*
import io.legado.app.help.DefaultData
import io.legado.app.help.LauncherIconHelp import io.legado.app.help.LauncherIconHelp
import io.legado.app.help.config.ReadBookConfig import io.legado.app.help.config.ReadBookConfig
import io.legado.app.help.config.ThemeConfig import io.legado.app.help.config.ThemeConfig
@ -96,10 +95,10 @@ object Restore {
fileToListT<RuleSub>(path, "sourceSub.json")?.let { fileToListT<RuleSub>(path, "sourceSub.json")?.let {
appDb.ruleSubDao.insert(*it.toTypedArray()) appDb.ruleSubDao.insert(*it.toTypedArray())
} }
fileToListT<TxtTocRule>(path, DefaultData.txtTocRuleFileName)?.let { fileToListT<TxtTocRule>(path, "txtTocRule.json")?.let {
appDb.txtTocRuleDao.insert(*it.toTypedArray()) appDb.txtTocRuleDao.insert(*it.toTypedArray())
} }
fileToListT<HttpTTS>(path, DefaultData.httpTtsFileName)?.let { fileToListT<HttpTTS>(path, "httpTTS.json")?.let {
appDb.httpTTSDao.insert(*it.toTypedArray()) appDb.httpTTSDao.insert(*it.toTypedArray())
} }
fileToListT<ReadRecord>(path, "readRecord.json")?.let { fileToListT<ReadRecord>(path, "readRecord.json")?.let {

Loading…
Cancel
Save