-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Display sent Transfers details
- Loading branch information
1 parent
8b10cfc
commit 9b0c038
Showing
12 changed files
with
342 additions
and
60 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
|
@@ -30,19 +30,26 @@ import androidx.compose.ui.Alignment | |
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.vector.ImageVector | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.res.pluralStringResource | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.unit.dp | ||
import androidx.hilt.navigation.compose.hiltViewModel | ||
import com.infomaniak.core2.FORMAT_DATE_FULL | ||
import com.infomaniak.core2.format | ||
import com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui.TransferUi | ||
import com.infomaniak.multiplatform_swisstransfer.common.models.TransferDirection | ||
import com.infomaniak.swisstransfer.R | ||
import com.infomaniak.swisstransfer.ui.components.* | ||
import com.infomaniak.swisstransfer.ui.images.AppImages.AppIcons | ||
import com.infomaniak.swisstransfer.ui.images.icons.ArrowDownBar | ||
import com.infomaniak.swisstransfer.ui.images.icons.LockedTextField | ||
import com.infomaniak.swisstransfer.ui.images.icons.QrCode | ||
import com.infomaniak.swisstransfer.ui.images.icons.Share | ||
import com.infomaniak.swisstransfer.ui.previewparameter.emailsPreviewData | ||
import com.infomaniak.swisstransfer.ui.previewparameter.transfersPreviewData | ||
import com.infomaniak.swisstransfer.ui.screen.main.components.SmallWindowTopAppBarScaffold | ||
import com.infomaniak.swisstransfer.ui.screen.main.transferdetails.components.PasswordBottomSheet | ||
import com.infomaniak.swisstransfer.ui.screen.main.transferdetails.components.QrCodeBottomSheet | ||
import com.infomaniak.swisstransfer.ui.screen.main.transferdetails.components.TransferInfo | ||
import com.infomaniak.swisstransfer.ui.theme.Margin | ||
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme | ||
|
@@ -53,16 +60,24 @@ import java.util.Date | |
@Composable | ||
fun TransferDetailsScreen( | ||
transferUuid: String, | ||
direction: TransferDirection, | ||
navigateBack: (() -> Unit)?, | ||
transferDetailsViewModel: TransferDetailsViewModel = hiltViewModel<TransferDetailsViewModel>(), | ||
) { | ||
|
||
val context = LocalContext.current | ||
val transfer = transfersPreviewData.first() // TODO: Use real data | ||
val transferSenderEmail: String? = "[email protected]" // TODO | ||
val transferUrl = "https://chk.me/83azQOl" // TODO | ||
val recipients = if (direction == TransferDirection.SENT) emailsPreviewData else emptyList() // TODO: Use real data | ||
val transferUrl = "https://chk.me/83azQOl" // TODO: Use the next line instead when available : | ||
// val transferUrl = transferDetailsViewModel.getTransferUrl(transferUuid) | ||
val transferPassword = "toto42" // TODO: Use real data | ||
|
||
val shouldDisplayRecipients = recipients.isNotEmpty() | ||
val shouldDisplayMessage = transfer.message != null | ||
|
||
var isMultiselectOn: Boolean by rememberSaveable { mutableStateOf(false) } | ||
val context = LocalContext.current | ||
var isQrCodeVisible: Boolean by rememberSaveable { mutableStateOf(false) } | ||
var isPasswordVisible: Boolean by rememberSaveable { mutableStateOf(false) } | ||
|
||
SmallWindowTopAppBarScaffold( | ||
smallWindowTopAppBar = { | ||
|
@@ -88,17 +103,23 @@ fun TransferDetailsScreen( | |
Column { | ||
Spacer(modifier = Modifier.height(Margin.Large)) | ||
TransferInfo(transfer) | ||
TransferMessage(transfer, transferSenderEmail) | ||
Spacer(modifier = Modifier.height(Margin.Large)) | ||
if (shouldDisplayRecipients) TransferRecipients(recipients) | ||
if (shouldDisplayRecipients && shouldDisplayMessage) Spacer(modifier = Modifier.height(Margin.Mini)) | ||
if (shouldDisplayMessage) TransferMessage(transfer) | ||
if (shouldDisplayRecipients || shouldDisplayMessage) Spacer(modifier = Modifier.height(Margin.Large)) | ||
TransferContentHeader() | ||
} | ||
} | ||
|
||
BottomBar( | ||
direction = direction, | ||
isMultiselectOn = { isMultiselectOn }, | ||
onClick = { item -> | ||
when (item) { | ||
BottomBarItem.SHARE -> context.shareText(transferUrl) | ||
BottomBarItem.QR_CODE -> isQrCodeVisible = true | ||
BottomBarItem.PASSWORD -> isPasswordVisible = true | ||
BottomBarItem.DOWNLOAD -> { | ||
// TODO: Move the multiselect elsewhere, and implement this feature | ||
isMultiselectOn = true | ||
|
@@ -112,51 +133,46 @@ fun TransferDetailsScreen( | |
}, | ||
) | ||
} | ||
|
||
QrCodeBottomSheet( | ||
isVisible = { isQrCodeVisible }, | ||
transferUrl = transferUrl, | ||
closeBottomSheet = { isQrCodeVisible = false }, | ||
) | ||
PasswordBottomSheet( | ||
isVisible = { isPasswordVisible }, | ||
transferPassword = transferPassword, | ||
closeBottomSheet = { isPasswordVisible = false }, | ||
) | ||
} | ||
} | ||
|
||
@Composable | ||
private fun TransferMessage(transfer: TransferUi, transferSenderEmail: String?) { | ||
|
||
if (transferSenderEmail == null && transfer.message == null) return | ||
|
||
Spacer(modifier = Modifier.height(Margin.Large)) | ||
private fun TransferRecipients(recipients: List<String>) { | ||
Text( | ||
text = pluralStringResource(R.plurals.recipientHeader, recipients.count()), | ||
style = SwissTransferTheme.typography.bodySmallRegular, | ||
color = SwissTransferTheme.colors.secondaryTextColor, | ||
) | ||
Spacer(modifier = Modifier.height(Margin.Mini)) | ||
EmailsFlowRow(recipients) | ||
} | ||
|
||
@Composable | ||
private fun TransferMessage(transfer: TransferUi) { | ||
Text( | ||
text = stringResource(R.string.messageHeader), | ||
style = SwissTransferTheme.typography.bodySmallRegular, | ||
color = SwissTransferTheme.colors.secondaryTextColor, | ||
) | ||
|
||
SwissTransferCard(modifier = Modifier.padding(top = Margin.Medium)) { | ||
|
||
transferSenderEmail?.let { | ||
Row( | ||
modifier = Modifier.padding(all = Margin.Large), | ||
verticalAlignment = Alignment.CenterVertically, | ||
) { | ||
Text( | ||
text = stringResource(R.string.fromHeader), | ||
style = SwissTransferTheme.typography.bodySmallRegular, | ||
color = SwissTransferTheme.colors.primaryTextColor, | ||
) | ||
EmailAddressChip( | ||
text = it, | ||
modifier = Modifier.padding(start = Margin.Mini), | ||
) | ||
} | ||
} | ||
|
||
if (transferSenderEmail != null && transfer.message != null) HorizontalDivider() | ||
|
||
transfer.message?.let { | ||
Text( | ||
text = it, | ||
modifier = Modifier.padding(all = Margin.Large), | ||
style = SwissTransferTheme.typography.bodySmallRegular, | ||
color = SwissTransferTheme.colors.primaryTextColor, | ||
) | ||
} | ||
Spacer(modifier = Modifier.height(Margin.Medium)) | ||
SwissTransferCard { | ||
Text( | ||
text = transfer.message!!, | ||
modifier = Modifier.padding(all = Margin.Large), | ||
style = SwissTransferTheme.typography.bodySmallRegular, | ||
color = SwissTransferTheme.colors.primaryTextColor, | ||
) | ||
} | ||
} | ||
|
||
|
@@ -171,6 +187,7 @@ private fun TransferContentHeader() { | |
|
||
@Composable | ||
private fun BottomBar( | ||
direction: TransferDirection, | ||
isMultiselectOn: () -> Boolean, | ||
onClick: (BottomBarItem) -> Unit, | ||
) { | ||
|
@@ -187,8 +204,20 @@ private fun BottomBar( | |
BottomBarButton(BottomBarItem.MULTISELECT_DOWNLOAD, onClick) | ||
} else { | ||
BottomBarButton(BottomBarItem.SHARE, onClick) | ||
Spacer(modifier = Modifier.width(Margin.Medium)) | ||
BottomBarButton(BottomBarItem.DOWNLOAD, onClick) | ||
|
||
when (direction) { | ||
TransferDirection.SENT -> { | ||
Spacer(modifier = Modifier.width(Margin.Medium)) | ||
BottomBarButton(BottomBarItem.QR_CODE, onClick) | ||
|
||
Spacer(modifier = Modifier.width(Margin.Medium)) | ||
BottomBarButton(BottomBarItem.PASSWORD, onClick) | ||
} | ||
TransferDirection.RECEIVED -> { | ||
Spacer(modifier = Modifier.width(Margin.Medium)) | ||
BottomBarButton(BottomBarItem.DOWNLOAD, onClick) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -215,6 +244,8 @@ private fun RowScope.BottomBarButton(item: BottomBarItem, onClick: (BottomBarIte | |
|
||
private enum class BottomBarItem(@StringRes val label: Int, val icon: ImageVector) { | ||
SHARE(R.string.buttonShare, AppIcons.Share), | ||
QR_CODE(R.string.transferTypeQrCode, AppIcons.QrCode), | ||
PASSWORD(R.string.settingsOptionPassword, AppIcons.LockedTextField), | ||
DOWNLOAD(R.string.buttonDownload, AppIcons.ArrowDownBar), | ||
MULTISELECT_DOWNLOAD(R.string.buttonDownloadSelected, AppIcons.ArrowDownBar), | ||
} | ||
|
@@ -224,7 +255,7 @@ private enum class BottomBarItem(@StringRes val label: Int, val icon: ImageVecto | |
private fun Preview() { | ||
SwissTransferTheme { | ||
Surface { | ||
TransferDetailsScreen("", {}) | ||
TransferDetailsScreen("", TransferDirection.SENT, {}) | ||
} | ||
} | ||
} |
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
105 changes: 105 additions & 0 deletions
105
...infomaniak/swisstransfer/ui/screen/main/transferdetails/components/PasswordBottomSheet.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,105 @@ | ||
/* | ||
* Infomaniak SwissTransfer - Android | ||
* Copyright (C) 2024 Infomaniak Network SA | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.infomaniak.swisstransfer.ui.screen.main.transferdetails.components | ||
|
||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.SnackbarHostState | ||
import androidx.compose.material3.Surface | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.rememberCoroutineScope | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.platform.LocalContext | ||
import com.infomaniak.swisstransfer.R | ||
import com.infomaniak.swisstransfer.ui.components.ButtonType | ||
import com.infomaniak.swisstransfer.ui.components.LargeButton | ||
import com.infomaniak.swisstransfer.ui.components.SwissTransferBottomSheet | ||
import com.infomaniak.swisstransfer.ui.components.SwissTransferTextField | ||
import com.infomaniak.swisstransfer.ui.images.AppImages.AppIcons | ||
import com.infomaniak.swisstransfer.ui.images.icons.DocumentOnDocument | ||
import com.infomaniak.swisstransfer.ui.theme.Margin | ||
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme | ||
import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows | ||
import com.infomaniak.swisstransfer.ui.utils.copyText | ||
import kotlinx.coroutines.launch | ||
|
||
@Composable | ||
fun PasswordBottomSheet( | ||
isVisible: () -> Boolean, | ||
transferPassword: String, | ||
closeBottomSheet: () -> Unit, | ||
) { | ||
|
||
if (!isVisible()) return | ||
|
||
val context = LocalContext.current | ||
val scope = rememberCoroutineScope() | ||
val snackbarHostState = remember { SnackbarHostState() } | ||
|
||
SwissTransferBottomSheet( | ||
onDismissRequest = closeBottomSheet, | ||
topButton = { | ||
LargeButton( | ||
modifier = it, | ||
titleRes = R.string.sharePasswordButton, | ||
imageVector = AppIcons.DocumentOnDocument, | ||
onClick = { | ||
context.copyText( | ||
text = transferPassword, | ||
showSnackbar = { scope.launch { snackbarHostState.showSnackbar(it) } }, | ||
) | ||
closeBottomSheet() | ||
}, | ||
) | ||
}, | ||
bottomButton = { | ||
LargeButton( | ||
modifier = it, | ||
titleRes = R.string.contentDescriptionButtonClose, | ||
style = ButtonType.SECONDARY, | ||
onClick = closeBottomSheet, | ||
) | ||
}, | ||
titleRes = R.string.sharePasswordTitle, | ||
descriptionRes = R.string.sharePasswordDescription, | ||
) { | ||
SwissTransferTextField( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(horizontal = Margin.Medium), | ||
initialValue = transferPassword, | ||
isPassword = true, | ||
isReadOnly = true, | ||
) | ||
} | ||
} | ||
|
||
@PreviewAllWindows | ||
@Composable | ||
private fun Preview() { | ||
SwissTransferTheme { | ||
Surface { | ||
PasswordBottomSheet( | ||
isVisible = { true }, | ||
transferPassword = "toto42", | ||
closeBottomSheet = {}, | ||
) | ||
} | ||
} | ||
} |
Oops, something went wrong.