mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-02 00:17:41 +01:00
Confirm backup location after successful local backup restore.
This commit is contained in:
committed by
Cody Henthorne
parent
542a820e22
commit
94e3dabc20
@@ -85,7 +85,7 @@ class RestoreLocalBackupActivity : BaseActivity() {
|
||||
LaunchedEffect(state.restorePhase) {
|
||||
when (state.restorePhase) {
|
||||
RestorePhase.COMPLETE -> {
|
||||
if (!state.showLocalBackupsDisabledDialog) {
|
||||
if (state.dialog == null) {
|
||||
startActivity(MainActivity.clearTop(this@RestoreLocalBackupActivity))
|
||||
if (finishActivity) {
|
||||
finishAffinity()
|
||||
@@ -108,8 +108,34 @@ class RestoreLocalBackupActivity : BaseActivity() {
|
||||
RestoreLocalBackupScreen(
|
||||
state = state,
|
||||
onContactSupportClick = contactSupportViewModel::showContactSupport,
|
||||
onConfirmBackupLocation = {
|
||||
viewModel.enableLocalBackupsAndDismissDialog()
|
||||
startActivity(MainActivity.clearTop(this@RestoreLocalBackupActivity))
|
||||
if (finishActivity) {
|
||||
finishAffinity()
|
||||
}
|
||||
},
|
||||
onDisableBackups = {
|
||||
viewModel.changeBackupLocation()
|
||||
startActivity(MainActivity.clearTop(this@RestoreLocalBackupActivity))
|
||||
if (finishActivity) {
|
||||
finishAffinity()
|
||||
}
|
||||
},
|
||||
onChangeBackupLocation = {
|
||||
viewModel.changeBackupLocation()
|
||||
startActivities(
|
||||
arrayOf(
|
||||
MainActivity.clearTop(this@RestoreLocalBackupActivity),
|
||||
AppSettingsActivity.backups(this@RestoreLocalBackupActivity)
|
||||
)
|
||||
)
|
||||
if (finishActivity) {
|
||||
finishAffinity()
|
||||
}
|
||||
},
|
||||
onLocalBackupsDisabledDialogConfirm = {
|
||||
viewModel.dismissLocalBackupsDisabledDialog()
|
||||
viewModel.dismissDialog()
|
||||
startActivities(
|
||||
arrayOf(
|
||||
MainActivity.clearTop(this@RestoreLocalBackupActivity),
|
||||
@@ -121,7 +147,7 @@ class RestoreLocalBackupActivity : BaseActivity() {
|
||||
}
|
||||
},
|
||||
onLocalBackupsDisabledDialogDeny = {
|
||||
viewModel.dismissLocalBackupsDisabledDialog()
|
||||
viewModel.dismissDialog()
|
||||
startActivity(MainActivity.clearTop(this@RestoreLocalBackupActivity))
|
||||
if (finishActivity) {
|
||||
finishAffinity()
|
||||
@@ -148,6 +174,9 @@ class RestoreLocalBackupActivity : BaseActivity() {
|
||||
private fun RestoreLocalBackupScreen(
|
||||
state: RestoreLocalBackupScreenState,
|
||||
onFailureDialogConfirm: () -> Unit,
|
||||
onConfirmBackupLocation: () -> Unit,
|
||||
onChangeBackupLocation: () -> Unit,
|
||||
onDisableBackups: () -> Unit,
|
||||
onLocalBackupsDisabledDialogConfirm: () -> Unit,
|
||||
onLocalBackupsDisabledDialogDeny: () -> Unit,
|
||||
onContactSupportClick: () -> Unit,
|
||||
@@ -266,15 +295,30 @@ private fun RestoreLocalBackupScreen(
|
||||
}
|
||||
}
|
||||
|
||||
if (state.showLocalBackupsDisabledDialog) {
|
||||
Dialogs.SimpleAlertDialog(
|
||||
title = stringResource(R.string.RestoreLocalBackupActivity__turn_on_on_device_backups),
|
||||
body = stringResource(R.string.RestoreLocalBackupActivity__to_continue_using_on_device_backups),
|
||||
confirm = stringResource(R.string.RestoreLocalBackupActivity__turn_on_now),
|
||||
dismiss = stringResource(R.string.RestoreLocalBackupActivity__not_now),
|
||||
onConfirm = onLocalBackupsDisabledDialogConfirm,
|
||||
onDeny = onLocalBackupsDisabledDialogDeny
|
||||
)
|
||||
when (state.dialog) {
|
||||
RestoreLocalBackupActivityDialog.CONFIRM_BACKUP_LOCATION -> {
|
||||
Dialogs.AdvancedAlertDialog(
|
||||
title = stringResource(R.string.RestoreLocalBackupActivity__restore_complete),
|
||||
body = stringResource(R.string.RestoreLocalBackupActivity__choose_a_folder_for_backups),
|
||||
positive = stringResource(R.string.RestoreLocalBackupActivity__use_current_folder),
|
||||
neutral = stringResource(R.string.RestoreLocalBackupActivity__choose_new_folder),
|
||||
negative = stringResource(R.string.RestoreLocalBackupActivity__disable_backups),
|
||||
onPositive = onConfirmBackupLocation,
|
||||
onNeutral = onChangeBackupLocation,
|
||||
onNegative = onDisableBackups
|
||||
)
|
||||
}
|
||||
RestoreLocalBackupActivityDialog.LOCAL_BACKUPS_DISABLED -> {
|
||||
Dialogs.SimpleAlertDialog(
|
||||
title = stringResource(R.string.RestoreLocalBackupActivity__turn_on_on_device_backups),
|
||||
body = stringResource(R.string.RestoreLocalBackupActivity__to_continue_using_on_device_backups),
|
||||
confirm = stringResource(R.string.RestoreLocalBackupActivity__turn_on_now),
|
||||
dismiss = stringResource(R.string.RestoreLocalBackupActivity__not_now),
|
||||
onConfirm = onLocalBackupsDisabledDialogConfirm,
|
||||
onDeny = onLocalBackupsDisabledDialogDeny
|
||||
)
|
||||
}
|
||||
null -> Unit
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -286,6 +330,9 @@ private fun RestoreLocalBackupScreenPreview() {
|
||||
RestoreLocalBackupScreen(
|
||||
state = RestoreLocalBackupScreenState(),
|
||||
onFailureDialogConfirm = {},
|
||||
onConfirmBackupLocation = {},
|
||||
onChangeBackupLocation = {},
|
||||
onDisableBackups = {},
|
||||
onLocalBackupsDisabledDialogConfirm = {},
|
||||
onLocalBackupsDisabledDialogDeny = {},
|
||||
onContactSupportClick = {},
|
||||
|
||||
@@ -140,7 +140,6 @@ class RestoreLocalBackupActivityViewModel : ViewModel() {
|
||||
val backupIdMatchesCurrentAccount = actualBackupId?.value?.contentEquals(expectedBackupId.value) == true
|
||||
if (backupIdMatchesCurrentAccount) {
|
||||
SignalStore.account.restoreAccountEntropyPool(localAepPool)
|
||||
SignalStore.backup.newLocalBackupsEnabled = true
|
||||
} else {
|
||||
Log.w(TAG, "Local backup does not match current account, not re-enabling local backups")
|
||||
}
|
||||
@@ -151,7 +150,9 @@ class RestoreLocalBackupActivityViewModel : ViewModel() {
|
||||
internalState.update {
|
||||
it.copy(
|
||||
restorePhase = RestorePhase.COMPLETE,
|
||||
showLocalBackupsDisabledDialog = !backupIdMatchesCurrentAccount
|
||||
backupDirectory = if (backupIdMatchesCurrentAccount) backupDirectory else null,
|
||||
dialog = if (backupIdMatchesCurrentAccount) RestoreLocalBackupActivityDialog.CONFIRM_BACKUP_LOCATION
|
||||
else RestoreLocalBackupActivityDialog.LOCAL_BACKUPS_DISABLED
|
||||
)
|
||||
}
|
||||
} else {
|
||||
@@ -161,8 +162,18 @@ class RestoreLocalBackupActivityViewModel : ViewModel() {
|
||||
}
|
||||
}
|
||||
|
||||
fun dismissLocalBackupsDisabledDialog() {
|
||||
internalState.update { it.copy(showLocalBackupsDisabledDialog = false) }
|
||||
fun enableLocalBackupsAndDismissDialog() {
|
||||
SignalStore.backup.newLocalBackupsEnabled = true
|
||||
internalState.update { it.copy(dialog = null) }
|
||||
}
|
||||
|
||||
fun changeBackupLocation() {
|
||||
SignalStore.backup.newLocalBackupsDirectory = null
|
||||
internalState.update { it.copy(dialog = null) }
|
||||
}
|
||||
|
||||
fun dismissDialog() {
|
||||
internalState.update { it.copy(dialog = null) }
|
||||
}
|
||||
|
||||
fun resetRestoreState() {
|
||||
@@ -175,7 +186,8 @@ data class RestoreLocalBackupScreenState(
|
||||
val bytesRead: ByteSize = 0L.bytes,
|
||||
val totalBytes: ByteSize = 0L.bytes,
|
||||
val progress: Float = 0f,
|
||||
val showLocalBackupsDisabledDialog: Boolean = false
|
||||
val dialog: RestoreLocalBackupActivityDialog? = null,
|
||||
val backupDirectory: String? = null
|
||||
)
|
||||
|
||||
enum class RestorePhase {
|
||||
@@ -184,3 +196,8 @@ enum class RestorePhase {
|
||||
COMPLETE,
|
||||
FAILED
|
||||
}
|
||||
|
||||
enum class RestoreLocalBackupActivityDialog {
|
||||
LOCAL_BACKUPS_DISABLED,
|
||||
CONFIRM_BACKUP_LOCATION
|
||||
}
|
||||
|
||||
@@ -9264,6 +9264,18 @@
|
||||
<!-- RestoreLocalBackupActivity: Dismiss button label for the dialog prompting the user to re-enable on-device backups -->
|
||||
<string name="RestoreLocalBackupActivity__not_now">Not now</string>
|
||||
|
||||
<!-- RestoreLocalBackupActivity: Body text for the dialog shown after a successful restore, prompting the user to choose a backup folder -->
|
||||
<string name="RestoreLocalBackupActivity__choose_a_folder_for_backups">To continue using on-device backups, choose a folder on your device where new backups will be saved.</string>
|
||||
|
||||
<!-- RestoreLocalBackupActivity: Positive button label for the dialog shown after a successful restore; keeps the current backup folder -->
|
||||
<string name="RestoreLocalBackupActivity__use_current_folder">Use current folder</string>
|
||||
|
||||
<!-- RestoreLocalBackupActivity: Neutral button label for the dialog shown after a successful restore; opens folder picker to select a different backup location -->
|
||||
<string name="RestoreLocalBackupActivity__choose_new_folder">Choose new folder</string>
|
||||
|
||||
<!-- RestoreLocalBackupActivity: Negative button label for the dialog shown after a successful restore; disables on-device backups -->
|
||||
<string name="RestoreLocalBackupActivity__disable_backups">Disable backups</string>
|
||||
|
||||
<!-- SelectInstructionsSheet: Title for the select backup folder instruction sheet -->
|
||||
<string name="SelectInstructionsSheet__select_your_backup_folder">Select your backup folder</string>
|
||||
<!-- SelectInstructionsSheet: Instruction to tap the select this folder button -->
|
||||
|
||||
Reference in New Issue
Block a user