generated from bitwarden/template
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BITAU-89 Show save location dialog on the QR scan screen (#258)
- Loading branch information
1 parent
bb6255b
commit 5de6dc3
Showing
10 changed files
with
786 additions
and
8 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
...uthenticator/data/authenticator/repository/util/SharedVerificationCodesStateExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.bitwarden.authenticator.data.authenticator.repository.util | ||
|
||
import com.bitwarden.authenticator.data.authenticator.repository.model.SharedVerificationCodesState | ||
|
||
/** | ||
* Whether or not the user has enabled sync with Bitwarden and the two apps are successfully | ||
* syncing. This is useful to know when to show certain sync UI and also when to support | ||
* moving codes to Bitwarden. | ||
*/ | ||
val SharedVerificationCodesState.isSyncWithBitwardenEnabled: Boolean | ||
get() = when (this) { | ||
SharedVerificationCodesState.AppNotInstalled, | ||
SharedVerificationCodesState.Error, | ||
SharedVerificationCodesState.FeatureNotEnabled, | ||
SharedVerificationCodesState.Loading, | ||
SharedVerificationCodesState.OsVersionNotSupported, | ||
SharedVerificationCodesState.SyncNotEnabled, | ||
-> false | ||
|
||
is SharedVerificationCodesState.Success -> true | ||
} |
119 changes: 119 additions & 0 deletions
119
...m/bitwarden/authenticator/ui/authenticator/feature/qrcodescan/ChooseSaveLocationDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package com.bitwarden.authenticator.ui.authenticator.feature.qrcodescan | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.ExperimentalLayoutApi | ||
import androidx.compose.foundation.layout.FlowRow | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.requiredHeightIn | ||
import androidx.compose.foundation.layout.requiredWidthIn | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.platform.LocalConfiguration | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.window.Dialog | ||
import androidx.compose.ui.window.DialogProperties | ||
import com.bitwarden.authenticator.R | ||
import com.bitwarden.authenticator.ui.platform.components.button.BitwardenTextButton | ||
import com.bitwarden.authenticator.ui.platform.components.toggle.BitwardenWideSwitch | ||
import com.bitwarden.authenticator.ui.platform.components.util.maxDialogHeight | ||
import com.bitwarden.authenticator.ui.platform.components.util.maxDialogWidth | ||
|
||
/** | ||
* Displays a dialog asking the user where they would like to save a new QR code. | ||
* | ||
* @param onSaveHereClick Invoked when the user clicks "Save here". The boolean parameter is true if | ||
* the user check "Save option as default". | ||
* @param onTakeMeToBitwardenClick Invoked when the user clicks "Take me to Bitwarden". The boolean | ||
* parameter is true if the user checked "Save option as default". | ||
*/ | ||
@Composable | ||
@OptIn(ExperimentalLayoutApi::class) | ||
@Suppress("LongMethod") | ||
fun ChooseSaveLocationDialog( | ||
onSaveHereClick: (Boolean) -> Unit, | ||
onTakeMeToBitwardenClick: (Boolean) -> Unit, | ||
) { | ||
Dialog( | ||
onDismissRequest = { }, // Not dismissible | ||
properties = DialogProperties(usePlatformDefaultWidth = false), | ||
) { | ||
var isSaveAsDefaultChecked by remember { mutableStateOf(false) } | ||
val configuration = LocalConfiguration.current | ||
Column( | ||
modifier = Modifier | ||
.requiredHeightIn( | ||
max = configuration.maxDialogHeight, | ||
) | ||
.requiredWidthIn( | ||
max = configuration.maxDialogWidth, | ||
) | ||
.background( | ||
color = MaterialTheme.colorScheme.surfaceContainerHigh, | ||
shape = RoundedCornerShape(28.dp), | ||
), | ||
horizontalAlignment = Alignment.End, | ||
) { | ||
Spacer(modifier = Modifier.height(24.dp)) | ||
Text( | ||
modifier = Modifier | ||
.padding(horizontal = 24.dp) | ||
.fillMaxWidth(), | ||
text = stringResource(R.string.verification_code_created), | ||
color = MaterialTheme.colorScheme.onSurface, | ||
style = MaterialTheme.typography.headlineSmall, | ||
) | ||
Spacer(modifier = Modifier.height(16.dp)) | ||
Text( | ||
modifier = Modifier | ||
.weight(1f, fill = false) | ||
.padding(horizontal = 24.dp) | ||
.fillMaxWidth(), | ||
text = stringResource(R.string.choose_save_location_message), | ||
color = MaterialTheme.colorScheme.onSurfaceVariant, | ||
style = MaterialTheme.typography.bodyMedium, | ||
) | ||
Spacer(Modifier.height(16.dp)) | ||
BitwardenWideSwitch( | ||
modifier = Modifier.padding(horizontal = 16.dp), | ||
label = stringResource(R.string.save_option_as_default), | ||
isChecked = isSaveAsDefaultChecked, | ||
onCheckedChange = { isSaveAsDefaultChecked = !isSaveAsDefaultChecked }, | ||
) | ||
Spacer(Modifier.height(16.dp)) | ||
FlowRow( | ||
horizontalArrangement = Arrangement.End, | ||
modifier = Modifier.padding(horizontal = 8.dp), | ||
) { | ||
BitwardenTextButton( | ||
modifier = Modifier | ||
.padding(horizontal = 4.dp), | ||
label = stringResource(R.string.save_here), | ||
labelTextColor = MaterialTheme.colorScheme.primary, | ||
onClick = { onSaveHereClick.invoke(isSaveAsDefaultChecked) }, | ||
) | ||
BitwardenTextButton( | ||
modifier = Modifier | ||
.padding(horizontal = 4.dp), | ||
label = stringResource(R.string.take_me_to_bitwarden), | ||
labelTextColor = MaterialTheme.colorScheme.primary, | ||
onClick = { onTakeMeToBitwardenClick.invoke(isSaveAsDefaultChecked) }, | ||
) | ||
} | ||
Spacer(modifier = Modifier.height(24.dp)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.