pull/279/head
gedoor 4 years ago
parent dfda51f869
commit 513e553721
  1. 1
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  2. 15
      app/src/main/java/io/legado/app/help/storage/Restore.kt
  3. 11
      app/src/main/java/io/legado/app/lib/dialogs/AlertBuilder.kt
  4. 15
      app/src/main/java/io/legado/app/lib/dialogs/AndroidAlertBuilder.kt
  5. 16
      app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt

@ -25,6 +25,7 @@ object PreferKey {
const val readBookFont = "readBookFont" const val readBookFont = "readBookFont"
const val fontFolder = "fontFolder" const val fontFolder = "fontFolder"
const val backupPath = "backupUri" const val backupPath = "backupUri"
const val restoreIgnore = "restoreIgnore"
const val threadCount = "threadCount" const val threadCount = "threadCount"
const val webPort = "webPort" const val webPort = "webPort"
const val keepLight = "keep_light" const val keepLight = "keep_light"

@ -24,6 +24,16 @@ import org.jetbrains.anko.defaultSharedPreferences
import java.io.File import java.io.File
object Restore { object Restore {
private val ignoreConfigPath =
App.INSTANCE.filesDir.absolutePath + File.separator + "restoreIgnore.json"
val ignoreConfig: HashMap<String, Boolean> by lazy {
val file = FileUtils.createFileIfNotExist(ignoreConfigPath)
val json = file.readText()
GSON.fromJsonObject<HashMap<String, Boolean>>(json) ?: hashMapOf()
}
val ignoreKeys = arrayOf("readConfig")
val ignoreTitle = arrayOf("阅读界面设置")
val jsonPath: ParseContext by lazy { val jsonPath: ParseContext by lazy {
JsonPath.using( JsonPath.using(
Configuration.builder() Configuration.builder()
@ -143,6 +153,11 @@ object Restore {
} }
} }
fun saveIgnoreConfig() {
val json = GSON.toJson(ignoreConfig)
FileUtils.createFileIfNotExist(ignoreConfigPath).writeText(json)
}
private inline fun <reified T> fileToListT(path: String, fileName: String): List<T>? { private inline fun <reified T> fileToListT(path: String, fileName: String): List<T>? {
try { try {
val file = FileUtils.createFileIfNotExist(path + File.separator + fileName) val file = FileUtils.createFileIfNotExist(path + File.separator + fileName)

@ -75,7 +75,16 @@ interface AlertBuilder<out D : DialogInterface> {
fun onKeyPressed(handler: (dialog: DialogInterface, keyCode: Int, e: KeyEvent) -> Boolean) fun onKeyPressed(handler: (dialog: DialogInterface, keyCode: Int, e: KeyEvent) -> Boolean)
fun items(items: List<CharSequence>, onItemSelected: (dialog: DialogInterface, index: Int) -> Unit) fun items(items: List<CharSequence>, onItemSelected: (dialog: DialogInterface, index: Int) -> Unit)
fun <T> items(items: List<T>, onItemSelected: (dialog: DialogInterface, item: T, index: Int) -> Unit) fun <T> items(
items: List<T>,
onItemSelected: (dialog: DialogInterface, item: T, index: Int) -> Unit
)
fun multiChoiceItems(
items: Array<String>,
checkedItems: BooleanArray,
onClick: (dialog: DialogInterface, which: Int, isChecked: Boolean) -> Unit
)
fun build(): D fun build(): D
fun show(): D fun show(): D

@ -105,12 +105,25 @@ internal class AndroidAlertBuilder(override val ctx: Context) : AlertBuilder<Ale
} }
} }
override fun <T> items(items: List<T>, onItemSelected: (dialog: DialogInterface, item: T, index: Int) -> Unit) { override fun <T> items(
items: List<T>,
onItemSelected: (dialog: DialogInterface, item: T, index: Int) -> Unit
) {
builder.setItems(Array(items.size) { i -> items[i].toString() }) { dialog, which -> builder.setItems(Array(items.size) { i -> items[i].toString() }) { dialog, which ->
onItemSelected(dialog, items[which], which) onItemSelected(dialog, items[which], which)
} }
} }
override fun multiChoiceItems(
items: Array<String>,
checkedItems: BooleanArray,
onClick: (dialog: DialogInterface, which: Int, isChecked: Boolean) -> Unit
) {
builder.setMultiChoiceItems(items, checkedItems) { dialog, which, isChecked ->
onClick(dialog, which, isChecked)
}
}
override fun build(): AlertDialog = builder.create() override fun build(): AlertDialog = builder.create()
override fun show(): AlertDialog = builder.show() override fun show(): AlertDialog = builder.show()

@ -11,6 +11,8 @@ import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import io.legado.app.R import io.legado.app.R
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.help.storage.Restore
import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.accentColor
import io.legado.app.ui.filechooser.FileChooserDialog import io.legado.app.ui.filechooser.FileChooserDialog
@ -104,6 +106,7 @@ class BackupConfigFragment : PreferenceFragmentCompat(),
override fun onPreferenceTreeClick(preference: Preference?): Boolean { override fun onPreferenceTreeClick(preference: Preference?): Boolean {
when (preference?.key) { when (preference?.key) {
PreferKey.backupPath -> BackupRestoreUi.selectBackupFolder(this) PreferKey.backupPath -> BackupRestoreUi.selectBackupFolder(this)
PreferKey.restoreIgnore -> restoreIgnore()
"web_dav_backup" -> BackupRestoreUi.backup(this) "web_dav_backup" -> BackupRestoreUi.backup(this)
"web_dav_restore" -> BackupRestoreUi.restore(this) "web_dav_restore" -> BackupRestoreUi.restore(this)
"import_old" -> BackupRestoreUi.importOldData(this) "import_old" -> BackupRestoreUi.importOldData(this)
@ -111,6 +114,19 @@ class BackupConfigFragment : PreferenceFragmentCompat(),
return super.onPreferenceTreeClick(preference) return super.onPreferenceTreeClick(preference)
} }
private fun restoreIgnore() {
val checkedItems = BooleanArray(Restore.ignoreKeys.size) {
Restore.ignoreConfig[Restore.ignoreKeys[it]] ?: false
}
alert(R.string.restore_ignore) {
multiChoiceItems(Restore.ignoreTitle, checkedItems) { _, which, isChecked ->
Restore.ignoreConfig[Restore.ignoreKeys[which]] = isChecked
}
}.show().setOnDismissListener {
Restore.saveIgnoreConfig()
}
}
override fun onFilePicked(requestCode: Int, currentPath: String) { override fun onFilePicked(requestCode: Int, currentPath: String) {
BackupRestoreUi.onFilePicked(requestCode, currentPath) BackupRestoreUi.onFilePicked(requestCode, currentPath)
} }

Loading…
Cancel
Save