pull/1251/head
gedoor 3 years ago
parent 39cced7cb0
commit 4a04d9ebb5
  1. 22
      app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt

@ -9,6 +9,7 @@ import android.view.MenuInflater
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import androidx.documentfile.provider.DocumentFile import androidx.documentfile.provider.DocumentFile
import androidx.lifecycle.lifecycleScope
import androidx.preference.EditTextPreference import androidx.preference.EditTextPreference
import androidx.preference.ListPreference import androidx.preference.ListPreference
import androidx.preference.Preference import androidx.preference.Preference
@ -30,7 +31,8 @@ import io.legado.app.lib.theme.accentColor
import io.legado.app.ui.document.FilePicker import io.legado.app.ui.document.FilePicker
import io.legado.app.ui.widget.dialog.TextDialog import io.legado.app.ui.widget.dialog.TextDialog
import io.legado.app.utils.* import io.legado.app.utils.*
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.launch
import splitties.init.appCtx import splitties.init.appCtx
class BackupConfigFragment : BasePreferenceFragment(), class BackupConfigFragment : BasePreferenceFragment(),
@ -265,17 +267,30 @@ class BackupConfigFragment : BasePreferenceFragment(),
} }
fun restore() { fun restore() {
Coroutine.async(context = Dispatchers.Main) { Coroutine.async(context = Main) {
BookWebDav.showRestoreDialog(requireContext()) BookWebDav.showRestoreDialog(requireContext())
}.onError { }.onError {
longToast("WebDavError:${it.localizedMessage}\n将从本地备份恢复。") alert {
setTitle(R.string.restore)
setMessage("WebDavError:${it.localizedMessage}\n将从本地备份恢复。")
okButton {
restoreFromLocal()
}
cancelButton()
}
}
}
private fun restoreFromLocal() {
val backupPath = getPrefString(PreferKey.backupPath) val backupPath = getPrefString(PreferKey.backupPath)
if (backupPath?.isNotEmpty() == true) { if (backupPath?.isNotEmpty() == true) {
if (backupPath.isContentScheme()) { if (backupPath.isContentScheme()) {
val uri = Uri.parse(backupPath) val uri = Uri.parse(backupPath)
val doc = DocumentFile.fromTreeUri(requireContext(), uri) val doc = DocumentFile.fromTreeUri(requireContext(), uri)
if (doc?.canWrite() == true) { if (doc?.canWrite() == true) {
lifecycleScope.launch {
Restore.restore(requireContext(), backupPath) Restore.restore(requireContext(), backupPath)
}
} else { } else {
restoreDir.launch(null) restoreDir.launch(null)
} }
@ -286,7 +301,6 @@ class BackupConfigFragment : BasePreferenceFragment(),
restoreDir.launch(null) restoreDir.launch(null)
} }
} }
}
private fun restoreUsePermission(path: String) { private fun restoreUsePermission(path: String) {
PermissionsCompat.Builder(this) PermissionsCompat.Builder(this)

Loading…
Cancel
Save