Skip to content

Commit

Permalink
Merge pull request #221 from Infomaniak/handle-password
Browse files Browse the repository at this point in the history
feat: Enable user to see their password
  • Loading branch information
sirambd authored Dec 2, 2024
2 parents 1d5d9bf + 9aee3bb commit 0881f0d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ private fun TransferDetailsScreen(

val context = LocalContext.current
val transferRecipients: List<String> = emptyList() // TODO: Use real data
val transferPassword = "toto42" // TODO: Use real data

var isMultiselectOn: Boolean by rememberSaveable { mutableStateOf(false) }
var showQrCodeBottomSheet: Boolean by rememberSaveable { mutableStateOf(false) }
Expand All @@ -123,6 +122,7 @@ private fun TransferDetailsScreen(
BottomBar(
direction = direction,
isMultiselectOn = { isMultiselectOn },
shouldShowPassword = { getTransfer().password?.isNotEmpty() == true },
onClick = { item ->
when (item) {
BottomBarItem.SHARE -> context.shareText(transferUrl)
Expand All @@ -149,7 +149,7 @@ private fun TransferDetailsScreen(
)
PasswordBottomSheet(
isVisible = { showPasswordBottomSheet },
transferPassword = transferPassword,
transferPassword = { getTransfer().password },
closeBottomSheet = { showPasswordBottomSheet = false },
)
}
Expand Down Expand Up @@ -230,7 +230,12 @@ private fun TransferContentHeader() {
}

@Composable
private fun BottomBar(direction: TransferDirection, isMultiselectOn: () -> Boolean, onClick: (BottomBarItem) -> Unit) {
private fun BottomBar(
direction: TransferDirection,
isMultiselectOn: () -> Boolean,
shouldShowPassword: () -> Boolean,
onClick: (BottomBarItem) -> Unit,
) {
Column(
modifier = Modifier
.height(80.dp)
Expand All @@ -250,8 +255,10 @@ private fun BottomBar(direction: TransferDirection, isMultiselectOn: () -> Boole
Spacer(Modifier.width(Margin.Medium))
BottomBarButton(BottomBarItem.QR_CODE, onClick)

Spacer(Modifier.width(Margin.Medium))
BottomBarButton(BottomBarItem.PASSWORD, onClick)
if (shouldShowPassword()) {
Spacer(Modifier.width(Margin.Medium))
BottomBarButton(BottomBarItem.PASSWORD, onClick)
}
}
TransferDirection.RECEIVED -> {
Spacer(Modifier.width(Margin.Medium))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ import com.infomaniak.swisstransfer.ui.utils.copyText
import kotlinx.coroutines.launch

@Composable
fun PasswordBottomSheet(isVisible: () -> Boolean, transferPassword: String, closeBottomSheet: () -> Unit) {
fun PasswordBottomSheet(isVisible: () -> Boolean, transferPassword: () -> String?, closeBottomSheet: () -> Unit) {

if (!isVisible()) return
val password = transferPassword()

if (!isVisible() || password == null) return

val context = LocalContext.current
val scope = rememberCoroutineScope()
Expand All @@ -57,7 +59,7 @@ fun PasswordBottomSheet(isVisible: () -> Boolean, transferPassword: String, clos
imageVector = AppIcons.DocumentOnDocument,
onClick = {
context.copyText(
text = transferPassword,
text = password,
showSnackbar = { scope.launch { snackbarHostState.showSnackbar(it) } },
)
closeBottomSheet()
Expand All @@ -79,7 +81,7 @@ fun PasswordBottomSheet(isVisible: () -> Boolean, transferPassword: String, clos
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = Margin.Medium),
initialValue = transferPassword,
initialValue = password,
isPassword = true,
isReadOnly = true,
)
Expand All @@ -93,7 +95,7 @@ private fun Preview() {
Surface {
PasswordBottomSheet(
isVisible = { true },
transferPassword = "toto42",
transferPassword = { "toto42" },
closeBottomSheet = {},
)
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ qrose = "1.0.1"
recaptcha = "18.6.1"
sentry = "4.12.0"
serialization = "1.7.3"
swisstransfer = "0.9.0"
swisstransfer = "0.9.2"
workmanager = "2.10.0"

[libraries]
Expand Down

0 comments on commit 0881f0d

Please sign in to comment.