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.View
import androidx.documentfile.provider.DocumentFile
import androidx.lifecycle.lifecycleScope
import androidx.preference.EditTextPreference
import androidx.preference.ListPreference
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.widget.dialog.TextDialog
import io.legado.app.utils.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.launch
import splitties.init.appCtx
class BackupConfigFragment : BasePreferenceFragment(),
@ -265,17 +267,30 @@ class BackupConfigFragment : BasePreferenceFragment(),
}
fun restore() {
Coroutine.async(context = Dispatchers.Main) {
Coroutine.async(context = Main) {
BookWebDav.showRestoreDialog(requireContext())
}.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)
if (backupPath?.isNotEmpty() == true) {
if (backupPath.isContentScheme()) {
val uri = Uri.parse(backupPath)
val doc = DocumentFile.fromTreeUri(requireContext(), uri)
if (doc?.canWrite() == true) {
lifecycleScope.launch {
Restore.restore(requireContext(), backupPath)
}
} else {
restoreDir.launch(null)
}
@ -286,7 +301,6 @@ class BackupConfigFragment : BasePreferenceFragment(),
restoreDir.launch(null)
}
}
}
private fun restoreUsePermission(path: String) {
PermissionsCompat.Builder(this)

Loading…
Cancel
Save