Skip to content

Commit

Permalink
feat: Make Sent screen use the ScreenWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinBoulongne committed Nov 12, 2024
1 parent 6414ed3 commit c924d10
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
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.R
import com.infomaniak.swisstransfer.ui.previewparameter.TransferUiListPreviewParameter
import com.infomaniak.swisstransfer.ui.theme.Margin
Expand All @@ -36,12 +37,14 @@ import com.infomaniak.swisstransfer.ui.utils.PreviewLightAndDark
@Composable
fun TransferItemList(
modifier: Modifier = Modifier,
direction: TransferDirection,
transfers: List<TransferUi>,
getSelectedTransferUuid: () -> String?,
onClick: (TransferUi) -> Unit,
) {

val selectedTransferUuid = getSelectedTransferUuid()
val titleRes = if (direction == TransferDirection.SENT) R.string.sentFilesTitle else R.string.receivedFilesTitle

LazyColumn(
modifier = modifier,
Expand All @@ -51,7 +54,7 @@ fun TransferItemList(

item {
Text(
text = stringResource(R.string.receivedFilesTitle),
text = stringResource(titleRes),
style = SwissTransferTheme.typography.h1,
)
}
Expand Down Expand Up @@ -79,6 +82,7 @@ private fun Preview(@PreviewParameter(TransferUiListPreviewParameter::class) tra
Surface {
TransferItemList(
transfers = transfers,
direction = TransferDirection.SENT,
getSelectedTransferUuid = { null },
onClick = {},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import com.infomaniak.multiplatform_swisstransfer.common.models.TransferDirection
import com.infomaniak.swisstransfer.ui.previewparameter.transfersPreviewData
import com.infomaniak.swisstransfer.ui.theme.Margin
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
Expand All @@ -34,6 +35,7 @@ import java.util.Date

@Composable
fun TransfersListWithExpiredBottomSheet(
direction: TransferDirection,
navigateToDetails: (transferUuid: String) -> Unit,
getSelectedTransferUuid: () -> String?,
) {
Expand All @@ -44,6 +46,7 @@ fun TransfersListWithExpiredBottomSheet(

TransferItemList(
modifier = Modifier.padding(Margin.Medium),
direction = direction,
transfers = transfersPreviewData, // TODO: Use real data
getSelectedTransferUuid = getSelectedTransferUuid,
onClick = { transfer ->
Expand Down Expand Up @@ -82,6 +85,7 @@ private fun Preview() {
SwissTransferTheme {
Surface {
TransfersListWithExpiredBottomSheet(
direction = TransferDirection.RECEIVED,
navigateToDetails = {},
getSelectedTransferUuid = { null },
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import androidx.compose.runtime.Composable
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import com.infomaniak.multiplatform_swisstransfer.common.models.TransferDirection
import com.infomaniak.swisstransfer.ui.navigation.MainNavigation
import com.infomaniak.swisstransfer.ui.navigation.MainNavigation.*
import com.infomaniak.swisstransfer.ui.screen.main.received.ReceivedScreenWrapper
import com.infomaniak.swisstransfer.ui.screen.main.sent.SentScreen
import com.infomaniak.swisstransfer.ui.screen.main.settings.SettingsScreenWrapper
import com.infomaniak.swisstransfer.ui.screen.main.transfers.TransfersScreenWrapper

@Composable
fun MainNavHost(
Expand All @@ -42,14 +42,8 @@ fun MainNavHost(
enterTransition = { if (currentDestination.enableTransition) fadeIn() else EnterTransition.None },
exitTransition = { if (currentDestination.enableTransition) fadeOut() else ExitTransition.None },
) {
composable<SentDestination> {
SentScreen(navigateToDetails = { navController.navigate(TransferDetailsDestination(it)) })
}
composable<ReceivedDestination> {
ReceivedScreenWrapper()
}
composable<SettingsDestination> {
SettingsScreenWrapper()
}
composable<SentDestination> { TransfersScreenWrapper(TransferDirection.SENT) }
composable<ReceivedDestination> { TransfersScreenWrapper(TransferDirection.RECEIVED) }
composable<SettingsDestination> { SettingsScreenWrapper() }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,30 @@ 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.models.TransferDirection
import com.infomaniak.swisstransfer.R
import com.infomaniak.swisstransfer.ui.components.EmptyState
import com.infomaniak.swisstransfer.ui.components.transfer.TransfersListWithExpiredBottomSheet
import com.infomaniak.swisstransfer.ui.images.AppImages.AppIllus
import com.infomaniak.swisstransfer.ui.images.illus.MascotSearching
import com.infomaniak.swisstransfer.ui.screen.main.components.BrandTopAppBarScaffold
import com.infomaniak.swisstransfer.ui.screen.main.received.components.ReceivedEmptyFab
import com.infomaniak.swisstransfer.ui.screen.main.sent.SentViewModel
import com.infomaniak.swisstransfer.ui.screen.main.transfers.TransfersViewModel
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows

@Composable
fun ReceivedScreen(
navigateToDetails: (transferUuid: String) -> Unit,
getSelectedTransferUuid: () -> String?,
sentViewModel: SentViewModel = hiltViewModel<SentViewModel>(),
transfersViewModel: TransfersViewModel = hiltViewModel<TransfersViewModel>(),
) {
val transfers by sentViewModel.transfers.collectAsStateWithLifecycle()
val areTransfersEmpty by remember { derivedStateOf { transfers?.isEmpty() == true } }
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,
Expand All @@ -67,7 +67,7 @@ private fun ReceivedScreen(
descriptionRes = R.string.noTransferReceivedDescription,
)
} else {
TransfersListWithExpiredBottomSheet(navigateToDetails, getSelectedTransferUuid)
TransfersListWithExpiredBottomSheet(TransferDirection.RECEIVED, navigateToDetails, getSelectedTransferUuid)
}
}
}
Expand All @@ -80,7 +80,7 @@ private fun Preview() {
ReceivedScreen(
navigateToDetails = {},
getSelectedTransferUuid = { null },
areTransfersEmpty = { true },
areTransfersEmpty = { false },
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,58 @@ package com.infomaniak.swisstransfer.ui.screen.main.sent
import androidx.compose.material3.Surface
import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo
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.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.screen.main.components.BrandTopAppBarScaffold
import com.infomaniak.swisstransfer.ui.screen.main.transfers.TransfersViewModel
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows
import com.infomaniak.swisstransfer.ui.utils.isWindowSmall

@Composable
fun SentScreen(
navigateToDetails: (transferUuid: String) -> Unit,
sentViewModel: SentViewModel = hiltViewModel<SentViewModel>(),
getSelectedTransferUuid: () -> String?,
transfersViewModel: TransfersViewModel = hiltViewModel<TransfersViewModel>(),
) {
val transfers by sentViewModel.transfers.collectAsStateWithLifecycle()
SentScreen(transfers)
val transfers by transfersViewModel.sentTransfers.collectAsStateWithLifecycle()
val areTransfersEmpty by remember { derivedStateOf { transfers?.isEmpty() == true } }

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

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

if (transfers == null) return
val windowAdaptiveInfo = currentWindowAdaptiveInfo()

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

Expand All @@ -61,7 +80,11 @@ private fun SentScreen(transfers: List<Any>?) {
private fun Preview() {
SwissTransferTheme {
Surface {
SentScreen(transfers = emptyList())
SentScreen(
navigateToDetails = {},
getSelectedTransferUuid = { null },
areTransfersEmpty = { true },
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* 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.received
package com.infomaniak.swisstransfer.ui.screen.main.transfers

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
Expand All @@ -28,29 +28,38 @@ import androidx.compose.material3.adaptive.navigation.ThreePaneScaffoldNavigator
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import com.infomaniak.multiplatform_swisstransfer.common.models.TransferDirection
import com.infomaniak.swisstransfer.ui.components.TwoPaneScaffold
import com.infomaniak.swisstransfer.ui.components.safeCurrentContent
import com.infomaniak.swisstransfer.ui.screen.main.received.ReceivedScreen
import com.infomaniak.swisstransfer.ui.screen.main.sent.SentScreen
import com.infomaniak.swisstransfer.ui.screen.main.transferdetails.TransferDetailsScreen
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows
import com.infomaniak.swisstransfer.ui.utils.ScreenWrapperUtils

@OptIn(ExperimentalMaterial3AdaptiveApi::class)
@Composable
fun ReceivedScreenWrapper() {
fun TransfersScreenWrapper(direction: TransferDirection) {
TwoPaneScaffold<String>(
listPane = { ListPane(navigator = this) },
listPane = { ListPane(direction, navigator = this) },
detailPane = { DetailPane(navigator = this) },
)
}

@OptIn(ExperimentalMaterial3AdaptiveApi::class)
@Composable
private fun ListPane(navigator: ThreePaneScaffoldNavigator<String>) {
ReceivedScreen(
navigateToDetails = { transferUuid -> navigator.navigateTo(ListDetailPaneScaffoldRole.Detail, transferUuid) },
getSelectedTransferUuid = { navigator.currentDestination?.content },
)
private fun ListPane(direction: TransferDirection, navigator: ThreePaneScaffoldNavigator<String>) {
when (direction) {
TransferDirection.SENT -> SentScreen(
navigateToDetails = { transferUuid -> navigator.navigateTo(ListDetailPaneScaffoldRole.Detail, transferUuid) },
getSelectedTransferUuid = { navigator.currentDestination?.content },
)
TransferDirection.RECEIVED -> ReceivedScreen(
navigateToDetails = { transferUuid -> navigator.navigateTo(ListDetailPaneScaffoldRole.Detail, transferUuid) },
getSelectedTransferUuid = { navigator.currentDestination?.content },
)
}
}

@OptIn(ExperimentalMaterial3AdaptiveApi::class)
Expand Down Expand Up @@ -81,7 +90,7 @@ private fun NoSelectionEmptyState() {
private fun Preview() {
SwissTransferTheme {
Surface(color = MaterialTheme.colorScheme.background) {
ReceivedScreenWrapper()
TransfersScreenWrapper(TransferDirection.RECEIVED)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* 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.sent
package com.infomaniak.swisstransfer.ui.screen.main.transfers

import androidx.compose.runtime.mutableStateMapOf
import androidx.compose.runtime.snapshots.SnapshotStateMap
Expand All @@ -28,7 +28,8 @@ import kotlinx.coroutines.flow.stateIn
import javax.inject.Inject

@HiltViewModel
class SentViewModel @Inject constructor() : ViewModel() {
val transfers = flow<List<Any>> { emit(listOf(1)) }.stateIn(viewModelScope, SharingStarted.Eagerly, null)
class TransfersViewModel @Inject constructor() : ViewModel() {
val sentTransfers = flow<List<Any>> { emit(listOf(1)) }.stateIn(viewModelScope, SharingStarted.Eagerly, null)
val receivedTransfers = flow<List<Any>> { emit(listOf(1)) }.stateIn(viewModelScope, SharingStarted.Eagerly, null)
val selectedTransferUuids: SnapshotStateMap<String, Boolean> = mutableStateMapOf()
}
1 change: 1 addition & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<string name="receivedFilesTitle">Empfangene Dateien</string>
<string name="receivedTitle">Empfangen</string>
<string name="sentEmptyTitle">Unsere Geschichte beginnt hier</string>
<string name="sentFilesTitle">Geteilte Dateien</string>
<string name="sentTitle">Gesendet</string>
<string name="settingsAuthorizeTracking">Verfolgung genehmigen</string>
<string name="settingsCategoryAbout">Über</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<string name="receivedFilesTitle">Archivos recibidos</string>
<string name="receivedTitle">Recibido</string>
<string name="sentEmptyTitle">Nuestra historia comienza aquí</string>
<string name="sentFilesTitle">Archivos compartidos</string>
<string name="sentTitle">Enviado a</string>
<string name="settingsAuthorizeTracking">Autorizar el seguimiento</string>
<string name="settingsCategoryAbout">Quiénes somos</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<string name="receivedFilesTitle">Fichiers reçus</string>
<string name="receivedTitle">Reçu</string>
<string name="sentEmptyTitle">Notre histoire commence ici</string>
<string name="sentFilesTitle">Fichiers partagés</string>
<string name="sentTitle">Envoyé</string>
<string name="settingsAuthorizeTracking">Autoriser le suivi</string>
<string name="settingsCategoryAbout">A propos</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<string name="receivedFilesTitle">File ricevuti</string>
<string name="receivedTitle">Ricevuto</string>
<string name="sentEmptyTitle">La nostra storia inizia qui</string>
<string name="sentFilesTitle">File condivisi</string>
<string name="sentTitle">Inviato a</string>
<string name="settingsAuthorizeTracking">Autorizza il tracciamento</string>
<string name="settingsCategoryAbout">Chi siamo</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<string name="receivedFilesTitle">Received files</string>
<string name="receivedTitle">Received</string>
<string name="sentEmptyTitle">Our story begins here</string>
<string name="sentFilesTitle">Shared files</string>
<string name="sentTitle">Sent</string>
<string name="settingsAuthorizeTracking">Authorize tracking</string>
<string name="settingsCategoryAbout">About</string>
Expand Down

0 comments on commit c924d10

Please sign in to comment.