Skip to content

Commit

Permalink
feat: Display sent Transfers details
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinBoulongne committed Nov 13, 2024
1 parent 8b10cfc commit 9b0c038
Show file tree
Hide file tree
Showing 12 changed files with 342 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ fun SwissTransferTextField(
keyboardType: KeyboardType = KeyboardType.Text,
imeAction: ImeAction = ImeAction.Default,
keyboardActions: KeyboardActions = KeyboardActions.Default,
isReadOnly: Boolean = false,
errorMessage: @Composable () -> String? = { null },
supportingText: String? = null,
onValueChange: ((String) -> Unit)? = null,
Expand All @@ -74,6 +75,9 @@ fun SwissTransferTextField(
val textFieldColors = OutlinedTextFieldDefaults.colors(
unfocusedLabelColor = SwissTransferTheme.colors.tertiaryTextColor,
unfocusedSupportingTextColor = SwissTransferTheme.colors.tertiaryTextColor,
disabledBorderColor = SwissTransferTheme.materialColors.outline,
unfocusedTrailingIconColor = SwissTransferTheme.colors.iconColor,
disabledTrailingIconColor = SwissTransferTheme.colors.iconColor,
)

@Composable
Expand All @@ -89,6 +93,8 @@ fun SwissTransferTextField(

OutlinedTextField(
modifier = modifier,
readOnly = isReadOnly,
enabled = !isReadOnly,
value = text,
label = displayLabel?.let { { Text(text = it) } },
minLines = minLineNumber,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = {
Expand All @@ -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
Expand All @@ -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,
)
}
}

Expand All @@ -171,6 +187,7 @@ private fun TransferContentHeader() {

@Composable
private fun BottomBar(
direction: TransferDirection,
isMultiselectOn: () -> Boolean,
onClick: (BottomBarItem) -> Unit,
) {
Expand All @@ -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)
}
}
}
}
}
Expand All @@ -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),
}
Expand All @@ -224,7 +255,7 @@ private enum class BottomBarItem(@StringRes val label: Int, val icon: ImageVecto
private fun Preview() {
SwissTransferTheme {
Surface {
TransferDetailsScreen("", {})
TransferDetailsScreen("", TransferDirection.SENT, {})
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@ package com.infomaniak.swisstransfer.ui.screen.main.transferdetails
import androidx.compose.runtime.mutableStateMapOf
import androidx.compose.runtime.snapshots.SnapshotStateMap
import androidx.lifecycle.ViewModel
import com.infomaniak.multiplatform_swisstransfer.SharedApiUrlCreator
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class TransferDetailsViewModel @Inject constructor() : ViewModel() {
class TransferDetailsViewModel @Inject constructor(
private val sharedApiUrlCreator: SharedApiUrlCreator,
) : ViewModel() {

val checkedFiles: SnapshotStateMap<String, Boolean> = mutableStateMapOf()

fun getTransferUrl(transferUuid: String): String = sharedApiUrlCreator.shareTransferUrl(transferUuid)
}
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 = {},
)
}
}
}
Loading

0 comments on commit 9b0c038

Please sign in to comment.