|
|
@ -5,7 +5,6 @@ import android.content.Intent |
|
|
|
import android.net.Uri |
|
|
|
import android.net.Uri |
|
|
|
import androidx.documentfile.provider.DocumentFile |
|
|
|
import androidx.documentfile.provider.DocumentFile |
|
|
|
import androidx.fragment.app.Fragment |
|
|
|
import androidx.fragment.app.Fragment |
|
|
|
import io.legado.app.App |
|
|
|
|
|
|
|
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.AppConfig |
|
|
|
import io.legado.app.help.AppConfig |
|
|
@ -22,6 +21,7 @@ import io.legado.app.utils.isContentScheme |
|
|
|
import io.legado.app.utils.longToast |
|
|
|
import io.legado.app.utils.longToast |
|
|
|
import io.legado.app.utils.toastOnUi |
|
|
|
import io.legado.app.utils.toastOnUi |
|
|
|
import kotlinx.coroutines.Dispatchers.Main |
|
|
|
import kotlinx.coroutines.Dispatchers.Main |
|
|
|
|
|
|
|
import splitties.init.appCtx |
|
|
|
|
|
|
|
|
|
|
|
object BackupRestoreUi { |
|
|
|
object BackupRestoreUi { |
|
|
|
private const val selectFolderRequestCode = 21 |
|
|
|
private const val selectFolderRequestCode = 21 |
|
|
@ -125,24 +125,24 @@ object BackupRestoreUi { |
|
|
|
backupSelectRequestCode -> if (resultCode == RESULT_OK) { |
|
|
|
backupSelectRequestCode -> if (resultCode == RESULT_OK) { |
|
|
|
data?.data?.let { uri -> |
|
|
|
data?.data?.let { uri -> |
|
|
|
if (uri.isContentScheme()) { |
|
|
|
if (uri.isContentScheme()) { |
|
|
|
App.INSTANCE.contentResolver.takePersistableUriPermission( |
|
|
|
appCtx.contentResolver.takePersistableUriPermission( |
|
|
|
uri, |
|
|
|
uri, |
|
|
|
Intent.FLAG_GRANT_READ_URI_PERMISSION |
|
|
|
Intent.FLAG_GRANT_READ_URI_PERMISSION |
|
|
|
or Intent.FLAG_GRANT_WRITE_URI_PERMISSION |
|
|
|
or Intent.FLAG_GRANT_WRITE_URI_PERMISSION |
|
|
|
) |
|
|
|
) |
|
|
|
AppConfig.backupPath = uri.toString() |
|
|
|
AppConfig.backupPath = uri.toString() |
|
|
|
Coroutine.async { |
|
|
|
Coroutine.async { |
|
|
|
Backup.backup(App.INSTANCE, uri.toString()) |
|
|
|
Backup.backup(appCtx, uri.toString()) |
|
|
|
}.onSuccess { |
|
|
|
}.onSuccess { |
|
|
|
App.INSTANCE.toastOnUi(R.string.backup_success) |
|
|
|
appCtx.toastOnUi(R.string.backup_success) |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
uri.path?.let { path -> |
|
|
|
uri.path?.let { path -> |
|
|
|
AppConfig.backupPath = path |
|
|
|
AppConfig.backupPath = path |
|
|
|
Coroutine.async { |
|
|
|
Coroutine.async { |
|
|
|
Backup.backup(App.INSTANCE, path) |
|
|
|
Backup.backup(appCtx, path) |
|
|
|
}.onSuccess { |
|
|
|
}.onSuccess { |
|
|
|
App.INSTANCE.toastOnUi(R.string.backup_success) |
|
|
|
appCtx.toastOnUi(R.string.backup_success) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -151,20 +151,20 @@ object BackupRestoreUi { |
|
|
|
restoreSelectRequestCode -> if (resultCode == RESULT_OK) { |
|
|
|
restoreSelectRequestCode -> if (resultCode == RESULT_OK) { |
|
|
|
data?.data?.let { uri -> |
|
|
|
data?.data?.let { uri -> |
|
|
|
if (uri.isContentScheme()) { |
|
|
|
if (uri.isContentScheme()) { |
|
|
|
App.INSTANCE.contentResolver.takePersistableUriPermission( |
|
|
|
appCtx.contentResolver.takePersistableUriPermission( |
|
|
|
uri, |
|
|
|
uri, |
|
|
|
Intent.FLAG_GRANT_READ_URI_PERMISSION |
|
|
|
Intent.FLAG_GRANT_READ_URI_PERMISSION |
|
|
|
or Intent.FLAG_GRANT_WRITE_URI_PERMISSION |
|
|
|
or Intent.FLAG_GRANT_WRITE_URI_PERMISSION |
|
|
|
) |
|
|
|
) |
|
|
|
AppConfig.backupPath = uri.toString() |
|
|
|
AppConfig.backupPath = uri.toString() |
|
|
|
Coroutine.async { |
|
|
|
Coroutine.async { |
|
|
|
Restore.restore(App.INSTANCE, uri.toString()) |
|
|
|
Restore.restore(appCtx, uri.toString()) |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
uri.path?.let { path -> |
|
|
|
uri.path?.let { path -> |
|
|
|
AppConfig.backupPath = path |
|
|
|
AppConfig.backupPath = path |
|
|
|
Coroutine.async { |
|
|
|
Coroutine.async { |
|
|
|
Restore.restore(App.INSTANCE, path) |
|
|
|
Restore.restore(appCtx, path) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -173,7 +173,7 @@ object BackupRestoreUi { |
|
|
|
selectFolderRequestCode -> if (resultCode == RESULT_OK) { |
|
|
|
selectFolderRequestCode -> if (resultCode == RESULT_OK) { |
|
|
|
data?.data?.let { uri -> |
|
|
|
data?.data?.let { uri -> |
|
|
|
if (uri.isContentScheme()) { |
|
|
|
if (uri.isContentScheme()) { |
|
|
|
App.INSTANCE.contentResolver.takePersistableUriPermission( |
|
|
|
appCtx.contentResolver.takePersistableUriPermission( |
|
|
|
uri, |
|
|
|
uri, |
|
|
|
Intent.FLAG_GRANT_READ_URI_PERMISSION |
|
|
|
Intent.FLAG_GRANT_READ_URI_PERMISSION |
|
|
|
or Intent.FLAG_GRANT_WRITE_URI_PERMISSION |
|
|
|
or Intent.FLAG_GRANT_WRITE_URI_PERMISSION |
|
|
@ -186,7 +186,7 @@ object BackupRestoreUi { |
|
|
|
} |
|
|
|
} |
|
|
|
oldDataRequestCode -> if (resultCode == RESULT_OK) { |
|
|
|
oldDataRequestCode -> if (resultCode == RESULT_OK) { |
|
|
|
data?.data?.let { uri -> |
|
|
|
data?.data?.let { uri -> |
|
|
|
ImportOldData.importUri(App.INSTANCE, uri) |
|
|
|
ImportOldData.importUri(appCtx, uri) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|