mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
refactor(settings/data): Simplify backup code
* Remove picker argument, it's permanently false now * Simplify backup file path retrieval * Remove unused code
This commit is contained in:
parent
5d457a7ae5
commit
58c5a17c50
1 changed files with 12 additions and 37 deletions
|
@ -251,10 +251,6 @@ class SettingsDataLegacyController : SettingsLegacyController() {
|
||||||
storagePreferences.baseStorageDirectory().set(file.uri.toString())
|
storagePreferences.baseStorageDirectory().set(file.uri.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
CODE_BACKUP_CREATE -> {
|
|
||||||
doBackup(backupFlags, uri, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
CODE_BACKUP_RESTORE -> {
|
CODE_BACKUP_RESTORE -> {
|
||||||
(activity as? MainActivity)?.showNotificationPermissionPrompt(true)
|
(activity as? MainActivity)?.showNotificationPermissionPrompt(true)
|
||||||
showBackupRestoreDialog(uri)
|
showBackupRestoreDialog(uri)
|
||||||
|
@ -263,48 +259,28 @@ class SettingsDataLegacyController : SettingsLegacyController() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun doBackup(options: BackupOptions, uri: Uri, requirePersist: Boolean = false) {
|
private fun createBackup(options: BackupOptions) {
|
||||||
val activity = activity ?: return
|
val activity = activity ?: return
|
||||||
|
|
||||||
val actualUri =
|
|
||||||
if (requirePersist) {
|
|
||||||
val intentFlags = Intent.FLAG_GRANT_READ_URI_PERMISSION or
|
|
||||||
Intent.FLAG_GRANT_WRITE_URI_PERMISSION
|
|
||||||
|
|
||||||
activity.tryTakePersistableUriPermission(uri, intentFlags)
|
|
||||||
uri
|
|
||||||
} else {
|
|
||||||
UniFile.fromUri(activity, uri)?.createFile(Backup.getBackupFilename())?.uri
|
|
||||||
} ?: return
|
|
||||||
activity.toast(MR.strings.creating_backup)
|
|
||||||
BackupCreatorJob.startNow(activity, actualUri, options)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun createBackup(options: BackupOptions, picker: Boolean = false) {
|
|
||||||
backupFlags = options
|
backupFlags = options
|
||||||
|
|
||||||
val dir = storageManager.getBackupsDirectory()
|
val uri = storageManager.getBackupsDirectory()?.createFile(Backup.getBackupFilename())?.uri
|
||||||
if (dir == null) {
|
if (uri == null) {
|
||||||
activity?.toast(MR.strings.invalid_location_generic)
|
activity?.toast(MR.strings.invalid_location_generic)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!picker) {
|
/* Might not need it
|
||||||
doBackup(backupFlags, dir.uri)
|
if (requirePersist) {
|
||||||
return
|
val intentFlags = Intent.FLAG_GRANT_READ_URI_PERMISSION or
|
||||||
}
|
Intent.FLAG_GRANT_WRITE_URI_PERMISSION
|
||||||
|
|
||||||
try {
|
activity.tryTakePersistableUriPermission(uri, intentFlags)
|
||||||
// Use Android's built-in file creator
|
|
||||||
val intent = Intent(Intent.ACTION_CREATE_DOCUMENT)
|
|
||||||
.addCategory(Intent.CATEGORY_OPENABLE)
|
|
||||||
.setType("application/*")
|
|
||||||
.putExtra(Intent.EXTRA_TITLE, Backup.getBackupFilename())
|
|
||||||
|
|
||||||
startActivityForResult(intent, CODE_BACKUP_CREATE)
|
|
||||||
} catch (e: ActivityNotFoundException) {
|
|
||||||
activity?.toast(MR.strings.file_picker_error)
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
activity.toast(MR.strings.creating_backup)
|
||||||
|
BackupCreatorJob.startNow(activity, uri, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showBackupCreateDialog() {
|
private fun showBackupCreateDialog() {
|
||||||
|
@ -406,7 +382,6 @@ class SettingsDataLegacyController : SettingsLegacyController() {
|
||||||
private const val CLEAR_CACHE_KEY = "pref_clear_cache_key"
|
private const val CLEAR_CACHE_KEY = "pref_clear_cache_key"
|
||||||
|
|
||||||
private const val CODE_DATA_DIR = 104
|
private const val CODE_DATA_DIR = 104
|
||||||
private const val CODE_BACKUP_CREATE = 504
|
|
||||||
private const val CODE_BACKUP_RESTORE = 505
|
private const val CODE_BACKUP_RESTORE = 505
|
||||||
|
|
||||||
private const val HELP_URL = "https://tachiyomi.org/docs/guides/backups"
|
private const val HELP_URL = "https://tachiyomi.org/docs/guides/backups"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue