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 89899d3cc..8c0266c63 100644 --- a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt +++ b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt @@ -19,8 +19,8 @@ import java.io.IOException * 阅读界面配置 */ object ReadBookConfig { - private const val fileName = "readConfig.json" - private val configList: ArrayList = arrayListOf() + const val readConfigFileName = "readConfig.json" + val configList: ArrayList = arrayListOf() .apply { upConfig(this) } @@ -35,11 +35,12 @@ object ReadBookConfig { } fun upConfig(list: ArrayList = configList) { - val configFile = File(App.INSTANCE.filesDir.absolutePath + File.separator + fileName) + val configFile = + File(App.INSTANCE.filesDir.absolutePath + File.separator + readConfigFileName) val json = if (configFile.exists()) { String(configFile.readBytes()) } else { - String(App.INSTANCE.assets.open(fileName).readBytes()) + String(App.INSTANCE.assets.open(readConfigFileName).readBytes()) } try { GSON.fromJsonArray(json)?.let { @@ -63,7 +64,8 @@ object ReadBookConfig { fun save() { GlobalScope.launch(IO) { val json = GSON.toJson(configList) - val configFile = File(App.INSTANCE.filesDir.absolutePath + File.separator + fileName) + val configFile = + File(App.INSTANCE.filesDir.absolutePath + File.separator + readConfigFileName) //获取流并存储 try { BufferedWriter(FileWriter(configFile)).use { writer -> @@ -78,7 +80,7 @@ object ReadBookConfig { fun reset() { try { - val json = String(App.INSTANCE.assets.open(fileName).readBytes()) + val json = String(App.INSTANCE.assets.open(readConfigFileName).readBytes()) GSON.fromJsonArray(json)?.let { configList.clear() configList.addAll(it) diff --git a/app/src/main/java/io/legado/app/help/storage/Backup.kt b/app/src/main/java/io/legado/app/help/storage/Backup.kt index fa3ad14f9..0ac19a1e8 100644 --- a/app/src/main/java/io/legado/app/help/storage/Backup.kt +++ b/app/src/main/java/io/legado/app/help/storage/Backup.kt @@ -3,6 +3,7 @@ package io.legado.app.help.storage import io.legado.app.App import io.legado.app.R import io.legado.app.help.FileHelp +import io.legado.app.help.ReadBookConfig import io.legado.app.utils.FileUtils import io.legado.app.utils.GSON import org.jetbrains.anko.defaultSharedPreferences @@ -25,6 +26,7 @@ object Backup { backupBookSource(path) backupRssSource(path) backupReplaceRule(path) + backupReadConfig(path) backupPreference(path) WebDavHelp.backUpWebDav(path) uiThread { @@ -40,6 +42,8 @@ object Backup { backupBookSource(path) backupRssSource(path) backupReplaceRule(path) + backupReadConfig(path) + backupPreference(path) WebDavHelp.backUpWebDav(path) } } @@ -84,6 +88,13 @@ object Backup { } } + private fun backupReadConfig(path: String) { + GSON.toJson(ReadBookConfig.configList)?.let { + FileHelp.getFile(path + File.separator + ReadBookConfig.readConfigFileName) + .writeText(it) + } + } + private fun backupPreference(path: String) { Preferences.getSharedPreferences(App.INSTANCE, path, "config")?.let { sp -> val edit = sp.edit() diff --git a/app/src/main/java/io/legado/app/help/storage/Restore.kt b/app/src/main/java/io/legado/app/help/storage/Restore.kt index 593bbec5e..06543c388 100644 --- a/app/src/main/java/io/legado/app/help/storage/Restore.kt +++ b/app/src/main/java/io/legado/app/help/storage/Restore.kt @@ -13,6 +13,7 @@ import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.ReplaceRule import io.legado.app.data.entities.RssSource import io.legado.app.help.FileHelp +import io.legado.app.help.ReadBookConfig import io.legado.app.help.storage.Backup.defaultPath import io.legado.app.utils.* import org.jetbrains.anko.defaultSharedPreferences @@ -68,6 +69,17 @@ object Restore { } catch (e: Exception) { e.printStackTrace() } + try { + val file = + FileHelp.getFile(path + File.separator + ReadBookConfig.readConfigFileName) + val configFile = + File(App.INSTANCE.filesDir.absolutePath + File.separator + ReadBookConfig.readConfigFileName) + if (file.exists()) { + file.copyTo(configFile, true) + } + } catch (e: Exception) { + e.printStackTrace() + } Preferences.getSharedPreferences(App.INSTANCE, path, "config")?.all?.map { val edit = App.INSTANCE.defaultSharedPreferences.edit() when (val value = it.value) { diff --git a/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt b/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt index 3d82b5320..898c2d8d3 100644 --- a/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt +++ b/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt @@ -3,6 +3,7 @@ package io.legado.app.help.storage import android.content.Context import io.legado.app.App import io.legado.app.help.FileHelp +import io.legado.app.help.ReadBookConfig import io.legado.app.lib.webdav.WebDav import io.legado.app.lib.webdav.http.HttpAuth import io.legado.app.utils.ZipUtils @@ -80,11 +81,14 @@ object WebDavHelp { fun backUpWebDav(path: String) { if (initWebDav()) { - val paths = arrayListOf() - paths.add(path + File.separator + "bookshelf.json") - paths.add(path + File.separator + "bookSource.json") - paths.add(path + File.separator + "rssSource.json") - paths.add(path + File.separator + "replaceRule.json") + val paths = arrayListOf( + path + File.separator + "bookshelf.json", + path + File.separator + "bookSource.json", + path + File.separator + "rssSource.json", + path + File.separator + "replaceRule.json", + path + File.separator + "config.xml", + path + File.separator + ReadBookConfig.readConfigFileName + ) FileHelp.deleteFile(zipFilePath) if (ZipUtils.zipFiles(paths, zipFilePath)) { WebDav(getWebDavUrl() + "legado").makeAsDir()