Skip to content

Commit

Permalink
Hide TopBar when it's needed, depending on the display mode (phone/ta…
Browse files Browse the repository at this point in the history
…blet)
  • Loading branch information
KevinBoulongne committed Sep 20, 2024
1 parent bf719fb commit fab625d
Show file tree
Hide file tree
Showing 16 changed files with 192 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.Column
import com.infomaniak.swisstransfer.ui.components.BrandTobAppBar
import com.infomaniak.swisstransfer.ui.screen.main.MainScreen
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
import dagger.hilt.android.AndroidEntryPoint
Expand All @@ -35,10 +33,7 @@ class MainActivity : ComponentActivity() {
enableEdgeToEdge()
setContent {
SwissTransferTheme {
Column {
BrandTobAppBar()
MainScreen()
}
MainScreen()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import com.infomaniak.swisstransfer.ui.navigation.MainNavigation
import com.infomaniak.swisstransfer.ui.navigation.NavigationDestination.Companion.toDestination
import com.infomaniak.swisstransfer.ui.screen.main.components.MainScaffold
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
import com.infomaniak.swisstransfer.ui.utils.PreviewMobile
import com.infomaniak.swisstransfer.ui.utils.PreviewTablet
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Infomaniak SwissTransfer - Android
* Copyright (C) 2024 Infomaniak Network SA
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* 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.components

import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.material3.Scaffold
import androidx.compose.material3.adaptive.navigationsuite.NavigationSuiteType
import androidx.compose.runtime.Composable
import com.infomaniak.swisstransfer.ui.components.BrandTobAppBar

@Composable
fun BrandTobAppBarScaffold(
floatingActionButton: @Composable () -> Unit = {},
content: @Composable (PaddingValues) -> Unit,
) {
Scaffold(
topBar = { if (LocalNavType.current == NavigationSuiteType.NavigationBar) BrandTobAppBar() },
floatingActionButton = floatingActionButton,
) { contentPadding ->
content(contentPadding)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Infomaniak SwissTransfer - Android
* Copyright (C) 2024 Infomaniak Network SA
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* 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.components

import androidx.annotation.StringRes
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.material3.Scaffold
import androidx.compose.material3.adaptive.navigationsuite.NavigationSuiteType
import androidx.compose.runtime.Composable
import com.infomaniak.swisstransfer.ui.components.SwissTransferTobAppBar
import com.infomaniak.swisstransfer.ui.components.TopAppBarButton

@Composable
fun DetailTobAppBarScaffold(
@StringRes titleRes: Int,
navigateBack: (() -> Unit)?,
content: @Composable (PaddingValues) -> Unit,
) {
Scaffold(
topBar = {
val navigationMenu = if (LocalNavType.current == NavigationSuiteType.NavigationBar) {
TopAppBarButton.backButton(navigateBack ?: {})
} else {
null
}
SwissTransferTobAppBar(titleRes, navigationMenu)
},
) { contentPadding ->
content(contentPadding)
}
}
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
package com.infomaniak.swisstransfer.ui.screen.main.components

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand All @@ -27,9 +27,9 @@ import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.navigation.NavGraph.Companion.findStartDestination
import androidx.navigation.NavHostController
import com.infomaniak.swisstransfer.ui.components.BrandTobAppBar
import com.infomaniak.swisstransfer.ui.navigation.MainNavigation
import com.infomaniak.swisstransfer.ui.navigation.NavigationItem
import com.infomaniak.swisstransfer.ui.screen.main.components.AppNavigationSuiteScaffold
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
import com.infomaniak.swisstransfer.ui.utils.PreviewMobile
import com.infomaniak.swisstransfer.ui.utils.PreviewTablet
Expand Down Expand Up @@ -57,13 +57,16 @@ private fun MainScaffold(
navigateToSelectedItem: (MainNavigation) -> Unit,
content: @Composable () -> Unit,
) {
AppNavigationSuiteScaffold(navType, NavigationItem.entries, currentDestination, navigateToSelectedItem) {
if (navType == NavigationSuiteType.None) {
content()
} else {
Column {
Box(modifier = Modifier.weight(1.0f)) { content() }
HorizontalDivider()
Column {
if (navType == NavigationSuiteType.NavigationRail) BrandTobAppBar()
AppNavigationSuiteScaffold(navType, NavigationItem.entries, currentDestination, navigateToSelectedItem) {
if (navType == NavigationSuiteType.None) {
content()
} else {
Column {
Box(modifier = Modifier.weight(1.0f)) { content() }
HorizontalDivider()
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@
package com.infomaniak.swisstransfer.ui.screen.main.received

import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.infomaniak.swisstransfer.R
import com.infomaniak.swisstransfer.ui.components.EmptyState
import com.infomaniak.swisstransfer.ui.images.AppImages.AppIllus
import com.infomaniak.swisstransfer.ui.images.illus.MascotSearching
import com.infomaniak.swisstransfer.ui.screen.main.components.BrandTobAppBarScaffold
import com.infomaniak.swisstransfer.ui.screen.main.received.components.ReceivedEmptyFab
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
import com.infomaniak.swisstransfer.ui.utils.PreviewMobile
import com.infomaniak.swisstransfer.ui.utils.PreviewTablet

@Composable
fun ReceivedScreen(navigateToDetails: (transferId: Int) -> Unit) {
Scaffold(
BrandTobAppBarScaffold(
floatingActionButton = { ReceivedEmptyFab() },
) { contentPadding ->
EmptyState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package com.infomaniak.swisstransfer.ui.screen.main.sent

import androidx.compose.foundation.layout.*
import androidx.compose.material3.Icon
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
Expand All @@ -40,52 +39,48 @@ import com.infomaniak.swisstransfer.ui.utils.PreviewMobile
import com.infomaniak.swisstransfer.ui.utils.PreviewTablet

@Composable
fun SentEmptyScreen() {
Scaffold { contentPadding ->
Column(
modifier = Modifier
.fillMaxSize()
.padding(contentPadding),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
) {
val maxWidth = Dimens.DescriptionWidth
Text(
modifier = Modifier.widthIn(max = maxWidth),
text = stringResource(id = R.string.sentEmptyTitle),
style = SwissTransferTheme.typography.specificMedium32,
textAlign = TextAlign.Center,
fun SentEmptyScreen(modifier: Modifier) {
Column(
modifier = modifier.fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
) {
val maxWidth = Dimens.DescriptionWidth
Text(
modifier = Modifier.widthIn(max = maxWidth),
text = stringResource(id = R.string.sentEmptyTitle),
style = SwissTransferTheme.typography.specificMedium32,
textAlign = TextAlign.Center,
)
Spacer(modifier = Modifier.height(Margin.Medium))
Text(
modifier = Modifier.widthIn(max = maxWidth),
text = stringResource(id = R.string.firstTransferDescription),
style = SwissTransferTheme.typography.bodyRegular,
color = SwissTransferTheme.colors.secondaryTextColor,
)
Spacer(modifier = Modifier.height(Margin.Medium))
ConstraintLayout {
val (icon, fab) = createRefs()

Icon(
modifier = Modifier
.constrainAs(icon) {
top.linkTo(parent.top)
end.linkTo(fab.start, Margin.Small)
},
imageVector = AppImages.AppIllus.ArrowDownRightCurved,
contentDescription = null,
)
Spacer(modifier = Modifier.height(Margin.Medium))
Text(
modifier = Modifier.widthIn(max = maxWidth),
text = stringResource(id = R.string.firstTransferDescription),
style = SwissTransferTheme.typography.bodyRegular,
color = SwissTransferTheme.colors.secondaryTextColor,
NewTransferFab(
modifier = Modifier
.constrainAs(fab) {
start.linkTo(parent.start)
end.linkTo(parent.end)
top.linkTo(parent.top, Margin.Large)
},
newTransferFabType = NewTransferFabType.EMPTY_STATE,
)
Spacer(modifier = Modifier.height(Margin.Medium))
ConstraintLayout {
val (icon, fab) = createRefs()

Icon(
modifier = Modifier
.constrainAs(icon) {
top.linkTo(parent.top)
end.linkTo(fab.start, Margin.Small)
},
imageVector = AppImages.AppIllus.ArrowDownRightCurved,
contentDescription = null,
)
NewTransferFab(
modifier = Modifier
.constrainAs(fab) {
start.linkTo(parent.start)
end.linkTo(parent.end)
top.linkTo(parent.top, Margin.Large)
},
newTransferFabType = NewTransferFabType.EMPTY_STATE,
)
}
}
}
}
Expand All @@ -96,7 +91,7 @@ fun SentEmptyScreen() {
private fun SentEmptyScreenPreview() {
SwissTransferTheme {
Surface {
SentEmptyScreen()
SentEmptyScreen(modifier = Modifier)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,35 @@
*/
package com.infomaniak.swisstransfer.ui.screen.main.sent

import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Scaffold
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.adaptive.navigationsuite.NavigationSuiteType
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 java.util.UUID

@Composable
fun SentListScreen(
navType: NavigationSuiteType,
modifier: Modifier = Modifier,
transfers: List<Any>,
) {
Scaffold(
floatingActionButton = {
if (navType == NavigationSuiteType.NavigationBar) NewTransferFab(newTransferFabType = NewTransferFabType.BOTTOM_BAR)
},
) { contentPadding ->
Text(
text = "Sent screen",
modifier = Modifier.padding(contentPadding),
)
LazyColumn(modifier) {
items(items = transfers, key = { UUID.randomUUID() }) {
Text(text = "Sent screen")
}
}
}

@PreviewMobile
@PreviewTablet
@Composable
private fun SentListScreenPreview() {
SwissTransferTheme {
Surface {
SentListScreen(navType = NavigationSuiteType.NavigationRail)
SentListScreen(transfers = listOf(Any()))
}
}
}
Loading

0 comments on commit fab625d

Please sign in to comment.