|
|
@ -116,13 +116,7 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), |
|
|
|
override fun onPreferenceTreeClick(preference: Preference?): Boolean { |
|
|
|
override fun onPreferenceTreeClick(preference: Preference?): Boolean { |
|
|
|
when (preference?.key) { |
|
|
|
when (preference?.key) { |
|
|
|
"web_dav_backup" -> backup() |
|
|
|
"web_dav_backup" -> backup() |
|
|
|
"web_dav_restore" -> PermissionsCompat.Builder(this) |
|
|
|
"web_dav_restore" -> restore() |
|
|
|
.addPermissions(*Permissions.Group.STORAGE) |
|
|
|
|
|
|
|
.rationale(R.string.tip_perm_request_storage) |
|
|
|
|
|
|
|
.onGranted { |
|
|
|
|
|
|
|
WebDavHelp.showRestoreDialog(requireContext()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
.request() |
|
|
|
|
|
|
|
"import_old" -> importOldData() |
|
|
|
"import_old" -> importOldData() |
|
|
|
} |
|
|
|
} |
|
|
|
return super.onPreferenceTreeClick(preference) |
|
|
|
return super.onPreferenceTreeClick(preference) |
|
|
@ -157,6 +151,39 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun restore() { |
|
|
|
|
|
|
|
launch { |
|
|
|
|
|
|
|
if (!WebDavHelp.showRestoreDialog(requireContext())) { |
|
|
|
|
|
|
|
val backupPath = getPrefString(PreferKey.backupPath) |
|
|
|
|
|
|
|
if (backupPath?.isEmpty() == true) { |
|
|
|
|
|
|
|
selectRestoreFolder() |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
val uri = Uri.parse(backupPath) |
|
|
|
|
|
|
|
val doc = DocumentFile.fromTreeUri(requireContext(), uri) |
|
|
|
|
|
|
|
if (doc?.canWrite() == true) { |
|
|
|
|
|
|
|
Restore.restore(requireContext(), uri) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
selectBackupFolder() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun selectRestoreFolder() { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) |
|
|
|
|
|
|
|
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) |
|
|
|
|
|
|
|
startActivityForResult(intent, restoreSelectRequestCode) |
|
|
|
|
|
|
|
} catch (e: java.lang.Exception) { |
|
|
|
|
|
|
|
PermissionsCompat.Builder(this) |
|
|
|
|
|
|
|
.addPermissions(*Permissions.Group.STORAGE) |
|
|
|
|
|
|
|
.rationale(R.string.tip_perm_request_storage) |
|
|
|
|
|
|
|
.onGranted { Restore.restore(Backup.legadoPath) } |
|
|
|
|
|
|
|
.request() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun importOldData() { |
|
|
|
private fun importOldData() { |
|
|
|
try { |
|
|
|
try { |
|
|
|
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) |
|
|
|
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) |
|
|
@ -270,6 +297,16 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), |
|
|
|
Backup.backup(requireContext(), uri) |
|
|
|
Backup.backup(requireContext(), uri) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
restoreSelectRequestCode -> if (resultCode == RESULT_OK) { |
|
|
|
|
|
|
|
data?.data?.let { uri -> |
|
|
|
|
|
|
|
requireContext().contentResolver.takePersistableUriPermission( |
|
|
|
|
|
|
|
uri, |
|
|
|
|
|
|
|
Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
putPrefString(PreferKey.backupPath, uri.toString()) |
|
|
|
|
|
|
|
Restore.restore(requireContext(), uri) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |