Skip to content

Commit

Permalink
[BWA-18] Add Backup option to settings (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
SaintPatrck authored May 22, 2024
1 parent 1161c3c commit e9fb28d
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ fun SettingsScreen(
SettingsEvent.NavigateToTutorial -> onNavigateToTutorial()
SettingsEvent.NavigateToExport -> onNavigateToExport()
SettingsEvent.NavigateToImport -> onNavigateToImport()
SettingsEvent.NavigateToBackup -> {
intentManager.launchUri(
uri = "https://support.google.com/android/answer/2819582".toUri(),
)
}

SettingsEvent.NavigateToHelpCenter -> {
intentManager.launchUri("https://bitwarden.com/help".toUri())
}
Expand Down Expand Up @@ -133,14 +139,19 @@ fun SettingsScreen(
VaultSettings(
onExportClick = remember(viewModel) {
{
viewModel.trySendAction(SettingsAction.VaultClick.ExportClick)
viewModel.trySendAction(SettingsAction.DataClick.ExportClick)
}
},
onImportClick = remember(viewModel) {
{
viewModel.trySendAction(SettingsAction.VaultClick.ImportClick)
viewModel.trySendAction(SettingsAction.DataClick.ImportClick)
}
},
onBackupClick = remember(viewModel) {
{
viewModel.trySendAction(SettingsAction.DataClick.BackupClick)
}
}
)
Spacer(modifier = Modifier.height(16.dp))
AppearanceSettings(
Expand Down Expand Up @@ -230,17 +241,18 @@ fun SecuritySettings(

//endregion

//region Vault settings
//region Data settings

@Composable
fun VaultSettings(
modifier: Modifier = Modifier,
onExportClick: () -> Unit,
onImportClick: () -> Unit,
onBackupClick: () -> Unit,
) {
BitwardenListHeaderText(
modifier = Modifier.padding(horizontal = 16.dp),
label = stringResource(id = R.string.vault)
label = stringResource(id = R.string.data)
)
Spacer(modifier = Modifier.height(8.dp))
BitwardenTextRow(
Expand Down Expand Up @@ -276,6 +288,15 @@ fun VaultSettings(
)
}
)
Spacer(modifier = Modifier.height(8.dp))
BitwardenExternalLinkRow(
text = stringResource(R.string.backup),
onConfirmClick = onBackupClick,
dialogTitle = stringResource(R.string.data_backup_title),
dialogMessage = stringResource(R.string.data_backup_message),
dialogConfirmButtonText = stringResource(R.string.learn_more),
dialogDismissButtonText = stringResource(R.string.ok),
)
}

@Composable
Expand Down Expand Up @@ -313,7 +334,7 @@ private fun UnlockWithBiometricsRow(
)
}

//endregion Vault settings
//endregion Data settings

//region Appearance settings

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class SettingsViewModel @Inject constructor(
handleSecurityClick(action)
}

is SettingsAction.VaultClick -> {
is SettingsAction.DataClick -> {
handleVaultClick(action)
}

Expand Down Expand Up @@ -125,10 +125,11 @@ class SettingsViewModel @Inject constructor(
}
}

private fun handleVaultClick(action: SettingsAction.VaultClick) {
private fun handleVaultClick(action: SettingsAction.DataClick) {
when (action) {
SettingsAction.VaultClick.ExportClick -> handleExportClick()
SettingsAction.VaultClick.ImportClick -> handleImportClick()
SettingsAction.DataClick.ExportClick -> handleExportClick()
SettingsAction.DataClick.ImportClick -> handleImportClick()
SettingsAction.DataClick.BackupClick -> handleBackupClick()
}
}

Expand All @@ -140,6 +141,10 @@ class SettingsViewModel @Inject constructor(
sendEvent(SettingsEvent.NavigateToImport)
}

private fun handleBackupClick() {
sendEvent(SettingsEvent.NavigateToBackup)
}

private fun handleAppearanceChange(action: SettingsAction.AppearanceChange) {
when (action) {
is SettingsAction.AppearanceChange.LanguageChange -> {
Expand Down Expand Up @@ -298,6 +303,11 @@ sealed class SettingsEvent {
*/
data object NavigateToImport : SettingsEvent()

/**
* Navigate to the Backup web page.
*/
data object NavigateToBackup : SettingsEvent()

/**
* Navigate to the Help Center web page.
*/
Expand All @@ -322,7 +332,7 @@ sealed class SettingsAction(
sealed class Dialog {

/**
*
* Display the loading screen with a [message].
*/
data class Loading(
val message: Text,
Expand All @@ -339,17 +349,22 @@ sealed class SettingsAction(
/**
* Models actions for the Vault section of settings.
*/
sealed class VaultClick : SettingsAction() {
sealed class DataClick : SettingsAction() {

/**
* Indicates the user clicked export.
*/
data object ExportClick : VaultClick()
data object ExportClick : DataClick()

/**
* Indicates the user clicked import.
*/
data object ImportClick : VaultClick()
data object ImportClick : DataClick()

/**
* Indicates the user click backup.
*/
data object BackupClick : DataClick()
}

/**
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
<string name="item_deleted">Item deleted</string>
<string name="delete">Delete</string>
<string name="do_you_really_want_to_permanently_delete_cipher">Do you really want to permanently delete? This cannot be undone.</string>
<string name="vault">Vault</string>
<string name="data">Data</string>
<string name="export">Export</string>
<string name="loading">Loading</string>
<string name="export_confirmation_title">Confirm export</string>
Expand Down Expand Up @@ -115,4 +115,8 @@
<string name="favorite_tooltip">Save as a favorite</string>
<string name="favorite">Favorite</string>
<string name="favorites">Favorites</string>
<string name="backup">Backup</string>
<string name="data_backup_title">Data backup</string>
<string name="data_backup_message">Bitwarden Authenticator data is backed up and can be restored with your regularly scheduled device backups.</string>
<string name="learn_more">Learn more</string>
</resources>

0 comments on commit e9fb28d

Please sign in to comment.