Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Use real data for Sent & Received transfers lists #175

Merged
merged 4 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ import com.infomaniak.swisstransfer.ui.utils.PreviewLightAndDark
fun TransferItemList(
modifier: Modifier = Modifier,
direction: TransferDirection,
transfers: List<TransferUi>,
getSelectedTransferUuid: () -> String?,
getTransfers: () -> List<TransferUi>,
onClick: (TransferUi) -> Unit,
) {

Expand All @@ -58,11 +58,11 @@ fun TransferItemList(
item { Text(stringResource(titleRes), style = SwissTransferTheme.typography.h1) }

items(
count = transfers.count(),
key = { transfers[it].uuid },
contentType = { transfers[it] },
count = getTransfers().count(),
key = { getTransfers()[it].uuid },
contentType = { getTransfers()[it] },
itemContent = {
val transfer = transfers[it]
val transfer = getTransfers()[it]
TransferItem(
transfer = transfer,
isSelected = { selectedTransferUuid == transfer.uuid },
Expand All @@ -79,9 +79,9 @@ private fun Preview(@PreviewParameter(TransferUiListPreviewParameter::class) tra
SwissTransferTheme {
Surface {
TransferItemList(
transfers = transfers,
direction = TransferDirection.SENT,
getSelectedTransferUuid = { null },
getTransfers = { transfers },
onClick = {},
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.PreviewParameter
import com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui.TransferUi
import com.infomaniak.multiplatform_swisstransfer.common.models.TransferDirection
import com.infomaniak.swisstransfer.ui.previewparameter.transfersPreviewData
import com.infomaniak.swisstransfer.ui.previewparameter.TransferUiListPreviewParameter
import com.infomaniak.swisstransfer.ui.theme.Margin
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
import com.infomaniak.swisstransfer.ui.utils.PreviewLightAndDark
Expand All @@ -38,6 +40,7 @@ fun TransfersListWithExpiredBottomSheet(
direction: TransferDirection,
navigateToDetails: (transferUuid: String) -> Unit,
getSelectedTransferUuid: () -> String?,
getTransfers: () -> List<TransferUi>,
) {

var isExpirySheetVisible: Boolean by rememberSaveable { mutableStateOf(false) }
Expand All @@ -47,8 +50,8 @@ fun TransfersListWithExpiredBottomSheet(
TransferItemList(
modifier = Modifier.padding(Margin.Medium),
direction = direction,
transfers = transfersPreviewData, // TODO: Use real data
getSelectedTransferUuid = getSelectedTransferUuid,
getTransfers = getTransfers,
onClick = { transfer ->
when {
transfer.expiresInDays < 0 -> {
Expand Down Expand Up @@ -81,13 +84,14 @@ fun TransfersListWithExpiredBottomSheet(

@PreviewLightAndDark
@Composable
private fun Preview() {
private fun Preview(@PreviewParameter(TransferUiListPreviewParameter::class) transfers: List<TransferUi>) {
SwissTransferTheme {
Surface {
TransfersListWithExpiredBottomSheet(
direction = TransferDirection.RECEIVED,
navigateToDetails = {},
getSelectedTransferUuid = { null },
getTransfers = { transfers },
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ package com.infomaniak.swisstransfer.ui.screen.main.received

import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
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.EmptyState
Expand All @@ -40,34 +43,41 @@ fun ReceivedScreen(
getSelectedTransferUuid: () -> String?,
transfersViewModel: TransfersViewModel = hiltViewModel<TransfersViewModel>(),
) {

val transfers by transfersViewModel.receivedTransfers.collectAsStateWithLifecycle()
val areTransfersEmpty = false // TODO: Use the next line instead when available :
// val areTransfersEmpty by remember { derivedStateOf { transfers?.isEmpty() == true } }

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

@Composable
private fun ReceivedScreen(
KevinBoulongne marked this conversation as resolved.
Show resolved Hide resolved
navigateToDetails: (transferUuid: String) -> Unit,
getSelectedTransferUuid: () -> String?,
areTransfersEmpty: () -> Boolean,
getTransfers: () -> List<TransferUi>,
) {

val areTransfersEmpty by remember { derivedStateOf { getTransfers().isEmpty() } }

BrandTopAppBarScaffold(
floatingActionButton = { ReceivedEmptyFab(areTransfersEmpty) },
floatingActionButton = { ReceivedEmptyFab { areTransfersEmpty } },
) {
if (areTransfersEmpty()) {
if (areTransfersEmpty) {
EmptyState(
icon = AppIllus.MascotSearching,
titleRes = R.string.noTransferReceivedTitle,
descriptionRes = R.string.noTransferReceivedDescription,
)
} else {
TransfersListWithExpiredBottomSheet(TransferDirection.RECEIVED, navigateToDetails, getSelectedTransferUuid)
TransfersListWithExpiredBottomSheet(
direction = TransferDirection.RECEIVED,
navigateToDetails = navigateToDetails,
getSelectedTransferUuid = getSelectedTransferUuid,
getTransfers = getTransfers,
)
}
}
}
Expand All @@ -80,7 +90,7 @@ private fun Preview() {
ReceivedScreen(
navigateToDetails = {},
getSelectedTransferUuid = { null },
areTransfersEmpty = { false },
getTransfers = { emptyList() },
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui.TransferUi
import com.infomaniak.multiplatform_swisstransfer.common.models.TransferDirection
import com.infomaniak.swisstransfer.ui.components.NewTransferFab
import com.infomaniak.swisstransfer.ui.components.NewTransferFabType
import com.infomaniak.swisstransfer.ui.components.transfer.TransfersListWithExpiredBottomSheet
import com.infomaniak.swisstransfer.ui.previewparameter.TransferUiListPreviewParameter
import com.infomaniak.swisstransfer.ui.screen.main.components.BrandTopAppBarScaffold
import com.infomaniak.swisstransfer.ui.screen.main.transfers.TransfersViewModel
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
Expand All @@ -41,49 +44,55 @@ fun SentScreen(
getSelectedTransferUuid: () -> String?,
transfersViewModel: TransfersViewModel = hiltViewModel<TransfersViewModel>(),
) {

val transfers by transfersViewModel.sentTransfers.collectAsStateWithLifecycle()
val areTransfersEmpty by remember { derivedStateOf { transfers?.isEmpty() == true } }

SentScreen(
navigateToDetails = navigateToDetails,
getSelectedTransferUuid = getSelectedTransferUuid,
areTransfersEmpty = { areTransfersEmpty },
getTransfers = { transfers },
)
}

@Composable
private fun SentScreen(
navigateToDetails: (transferUuid: String) -> Unit,
getSelectedTransferUuid: () -> String?,
areTransfersEmpty: () -> Boolean,
getTransfers: () -> List<TransferUi>,
) {

val areTransfersEmpty by remember { derivedStateOf { getTransfers().isEmpty() } }
val windowAdaptiveInfo = currentWindowAdaptiveInfo()

BrandTopAppBarScaffold(
floatingActionButton = {
if (windowAdaptiveInfo.isWindowSmall() && !areTransfersEmpty()) {
if (windowAdaptiveInfo.isWindowSmall() && !areTransfersEmpty) {
NewTransferFab(newTransferFabType = NewTransferFabType.BOTTOM_BAR)
}
},
) {
if (areTransfersEmpty()) {
if (areTransfersEmpty) {
SentEmptyScreen()
} else {
TransfersListWithExpiredBottomSheet(TransferDirection.SENT, navigateToDetails, getSelectedTransferUuid)
TransfersListWithExpiredBottomSheet(
direction = TransferDirection.SENT,
navigateToDetails = navigateToDetails,
getSelectedTransferUuid = getSelectedTransferUuid,
getTransfers = getTransfers,
)
}
}
}

@PreviewAllWindows
@Composable
private fun Preview() {
private fun Preview(@PreviewParameter(TransferUiListPreviewParameter::class) transfers: List<TransferUi>) {
SwissTransferTheme {
Surface {
SentScreen(
navigateToDetails = {},
getSelectedTransferUuid = { null },
areTransfersEmpty = { true },
getTransfers = { transfers },
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ private fun TransferDetailsScreen(
val transferPassword = "toto42" // TODO: Use real data

var isMultiselectOn: Boolean by rememberSaveable { mutableStateOf(false) }
var showQrCodeSheet: Boolean by rememberSaveable { mutableStateOf(false) }
var showPasswordSheet: Boolean by rememberSaveable { mutableStateOf(false) }
var showQrCodeBottomSheet: Boolean by rememberSaveable { mutableStateOf(false) }
var showPasswordBottomSheet: Boolean by rememberSaveable { mutableStateOf(false) }

SmallWindowTopAppBarScaffold(
smallWindowTopAppBar = {
Expand All @@ -115,8 +115,8 @@ private fun TransferDetailsScreen(
onClick = { item ->
when (item) {
BottomBarItem.SHARE -> context.shareText(transferUrl)
BottomBarItem.QR_CODE -> showQrCodeSheet = true
BottomBarItem.PASSWORD -> showPasswordSheet = true
BottomBarItem.QR_CODE -> showQrCodeBottomSheet = true
BottomBarItem.PASSWORD -> showPasswordBottomSheet = true
BottomBarItem.DOWNLOAD -> {
// TODO: Move the multiselect elsewhere, and implement this feature
isMultiselectOn = true
Expand All @@ -132,14 +132,14 @@ private fun TransferDetailsScreen(
}

QrCodeBottomSheet(
isVisible = { showQrCodeSheet },
isVisible = { showQrCodeBottomSheet },
transferUrl = transferUrl,
closeBottomSheet = { showQrCodeSheet = false },
closeBottomSheet = { showQrCodeBottomSheet = false },
)
PasswordBottomSheet(
isVisible = { showPasswordSheet },
isVisible = { showPasswordBottomSheet },
transferPassword = transferPassword,
closeBottomSheet = { showPasswordSheet = false },
closeBottomSheet = { showPasswordBottomSheet = false },
)
}
}
Expand Down
Loading