|
|
@ -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,26 +267,38 @@ 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 { |
|
|
|
val backupPath = getPrefString(PreferKey.backupPath) |
|
|
|
setTitle(R.string.restore) |
|
|
|
if (backupPath?.isNotEmpty() == true) { |
|
|
|
setMessage("WebDavError:${it.localizedMessage}\n将从本地备份恢复。") |
|
|
|
if (backupPath.isContentScheme()) { |
|
|
|
okButton { |
|
|
|
val uri = Uri.parse(backupPath) |
|
|
|
restoreFromLocal() |
|
|
|
val doc = DocumentFile.fromTreeUri(requireContext(), uri) |
|
|
|
} |
|
|
|
if (doc?.canWrite() == true) { |
|
|
|
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) |
|
|
|
Restore.restore(requireContext(), backupPath) |
|
|
|
} else { |
|
|
|
|
|
|
|
restoreDir.launch(null) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
restoreUsePermission(backupPath) |
|
|
|
restoreDir.launch(null) |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
restoreDir.launch(null) |
|
|
|
restoreUsePermission(backupPath) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
restoreDir.launch(null) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|