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
object Backup : BackupRestore() {
object Backup {
val backupPath: String by lazy {
appCtx.filesDir.getFile("backup").absolutePath
@ -94,7 +94,7 @@ object Backup : BackupRestore() {
Preferences.getSharedPreferences(appCtx, backupPath, "config")?.let { sp ->
val edit = sp.edit()
appCtx.defaultSharedPreferences.all.forEach { (key, value) ->
if (keyIsNotIgnore(key)) {
if (BackupConfig.keyIsNotIgnore(key)) {
when (value) {
is Int -> edit.putInt(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 splitties.init.appCtx
abstract class BackupRestore {
object BackupConfig {
private val ignoreConfigPath = FileUtils.getPath(appCtx.filesDir, "restoreIgnore.json")
val ignoreConfig: HashMap<String, Boolean> by lazy {
@ -16,7 +16,7 @@ abstract class BackupRestore {
GSON.fromJsonObject<HashMap<String, Boolean>>(json).getOrNull() ?: hashMapOf()
}
//忽略key
//配置忽略key
val ignoreKeys = arrayOf(
"readConfig",
PreferKey.themeMode,
@ -25,7 +25,7 @@ abstract class BackupRestore {
PreferKey.threadCount
)
//忽略标题
//配置忽略标题
val ignoreTitle = arrayOf(
appCtx.getString(R.string.read_config),
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 {
ignorePrefKeys.contains(key) -> false
readPrefKeys.contains(key) && ignoreReadConfig -> false
@ -64,7 +64,7 @@ abstract class BackupRestore {
}
}
protected val ignoreReadConfig: Boolean
val ignoreReadConfig: Boolean
get() = ignoreConfig["readConfig"] == true
private val ignoreThemeMode: Boolean
get() = ignoreConfig[PreferKey.themeMode] == true

@ -24,7 +24,7 @@ import splitties.init.appCtx
import java.io.File
object Restore : BackupRestore() {
object Restore {
suspend fun restore(context: Context, path: String) {
withContext(IO) {
@ -131,7 +131,7 @@ object Restore : BackupRestore() {
} catch (e: Exception) {
e.printOnDebug()
}
if (!ignoreReadConfig) {
if (!BackupConfig.ignoreReadConfig) {
//恢复阅读界面配置
try {
val file =
@ -159,7 +159,7 @@ object Restore : BackupRestore() {
Preferences.getSharedPreferences(appCtx, path, "config")?.all?.let { map ->
val edit = appCtx.defaultSharedPreferences.edit()
map.forEach { (key, value) ->
if (keyIsNotIgnore(key)) {
if (BackupConfig.keyIsNotIgnore(key)) {
when (value) {
is Int -> edit.putInt(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.LocalConfig
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.help.storage.AppWebDav
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.help.storage.*
import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.permission.Permissions
import io.legado.app.lib.permission.PermissionsCompat
@ -224,15 +221,15 @@ class BackupConfigFragment : BasePreferenceFragment(),
private fun backupIgnore() {
val checkedItems = BooleanArray(Backup.ignoreKeys.size) {
Backup.ignoreConfig[Backup.ignoreKeys[it]] ?: false
val checkedItems = BooleanArray(BackupConfig.ignoreKeys.size) {
BackupConfig.ignoreConfig[BackupConfig.ignoreKeys[it]] ?: false
}
alert(R.string.restore_ignore) {
multiChoiceItems(Backup.ignoreTitle, checkedItems) { _, which, isChecked ->
Backup.ignoreConfig[Backup.ignoreKeys[which]] = isChecked
multiChoiceItems(BackupConfig.ignoreTitle, checkedItems) { _, which, isChecked ->
BackupConfig.ignoreConfig[BackupConfig.ignoreKeys[which]] = isChecked
}
onDismiss {
Backup.saveIgnoreConfig()
BackupConfig.saveIgnoreConfig()
}
}
}

Loading…
Cancel
Save