Skip to content

Commit

Permalink
feat: Add border around selected Transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinBoulongne committed Nov 7, 2024
1 parent 31748f2 commit e71cf27
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ private fun FileItemContent(
) {
Card(
onClick = onClick,
modifier = Modifier.aspectRatio(164 / 152f),
modifier = Modifier.aspectRatio(164.0f / 152.0f),
colors = CardDefaults.cardColors(containerColor = SwissTransferTheme.materialColors.background),
shape = CustomShapes.SMALL,
border = BorderStroke(width = Dimens.BorderWidth, SwissTransferTheme.materialColors.outlineVariant),
border = BorderStroke(width = Dimens.BorderWidth, color = SwissTransferTheme.materialColors.outlineVariant),
) {
Box(
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package com.infomaniak.swisstransfer.ui.components.transfer

import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.layout.*
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
Expand All @@ -35,6 +36,7 @@ import com.infomaniak.swisstransfer.ui.components.TextDotText
import com.infomaniak.swisstransfer.ui.images.AppImages.AppIcons
import com.infomaniak.swisstransfer.ui.images.icons.ChevronRightThick
import com.infomaniak.swisstransfer.ui.theme.CustomShapes
import com.infomaniak.swisstransfer.ui.theme.Dimens
import com.infomaniak.swisstransfer.ui.theme.Margin
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
import com.infomaniak.swisstransfer.ui.utils.HumanReadableSizeUtils
Expand All @@ -45,7 +47,11 @@ import java.util.UUID

@OptIn(ExperimentalLayoutApi::class)
@Composable
fun TransferItem(transfer: TransferUi, onClick: () -> Unit) {
fun TransferItem(
transfer: TransferUi,
isSelected: () -> Boolean,
onClick: () -> Unit,
) {

val createdDate = Date(transfer.createdDateTimestamp).format(FORMAT_DATE_TITLE)
val expirationDate = Date(transfer.expirationDateTimestamp)
Expand All @@ -66,11 +72,17 @@ fun TransferItem(transfer: TransferUi, onClick: () -> Unit) {
stringResource(R.string.expiresIn, remainingDays) to SwissTransferTheme.colors.secondaryTextColor
}
}
val border = if (isSelected()) {
BorderStroke(width = Dimens.BorderWidth, color = SwissTransferTheme.colors.transferListStroke)
} else {
null
}

Card(
onClick = onClick,
colors = CardDefaults.cardColors(containerColor = SwissTransferTheme.materialColors.surfaceContainerHighest),
shape = CustomShapes.SMALL,
border = border,
) {
Row(
modifier = Modifier.padding(Margin.Medium),
Expand Down Expand Up @@ -178,6 +190,7 @@ private fun Preview() {
),
),
),
isSelected = { false },
onClick = {},
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@ import java.util.UUID
fun TransferItemList(
modifier: Modifier = Modifier,
transfers: List<TransferUi>,
getSelectedTransferUuid: () -> String?,
onClick: (TransferUi) -> Unit,
) {

val selectedTransferUuid = getSelectedTransferUuid()

LazyColumn(
modifier = modifier,
verticalArrangement = Arrangement.spacedBy(Margin.Medium),
Expand All @@ -60,7 +64,11 @@ fun TransferItemList(
contentType = { transfers[it] },
itemContent = {
val transfer = transfers[it]
TransferItem(transfer) { onClick(transfer) }
TransferItem(
transfer = transfer,
isSelected = { selectedTransferUuid == transfer.uuid },
onClick = { onClick(transfer) },
)
},
)
}
Expand Down Expand Up @@ -159,7 +167,11 @@ private fun Preview() {

SwissTransferTheme {
Surface {
TransferItemList(transfers = transfers, onClick = {})
TransferItemList(
transfers = transfers,
getSelectedTransferUuid = { null },
onClick = {},
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,23 @@ import java.util.UUID
@Composable
fun ReceivedScreen(
navigateToDetails: (transferUuid: String) -> Unit,
getSelectedTransferUuid: () -> String?,
sentViewModel: SentViewModel = hiltViewModel<SentViewModel>(),
) {
val transfers by sentViewModel.transfers.collectAsStateWithLifecycle()
val areTransfersEmpty by remember { derivedStateOf { transfers?.isEmpty() == true } }

ReceivedScreen(
navigateToDetails = navigateToDetails,
getSelectedTransferUuid = getSelectedTransferUuid,
areTransfersEmpty = { areTransfersEmpty },
)
}

@Composable
private fun ReceivedScreen(
navigateToDetails: (transferUuid: String) -> Unit,
getSelectedTransferUuid: () -> String?,
areTransfersEmpty: () -> Boolean,
) {

Expand Down Expand Up @@ -169,6 +172,7 @@ private fun ReceivedScreen(
TransferItemList(
modifier = Modifier.padding(Margin.Medium),
transfers = transfers,
getSelectedTransferUuid = getSelectedTransferUuid,
onClick = { transfer ->
when {
transfer.expiresInDays < 0 -> {
Expand Down Expand Up @@ -211,6 +215,7 @@ private fun Preview() {
Surface {
ReceivedScreen(
navigateToDetails = {},
getSelectedTransferUuid = { null },
areTransfersEmpty = { true },
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ fun ReceivedScreenWrapper() {
private fun ListPane(navigator: ThreePaneScaffoldNavigator<String>) {
ReceivedScreen(
navigateToDetails = { transferUuid -> navigator.navigateTo(ListDetailPaneScaffoldRole.Detail, transferUuid) },
getSelectedTransferUuid = { navigator.currentDestination?.content },
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,5 @@ val CustomDarkColorScheme = CustomColorScheme(
qrCodeLightPixels = Color(dark1),
transferFilePreviewOverflow = Color(dark3),
onTransferFilePreviewOverflow = Color(green_main),
transferListStroke = Color(green_main),
)
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,5 @@ val CustomLightColorScheme = CustomColorScheme(
qrCodeLightPixels = Color(white),
transferFilePreviewOverflow = Color(green_dark),
onTransferFilePreviewOverflow = Color(green_contrast),
transferListStroke = Color(green_dark),
)
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ data class CustomColorScheme(
val qrCodeLightPixels: Color = Color.Unspecified,
val transferFilePreviewOverflow: Color = Color.Unspecified,
val onTransferFilePreviewOverflow: Color = Color.Unspecified,
val transferListStroke: Color = Color.Unspecified,
)

private val Shapes = Shapes(
Expand Down

0 comments on commit e71cf27

Please sign in to comment.