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 61db8bc commit f334ac9
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ import androidx.compose.ui.tooling.preview.PreviewParameter
import com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui.TransferUi
import com.infomaniak.swisstransfer.R
import com.infomaniak.swisstransfer.ui.previewparameter.TransferUiListPreviewParameter
import com.infomaniak.swisstransfer.ui.screen.main.transfers.TransfersType
import com.infomaniak.swisstransfer.ui.theme.Margin
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
import com.infomaniak.swisstransfer.ui.utils.PreviewLightAndDark

@Composable
fun TransferItemList(
modifier: Modifier = Modifier,
type:TransfersType,
transfers: List<TransferUi>,
getSelectedTransferUuid: () -> String?,
onClick: (TransferUi) -> Unit,
Expand All @@ -51,7 +53,7 @@ fun TransferItemList(

item {
Text(
text = stringResource(R.string.receivedFilesTitle),
text = stringResource(if (type == TransfersType.SENT) R.string.sentFilesTitle else R.string.receivedFilesTitle),
style = SwissTransferTheme.typography.h1,
)
}
Expand Down Expand Up @@ -79,6 +81,7 @@ private fun Preview(@PreviewParameter(TransferUiListPreviewParameter::class) tra
Surface {
TransferItemList(
transfers = transfers,
type = TransfersType.SENT,
getSelectedTransferUuid = { null },
onClick = {},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
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
import com.infomaniak.swisstransfer.ui.screen.main.transfers.TransfersType

@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(TransfersType.SENT) }
composable<ReceivedDestination> { TransfersScreenWrapper(TransfersType.RECEIVED) }
composable<SettingsDestination> { SettingsScreenWrapper() }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ import com.infomaniak.swisstransfer.ui.images.illus.MascotSearching
import com.infomaniak.swisstransfer.ui.previewparameter.transfersPreviewData
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.TransfersType
import com.infomaniak.swisstransfer.ui.screen.main.transfers.TransfersViewModel
import com.infomaniak.swisstransfer.ui.theme.Margin
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows
Expand All @@ -44,9 +45,9 @@ import java.util.Date
fun ReceivedScreen(
navigateToDetails: (transferUuid: String) -> Unit,
getSelectedTransferUuid: () -> String?,
sentViewModel: SentViewModel = hiltViewModel<SentViewModel>(),
transfersViewModel: TransfersViewModel = hiltViewModel<TransfersViewModel>(),
) {
val transfers by sentViewModel.transfers.collectAsStateWithLifecycle()
val transfers by transfersViewModel.receivedTransfers.collectAsStateWithLifecycle()
val areTransfersEmpty by remember { derivedStateOf { transfers?.isEmpty() == true } }

ReceivedScreen(
Expand Down Expand Up @@ -79,6 +80,7 @@ private fun ReceivedScreen(
} else {
TransferItemList(
modifier = Modifier.padding(Margin.Medium),
type = TransfersType.RECEIVED,
transfers = transfersPreviewData, // TODO: Use real data
getSelectedTransferUuid = getSelectedTransferUuid,
onClick = { transfer ->
Expand All @@ -102,10 +104,7 @@ private fun ReceivedScreen(
isVisible = { isVisible },
expirationDate = { expirationDate },
downloadsLimit = { downloadsLimit },
onDeleteTransferClicked = {
Log.d("TODO", "Delete expired Transfer")
// TODO
},
onDeleteTransferClicked = { Log.d("TODO", "Delete expired Transfer") }, // TODO
closeBottomSheet = {
isVisible = false
expirationDate = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,45 +17,100 @@
*/
package com.infomaniak.swisstransfer.ui.screen.main.sent

import android.util.Log
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Surface
import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.*
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Modifier
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.infomaniak.swisstransfer.ui.components.NewTransferFab
import com.infomaniak.swisstransfer.ui.components.NewTransferFabType
import com.infomaniak.swisstransfer.ui.components.transfer.TransferExpiredBottomSheet
import com.infomaniak.swisstransfer.ui.components.transfer.TransferItemList
import com.infomaniak.swisstransfer.ui.previewparameter.transfersPreviewData
import com.infomaniak.swisstransfer.ui.screen.main.components.BrandTopAppBarScaffold
import com.infomaniak.swisstransfer.ui.screen.main.transfers.TransfersType
import com.infomaniak.swisstransfer.ui.screen.main.transfers.TransfersViewModel
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.isWindowSmall
import java.util.Date

@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()
var isVisible: Boolean by rememberSaveable { mutableStateOf(false) }
var expirationDate: Date? by rememberSaveable { mutableStateOf(null) }
var downloadsLimit: Int? by rememberSaveable { mutableStateOf(null) }

BrandTopAppBarScaffold(
floatingActionButton = {
if (windowAdaptiveInfo.isWindowSmall() && transfers.isNotEmpty()) {
if (windowAdaptiveInfo.isWindowSmall() && !areTransfersEmpty()) {
NewTransferFab(newTransferFabType = NewTransferFabType.BOTTOM_BAR)
}
},
) {
if (transfers.isEmpty()) {
if (areTransfersEmpty()) {
SentEmptyScreen()
} else {
SentListScreen(transfers)
TransferItemList(
modifier = Modifier.padding(Margin.Medium),
type = TransfersType.SENT,
transfers = transfersPreviewData, // TODO: Use real data
getSelectedTransferUuid = getSelectedTransferUuid,
onClick = { transfer ->
when {
transfer.expiresInDays < 0 -> {
isVisible = true
expirationDate = Date(transfer.expirationDateTimestamp)
}
transfer.downloadLeft == 0 -> {
isVisible = true
downloadsLimit = transfer.downloadLimit
}
else -> {
navigateToDetails(transfer.uuid)
}
}
}
)

TransferExpiredBottomSheet(
isVisible = { isVisible },
expirationDate = { expirationDate },
downloadsLimit = { downloadsLimit },
onDeleteTransferClicked = { Log.d("TODO", "Delete expired Transfer") }, // TODO
closeBottomSheet = {
isVisible = false
expirationDate = null
downloadsLimit = null
},
)
}
}
}
Expand All @@ -65,7 +120,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 @@ -30,27 +30,35 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
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(type: TransfersType) {
TwoPaneScaffold<String>(
listPane = { ListPane(navigator = this) },
listPane = { ListPane(type, 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(type: TransfersType, navigator: ThreePaneScaffoldNavigator<String>) {
when (type) {
TransfersType.SENT -> SentScreen(
navigateToDetails = { transferUuid -> navigator.navigateTo(ListDetailPaneScaffoldRole.Detail, transferUuid) },
getSelectedTransferUuid = { navigator.currentDestination?.content },
)
TransfersType.RECEIVED -> ReceivedScreen(
navigateToDetails = { transferUuid -> navigator.navigateTo(ListDetailPaneScaffoldRole.Detail, transferUuid) },
getSelectedTransferUuid = { navigator.currentDestination?.content },
)
}
}

@OptIn(ExperimentalMaterial3AdaptiveApi::class)
Expand All @@ -77,12 +85,17 @@ private fun NoSelectionEmptyState() {
}
}

enum class TransfersType {
SENT,
RECEIVED,
}

@PreviewAllWindows
@Composable
private fun Preview() {
SwissTransferTheme {
Surface(color = MaterialTheme.colorScheme.background) {
ReceivedScreenWrapper()
TransfersScreenWrapper(TransfersType.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 f334ac9

Please sign in to comment.