Skip to content

Commit

Permalink
refactor: Update SentScreen with LocalWindowAdptiveInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
sirambd committed Sep 25, 2024
1 parent de3b3a1 commit e5b4ba7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,23 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.adaptive.navigationsuite.NavigationSuiteType
import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.infomaniak.swisstransfer.ui.components.NewTransferFab
import com.infomaniak.swisstransfer.ui.components.NewTransferFabType
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
import com.infomaniak.swisstransfer.ui.utils.PreviewMobile
import com.infomaniak.swisstransfer.ui.utils.PreviewTablet
import com.infomaniak.swisstransfer.ui.utils.isWindowSmall

@Composable
fun SentListScreen(
navType: NavigationSuiteType,
) {
fun SentListScreen() {
val windowAdaptiveInfo = currentWindowAdaptiveInfo()

Scaffold(
floatingActionButton = {
if (navType == NavigationSuiteType.NavigationBar) NewTransferFab(newTransferFabType = NewTransferFabType.BOTTOM_BAR)
if (windowAdaptiveInfo.isWindowSmall()) NewTransferFab(newTransferFabType = NewTransferFabType.BOTTOM_BAR)
},
) { contentPadding ->
Text(
Expand All @@ -52,7 +53,7 @@ fun SentListScreen(
private fun SentListScreenPreview() {
SwissTransferTheme {
Surface {
SentListScreen(navType = NavigationSuiteType.NavigationRail)
SentListScreen()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@
package com.infomaniak.swisstransfer.ui.screen.main.sent

import androidx.compose.material3.Surface
import androidx.compose.material3.adaptive.navigationsuite.NavigationSuiteType
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.infomaniak.swisstransfer.ui.screen.main.LocalNavType
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
import com.infomaniak.swisstransfer.ui.utils.PreviewMobile
import com.infomaniak.swisstransfer.ui.utils.PreviewTablet
Expand All @@ -34,20 +32,17 @@ fun SentScreen(
sentViewModel: SentViewModel = hiltViewModel<SentViewModel>(),
) {
val transfers by sentViewModel.transfers.collectAsStateWithLifecycle()
SentScreen(
transfers = transfers,
navType = LocalNavType.current,
)
SentScreen(transfers)
}

@Composable
private fun SentScreen(transfers: List<Any>?, navType: NavigationSuiteType) {
private fun SentScreen(transfers: List<Any>?) {
if (transfers == null) return

if (transfers.isEmpty()) {
SentEmptyScreen()
} else {
SentListScreen(navType)
SentListScreen()
}
}

Expand All @@ -56,10 +51,7 @@ private fun SentScreen(transfers: List<Any>?, navType: NavigationSuiteType) {
private fun SentScreenMobilePreview() {
SwissTransferTheme {
Surface {
SentScreen(
transfers = emptyList(),
navType = NavigationSuiteType.NavigationBar,
)
SentScreen(transfers = emptyList())
}
}
}
Expand All @@ -69,10 +61,7 @@ private fun SentScreenMobilePreview() {
private fun SentScreenTabletPreview() {
SwissTransferTheme {
Surface {
SentScreen(
transfers = emptyList(),
navType = NavigationSuiteType.NavigationRail,
)
SentScreen(transfers = emptyList())
}
}
}

0 comments on commit e5b4ba7

Please sign in to comment.