pull/1679/head
kunfei 3 years ago
parent a43b842ba7
commit 5ca2f10fac
  1. 4
      app/src/main/java/io/legado/app/help/storage/Backup.kt
  2. 10
      app/src/main/java/io/legado/app/help/storage/BackupConfig.kt
  3. 6
      app/src/main/java/io/legado/app/help/storage/Restore.kt
  4. 15
      app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt

@ -20,7 +20,7 @@ import java.io.FileOutputStream
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
object Backup : BackupRestore() { object Backup {
val backupPath: String by lazy { val backupPath: String by lazy {
appCtx.filesDir.getFile("backup").absolutePath appCtx.filesDir.getFile("backup").absolutePath
@ -94,7 +94,7 @@ object Backup : BackupRestore() {
Preferences.getSharedPreferences(appCtx, backupPath, "config")?.let { sp -> Preferences.getSharedPreferences(appCtx, backupPath, "config")?.let { sp ->
val edit = sp.edit() val edit = sp.edit()
appCtx.defaultSharedPreferences.all.forEach { (key, value) -> appCtx.defaultSharedPreferences.all.forEach { (key, value) ->
if (keyIsNotIgnore(key)) { if (BackupConfig.keyIsNotIgnore(key)) {
when (value) { when (value) {
is Int -> edit.putInt(key, value) is Int -> edit.putInt(key, value)
is Boolean -> edit.putBoolean(key, value) is Boolean -> edit.putBoolean(key, value)

@ -7,7 +7,7 @@ import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonObject import io.legado.app.utils.fromJsonObject
import splitties.init.appCtx import splitties.init.appCtx
abstract class BackupRestore { object BackupConfig {
private val ignoreConfigPath = FileUtils.getPath(appCtx.filesDir, "restoreIgnore.json") private val ignoreConfigPath = FileUtils.getPath(appCtx.filesDir, "restoreIgnore.json")
val ignoreConfig: HashMap<String, Boolean> by lazy { val ignoreConfig: HashMap<String, Boolean> by lazy {
@ -16,7 +16,7 @@ abstract class BackupRestore {
GSON.fromJsonObject<HashMap<String, Boolean>>(json).getOrNull() ?: hashMapOf() GSON.fromJsonObject<HashMap<String, Boolean>>(json).getOrNull() ?: hashMapOf()
} }
//忽略key //配置忽略key
val ignoreKeys = arrayOf( val ignoreKeys = arrayOf(
"readConfig", "readConfig",
PreferKey.themeMode, PreferKey.themeMode,
@ -25,7 +25,7 @@ abstract class BackupRestore {
PreferKey.threadCount PreferKey.threadCount
) )
//忽略标题 //配置忽略标题
val ignoreTitle = arrayOf( val ignoreTitle = arrayOf(
appCtx.getString(R.string.read_config), appCtx.getString(R.string.read_config),
appCtx.getString(R.string.theme_mode), appCtx.getString(R.string.theme_mode),
@ -52,7 +52,7 @@ abstract class BackupRestore {
) )
protected fun keyIsNotIgnore(key: String): Boolean { fun keyIsNotIgnore(key: String): Boolean {
return when { return when {
ignorePrefKeys.contains(key) -> false ignorePrefKeys.contains(key) -> false
readPrefKeys.contains(key) && ignoreReadConfig -> false readPrefKeys.contains(key) && ignoreReadConfig -> false
@ -64,7 +64,7 @@ abstract class BackupRestore {
} }
} }
protected val ignoreReadConfig: Boolean val ignoreReadConfig: Boolean
get() = ignoreConfig["readConfig"] == true get() = ignoreConfig["readConfig"] == true
private val ignoreThemeMode: Boolean private val ignoreThemeMode: Boolean
get() = ignoreConfig[PreferKey.themeMode] == true get() = ignoreConfig[PreferKey.themeMode] == true

@ -24,7 +24,7 @@ import splitties.init.appCtx
import java.io.File import java.io.File
object Restore : BackupRestore() { object Restore {
suspend fun restore(context: Context, path: String) { suspend fun restore(context: Context, path: String) {
withContext(IO) { withContext(IO) {
@ -131,7 +131,7 @@ object Restore : BackupRestore() {
} catch (e: Exception) { } catch (e: Exception) {
e.printOnDebug() e.printOnDebug()
} }
if (!ignoreReadConfig) { if (!BackupConfig.ignoreReadConfig) {
//恢复阅读界面配置 //恢复阅读界面配置
try { try {
val file = val file =
@ -159,7 +159,7 @@ object Restore : BackupRestore() {
Preferences.getSharedPreferences(appCtx, path, "config")?.all?.let { map -> Preferences.getSharedPreferences(appCtx, path, "config")?.all?.let { map ->
val edit = appCtx.defaultSharedPreferences.edit() val edit = appCtx.defaultSharedPreferences.edit()
map.forEach { (key, value) -> map.forEach { (key, value) ->
if (keyIsNotIgnore(key)) { if (BackupConfig.keyIsNotIgnore(key)) {
when (value) { when (value) {
is Int -> edit.putInt(key, value) is Int -> edit.putInt(key, value)
is Boolean -> edit.putBoolean(key, value) is Boolean -> edit.putBoolean(key, value)

@ -20,10 +20,7 @@ import io.legado.app.constant.PreferKey
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.LocalConfig import io.legado.app.help.LocalConfig
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
import io.legado.app.help.storage.AppWebDav import io.legado.app.help.storage.*
import io.legado.app.help.storage.Backup
import io.legado.app.help.storage.ImportOldData
import io.legado.app.help.storage.Restore
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.permission.Permissions import io.legado.app.lib.permission.Permissions
import io.legado.app.lib.permission.PermissionsCompat import io.legado.app.lib.permission.PermissionsCompat
@ -224,15 +221,15 @@ class BackupConfigFragment : BasePreferenceFragment(),
private fun backupIgnore() { private fun backupIgnore() {
val checkedItems = BooleanArray(Backup.ignoreKeys.size) { val checkedItems = BooleanArray(BackupConfig.ignoreKeys.size) {
Backup.ignoreConfig[Backup.ignoreKeys[it]] ?: false BackupConfig.ignoreConfig[BackupConfig.ignoreKeys[it]] ?: false
} }
alert(R.string.restore_ignore) { alert(R.string.restore_ignore) {
multiChoiceItems(Backup.ignoreTitle, checkedItems) { _, which, isChecked -> multiChoiceItems(BackupConfig.ignoreTitle, checkedItems) { _, which, isChecked ->
Backup.ignoreConfig[Backup.ignoreKeys[which]] = isChecked BackupConfig.ignoreConfig[BackupConfig.ignoreKeys[which]] = isChecked
} }
onDismiss { onDismiss {
Backup.saveIgnoreConfig() BackupConfig.saveIgnoreConfig()
} }
} }
} }

Loading…
Cancel
Save