diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/MainApplication.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/MainApplication.kt index 926569f9b..f5bfb2e38 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/MainApplication.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/MainApplication.kt @@ -20,6 +20,7 @@ package com.infomaniak.swisstransfer.ui import android.app.Application import com.infomaniak.multiplatform_swisstransfer.SwissTransferInjection import com.infomaniak.swisstransfer.BuildConfig +import com.infomaniak.swisstransfer.ui.utils.AccountUtils import dagger.hilt.android.HiltAndroidApp import io.sentry.SentryEvent import io.sentry.SentryOptions @@ -40,7 +41,8 @@ class MainApplication : Application() { override fun onCreate() { super.onCreate() - globalCoroutineScope.launch { swissTransferInjection.loadDefaultAccount() } + + configureAccountUtils() SentryAndroid.init(this) { options: SentryAndroidOptions -> // Register the callback as an option @@ -50,4 +52,8 @@ class MainApplication : Application() { } } } + + private fun configureAccountUtils() { + globalCoroutineScope.launch { AccountUtils.init(swissTransferInjection) } + } } diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/BrandTopAppBar.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/BrandTopAppBar.kt index be9aebe95..c344ffc03 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/BrandTopAppBar.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/BrandTopAppBar.kt @@ -33,8 +33,7 @@ import com.infomaniak.swisstransfer.ui.images.illus.LogoInfomaniak import com.infomaniak.swisstransfer.ui.images.illus.LogoSwissTransfer import com.infomaniak.swisstransfer.ui.theme.Margin import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme -import com.infomaniak.swisstransfer.ui.utils.PreviewLargeWindow -import com.infomaniak.swisstransfer.ui.utils.PreviewSmallWindow +import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows @Composable @OptIn(ExperimentalMaterial3Api::class) @@ -58,8 +57,7 @@ fun BrandTopAppBar() { ) } -@PreviewSmallWindow -@PreviewLargeWindow +@PreviewAllWindows @Composable private fun BrandTopAppBarPreview() { SwissTransferTheme { diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/Buttons.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/Buttons.kt index 68da741e6..23dc5853c 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/Buttons.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/Buttons.kt @@ -22,7 +22,12 @@ import androidx.annotation.StringRes import androidx.compose.foundation.layout.* import androidx.compose.material3.* import androidx.compose.runtime.Composable +import androidx.compose.runtime.derivedStateOf +import androidx.compose.runtime.getValue +import androidx.compose.runtime.remember +import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.alpha import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.res.stringResource @@ -37,28 +42,60 @@ import com.infomaniak.swisstransfer.ui.theme.Dimens import com.infomaniak.swisstransfer.ui.theme.Margin import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme + +/** + * Specifying a progress has the priority over specifying showIndeterminateProgress + */ @Composable fun LargeButton( @StringRes titleRes: Int, modifier: Modifier = Modifier, style: ButtonType = ButtonType.PRIMARY, enabled: () -> Boolean = { true }, + showIndeterminateProgress: () -> Boolean = { false }, + progress: (() -> Float)? = null, onClick: () -> Unit, imageVector: ImageVector? = null, ) { - CoreButton(titleRes, modifier, ButtonSize.LARGE, style, enabled, onClick, imageVector) + CoreButton( + titleRes, + modifier, + ButtonSize.LARGE, + style, + enabled, + showIndeterminateProgress, + progress, + onClick, + imageVector, + ) } + +/** + * Specifying a progress has the priority over specifying showIndeterminateProgress + */ @Composable fun SmallButton( @StringRes titleRes: Int, modifier: Modifier = Modifier, style: ButtonType = ButtonType.PRIMARY, enabled: () -> Boolean = { true }, + showIndeterminateProgress: () -> Boolean = { false }, + progress: (() -> Float)? = null, onClick: () -> Unit, imageVector: ImageVector? = null, ) { - CoreButton(titleRes, modifier, ButtonSize.SMALL, style, enabled, onClick, imageVector) + CoreButton( + titleRes, + modifier, + ButtonSize.SMALL, + style, + enabled, + showIndeterminateProgress, + progress, + onClick, + imageVector, + ) } @Composable @@ -68,24 +105,69 @@ private fun CoreButton( buttonSize: ButtonSize, style: ButtonType, enabled: () -> Boolean, + showIndeterminateProgress: () -> Boolean, + progress: (() -> Float)?, onClick: () -> Unit, imageVector: ImageVector?, ) { + val isEnabled by remember(progress) { derivedStateOf { enabled() && !showIndeterminateProgress() && progress == null } } + val buttonColors = style.buttonColors() + Button( modifier = modifier.height(buttonSize.height), - colors = style.buttonColors(), + colors = buttonColors, shape = CustomShapes.medium, enabled = enabled(), onClick = onClick, ) { - imageVector?.let { - Icon(modifier = Modifier.size(Margin.Medium), imageVector = it, contentDescription = null) - Spacer(modifier = Modifier.width(Margin.Small)) + when { + progress != null -> { + val (progressColor, progressModifier) = getProgressSpecs(buttonColors) + KeepButtonSize(imageVector, titleRes) { + CircularProgressIndicator(modifier = progressModifier, color = progressColor, progress = progress) + } + } + showIndeterminateProgress() -> { + val (progressColor, progressModifier) = getProgressSpecs(buttonColors) + KeepButtonSize(imageVector, titleRes) { + CircularProgressIndicator(modifier = progressModifier, color = progressColor) + } + } + else -> { + ButtonTextContent(imageVector, titleRes) + } + } + } +} + +@Composable +fun KeepButtonSize(imageVector: ImageVector?, titleRes: Int, content: @Composable () -> Unit) { + Box(contentAlignment = Alignment.Center) { + Row(modifier = Modifier.alpha(0f)) { + ButtonTextContent(imageVector, titleRes) } - Text(text = stringResource(id = titleRes), style = SwissTransferTheme.typography.bodyMedium) + content() } } +@Composable +private fun ButtonTextContent(imageVector: ImageVector?, titleRes: Int) { + imageVector?.let { + Icon(modifier = Modifier.size(Margin.Medium), imageVector = it, contentDescription = null) + Spacer(modifier = Modifier.width(Margin.Small)) + } + Text(text = stringResource(id = titleRes), style = SwissTransferTheme.typography.bodyMedium) +} + +@Composable +private fun getProgressSpecs(buttonColors: ButtonColors): Pair { + val progressColor = buttonColors.disabledContentColor + val progressModifier = Modifier + .fillMaxHeight(0.8f) + .aspectRatio(1f) + return Pair(progressColor, progressModifier) +} + enum class ButtonType(val buttonColors: @Composable () -> ButtonColors) { PRIMARY({ ButtonDefaults.buttonColors( @@ -118,8 +200,8 @@ private enum class ButtonSize(val height: Dp) { SMALL(40.dp), } -@Preview(name = "Light") -@Preview(name = "Dark", uiMode = Configuration.UI_MODE_NIGHT_YES or Configuration.UI_MODE_TYPE_NORMAL) +@Preview(name = "Light", widthDp = 800) +@Preview(name = "Dark", widthDp = 800, uiMode = Configuration.UI_MODE_NIGHT_YES or Configuration.UI_MODE_TYPE_NORMAL) @Composable private fun LargeButtonPreview() { SwissTransferTheme { @@ -127,9 +209,27 @@ private fun LargeButtonPreview() { Column { ButtonType.entries.forEach { Row { - LargeButton(titleRes = R.string.appName, style = it, imageVector = AppIcons.Add, onClick = {}) + LargeButton(titleRes = R.string.appName, style = it, onClick = {}, imageVector = AppIcons.Add) + Spacer(modifier = Modifier.width(Margin.Small)) + LargeButton( + titleRes = R.string.appName, + style = it, + progress = { 0.3f }, + onClick = {}, + imageVector = AppIcons.Add + ) + Spacer(modifier = Modifier.width(Margin.Small)) + SmallButton(titleRes = R.string.appName, style = it, imageVector = AppIcons.Add, onClick = {}) + Spacer(modifier = Modifier.width(Margin.Small)) + SmallButton( + titleRes = R.string.appName, + style = it, + progress = { 0.3f }, + imageVector = AppIcons.Add, + onClick = {} + ) } Spacer(modifier = Modifier.height(Margin.Medium)) } diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/DoubleButtonCombo.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/DoubleButtonCombo.kt index ab3c363d8..f2372c508 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/DoubleButtonCombo.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/DoubleButtonCombo.kt @@ -22,7 +22,10 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp +import com.infomaniak.swisstransfer.R import com.infomaniak.swisstransfer.ui.theme.Margin +import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme +import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows private val WIDTH_LIMIT = 800.dp private val WIDTH_THRESHOLD = 500.dp @@ -92,10 +95,45 @@ private fun HorizontallyStackedButtons( @Composable private fun SingleButton(button: @Composable (Modifier) -> Unit) { - button( - Modifier - .fillMaxWidth() - .widthIn(WIDTH_LIMIT / 2) - .padding(bottom = Margin.Large, start = Margin.Medium, end = Margin.Medium), - ) + Box(Modifier.widthIn(max = WIDTH_LIMIT / 2)) { + button( + Modifier + .fillMaxWidth() + .padding(bottom = Margin.Large, start = Margin.Medium, end = Margin.Medium), + ) + } +} + +@PreviewAllWindows +@Composable +private fun DoubleButtonComboPreview() { + SwissTransferTheme { + Column { + DoubleButtonCombo( + topButton = { + LargeButton( + modifier = it, + titleRes = R.string.appName, + onClick = {}, + ) + }, + bottomButton = { + LargeButton( + modifier = it, + titleRes = R.string.appName, + onClick = {}, + ) + }, + ) + DoubleButtonCombo( + bottomButton = { + LargeButton( + modifier = it, + titleRes = R.string.appName, + onClick = {}, + ) + }, + ) + } + } } diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/FileItem.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/FileItem.kt index df680d0d3..e338afb5f 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/FileItem.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/FileItem.kt @@ -28,19 +28,10 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp -import androidx.core.net.toUri -import coil.compose.AsyncImage -import coil.request.ImageRequest -import com.infomaniak.library.filetypes.FileType -import com.infomaniak.swisstransfer.R -import com.infomaniak.swisstransfer.ui.images.AppImages -import com.infomaniak.swisstransfer.ui.images.icons.CrossThick import com.infomaniak.swisstransfer.ui.theme.CustomShapes -import com.infomaniak.swisstransfer.ui.theme.LocalIsDarkMode import com.infomaniak.swisstransfer.ui.theme.Margin import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme -import com.infomaniak.swisstransfer.ui.utils.PreviewLargeWindow -import com.infomaniak.swisstransfer.ui.utils.PreviewSmallWindow +import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows // TODO: Get the interface from the shared kmp code interface FileUiItem { @@ -136,8 +127,7 @@ private fun FileItemContent( } } -@PreviewSmallWindow -@PreviewLargeWindow +@PreviewAllWindows @Composable private fun FileItemPreview() { SwissTransferTheme { diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/FileItemList.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/FileItemList.kt index 8a7dbbbfd..35299de01 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/FileItemList.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/FileItemList.kt @@ -26,8 +26,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import com.infomaniak.swisstransfer.ui.theme.Margin import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme -import com.infomaniak.swisstransfer.ui.utils.PreviewLargeWindow -import com.infomaniak.swisstransfer.ui.utils.PreviewSmallWindow +import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows @Composable fun FileItemList( @@ -58,8 +57,7 @@ fun FileItemList( } } -@PreviewSmallWindow -@PreviewLargeWindow +@PreviewAllWindows @Composable private fun FileItemListPreview() { val files = listOf(object : FileUiItem { diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/SwissTransferTopAppBar.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/SwissTransferTopAppBar.kt index b6f18d2f0..f8106f1e9 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/SwissTransferTopAppBar.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/SwissTransferTopAppBar.kt @@ -29,8 +29,7 @@ import com.infomaniak.swisstransfer.ui.images.icons.Add import com.infomaniak.swisstransfer.ui.images.icons.ArrowLeft import com.infomaniak.swisstransfer.ui.images.icons.Cross import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme -import com.infomaniak.swisstransfer.ui.utils.PreviewLargeWindow -import com.infomaniak.swisstransfer.ui.utils.PreviewSmallWindow +import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows @Composable @OptIn(ExperimentalMaterial3Api::class) @@ -75,8 +74,7 @@ data class TopAppBarButton( } } -@PreviewSmallWindow -@PreviewLargeWindow +@PreviewAllWindows @Composable private fun SwissTransferTopAppBarPreview() { SwissTransferTheme { diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/MainScreen.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/MainScreen.kt index b45e46d88..389076787 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/MainScreen.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/MainScreen.kt @@ -28,8 +28,7 @@ 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.PreviewLargeWindow -import com.infomaniak.swisstransfer.ui.utils.PreviewSmallWindow +import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows @Composable fun MainScreen() { @@ -49,8 +48,7 @@ fun MainScreen() { ) } -@PreviewSmallWindow -@PreviewLargeWindow +@PreviewAllWindows @Composable private fun MainScreenPreview() { SwissTransferTheme { diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/received/ReceivedScreen.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/received/ReceivedScreen.kt index 46e2ea386..1a2f21a73 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/received/ReceivedScreen.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/received/ReceivedScreen.kt @@ -37,8 +37,7 @@ import com.infomaniak.swisstransfer.ui.screen.main.received.components.ReceivedE import com.infomaniak.swisstransfer.ui.screen.main.sent.SentViewModel import com.infomaniak.swisstransfer.ui.theme.Margin import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme -import com.infomaniak.swisstransfer.ui.utils.PreviewLargeWindow -import com.infomaniak.swisstransfer.ui.utils.PreviewSmallWindow +import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows @Composable fun ReceivedScreen( @@ -104,8 +103,7 @@ private fun ReceivedScreen( } } -@PreviewSmallWindow -@PreviewLargeWindow +@PreviewAllWindows @Composable private fun ReceivedScreenPreview() { SwissTransferTheme { diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/sent/SentEmptyScreen.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/sent/SentEmptyScreen.kt index dafa8336b..1d579916b 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/sent/SentEmptyScreen.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/sent/SentEmptyScreen.kt @@ -35,8 +35,7 @@ import com.infomaniak.swisstransfer.ui.images.illus.ArrowDownRightCurved import com.infomaniak.swisstransfer.ui.theme.Dimens import com.infomaniak.swisstransfer.ui.theme.Margin import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme -import com.infomaniak.swisstransfer.ui.utils.PreviewLargeWindow -import com.infomaniak.swisstransfer.ui.utils.PreviewSmallWindow +import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows @Composable fun SentEmptyScreen() { @@ -85,8 +84,7 @@ fun SentEmptyScreen() { } } -@PreviewSmallWindow -@PreviewLargeWindow +@PreviewAllWindows @Composable private fun SentEmptyScreenPreview() { SwissTransferTheme { diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/sent/SentListScreen.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/sent/SentListScreen.kt index 634e959dd..2ac1937b4 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/sent/SentListScreen.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/sent/SentListScreen.kt @@ -25,8 +25,7 @@ import com.infomaniak.swisstransfer.ui.components.FileItemList import com.infomaniak.swisstransfer.ui.components.FileUiItem import com.infomaniak.swisstransfer.ui.theme.Margin import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme -import com.infomaniak.swisstransfer.ui.utils.PreviewLargeWindow -import com.infomaniak.swisstransfer.ui.utils.PreviewSmallWindow +import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows @Composable fun SentListScreen(transfers: List) { @@ -60,8 +59,7 @@ fun SentListScreen(transfers: List) { ) } -@PreviewSmallWindow -@PreviewLargeWindow +@PreviewAllWindows @Composable private fun SentListScreenPreview() { SwissTransferTheme { diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/sent/SentScreen.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/sent/SentScreen.kt index 84a9f7b88..57adb8c33 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/sent/SentScreen.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/sent/SentScreen.kt @@ -27,8 +27,7 @@ import com.infomaniak.swisstransfer.ui.components.NewTransferFab import com.infomaniak.swisstransfer.ui.components.NewTransferFabType import com.infomaniak.swisstransfer.ui.screen.main.components.BrandTopAppBarScaffold import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme -import com.infomaniak.swisstransfer.ui.utils.PreviewLargeWindow -import com.infomaniak.swisstransfer.ui.utils.PreviewSmallWindow +import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows import com.infomaniak.swisstransfer.ui.utils.isWindowSmall @Composable @@ -61,8 +60,7 @@ private fun SentScreen(transfers: List?) { } } -@PreviewSmallWindow -@PreviewLargeWindow +@PreviewAllWindows @Composable private fun SentScreenPreview() { SwissTransferTheme { diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsDownloadsLimitScreen.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsDownloadsLimitScreen.kt index a5325f87f..68c42b695 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsDownloadsLimitScreen.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsDownloadsLimitScreen.kt @@ -25,7 +25,7 @@ import com.infomaniak.swisstransfer.R import com.infomaniak.swisstransfer.ui.screen.main.settings.components.OptionScaffold import com.infomaniak.swisstransfer.ui.screen.main.settings.components.SettingOption import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme -import com.infomaniak.swisstransfer.ui.utils.PreviewSmallWindow +import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows @Composable fun SettingsDownloadsLimitScreen( @@ -54,13 +54,13 @@ enum class DownloadLimitOption( ONE({ "1" }), } -@PreviewSmallWindow +@PreviewAllWindows @Composable private fun SettingsThemeScreenPreview() { SwissTransferTheme { Surface { SettingsDownloadsLimitScreen( - downloadLimit = DownloadLimit.TWOHUNDREDFIFTY, + downloadLimit = DownloadLimit.TWO_HUNDRED_FIFTY, navigateBack = {}, onDownloadLimitChange = {}, ) diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsEmailLanguageScreen.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsEmailLanguageScreen.kt index 68b2b944d..c6bd9cb82 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsEmailLanguageScreen.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsEmailLanguageScreen.kt @@ -26,7 +26,7 @@ import com.infomaniak.swisstransfer.R import com.infomaniak.swisstransfer.ui.screen.main.settings.components.OptionScaffold import com.infomaniak.swisstransfer.ui.screen.main.settings.components.SettingOption import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme -import com.infomaniak.swisstransfer.ui.utils.PreviewSmallWindow +import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows @Composable fun SettingsEmailLanguageScreen( @@ -56,7 +56,7 @@ enum class EmailLanguageOption( SPANISH({ stringResource(R.string.settingsEmailLanguageValueSpanish) }, imageVectorResId = R.drawable.flag_es), } -@PreviewSmallWindow +@PreviewAllWindows @Composable private fun SettingsThemeScreenPreview() { SwissTransferTheme { diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsScreen.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsScreen.kt index e91509901..70757eeae 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsScreen.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsScreen.kt @@ -47,7 +47,7 @@ import com.infomaniak.swisstransfer.ui.screen.main.settings.components.SettingTi import com.infomaniak.swisstransfer.ui.theme.Margin import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme import com.infomaniak.swisstransfer.ui.utils.GetSetCallbacks -import com.infomaniak.swisstransfer.ui.utils.PreviewSmallWindow +import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows @Composable fun SettingsScreen( @@ -184,7 +184,7 @@ enum class SettingsOptionScreens { DISCOVER_INFOMANIAK, SHARE_IDEAS, GIVE_FEEDBACK, } -@PreviewSmallWindow +@PreviewAllWindows @Composable private fun SettingsScreenPreview() { SwissTransferTheme { @@ -192,7 +192,7 @@ private fun SettingsScreenPreview() { SettingsScreen( theme = GetSetCallbacks(get = { Theme.SYSTEM }, set = {}), validityPeriod = GetSetCallbacks(get = { ValidityPeriod.THIRTY }, set = {}), - downloadLimit = GetSetCallbacks(get = { DownloadLimit.TWOHUNDREDFIFTY }, set = {}), + downloadLimit = GetSetCallbacks(get = { DownloadLimit.TWO_HUNDRED_FIFTY }, set = {}), emailLanguage = GetSetCallbacks(get = { EmailLanguage.ENGLISH }, set = {}), onItemClick = {}, getSelectedSetting = { null }, diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsScreenWrapper.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsScreenWrapper.kt index 56bf8b4ef..ebb8ed197 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsScreenWrapper.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsScreenWrapper.kt @@ -167,8 +167,7 @@ private fun NoSelectionEmptyState() { } } -@PreviewSmallWindow -@PreviewLargeWindow +@PreviewAllWindows @Composable private fun SettingsScreenWrapperPreview() { SwissTransferTheme { @@ -176,7 +175,7 @@ private fun SettingsScreenWrapperPreview() { SettingsScreenWrapper( theme = GetSetCallbacks(get = { Theme.SYSTEM }, set = {}), validityPeriod = GetSetCallbacks(get = { ValidityPeriod.THIRTY }, set = {}), - downloadLimit = GetSetCallbacks(get = { DownloadLimit.TWOHUNDREDFIFTY }, set = {}), + downloadLimit = GetSetCallbacks(get = { DownloadLimit.TWO_HUNDRED_FIFTY }, set = {}), emailLanguage = GetSetCallbacks(get = { EmailLanguage.ENGLISH }, set = {}), ) } diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsThemeScreen.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsThemeScreen.kt index 1ba15baf4..9289b2db0 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsThemeScreen.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsThemeScreen.kt @@ -30,7 +30,7 @@ import com.infomaniak.swisstransfer.ui.images.icons.CircleWhite import com.infomaniak.swisstransfer.ui.screen.main.settings.components.OptionScaffold import com.infomaniak.swisstransfer.ui.screen.main.settings.components.SettingOption import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme -import com.infomaniak.swisstransfer.ui.utils.PreviewSmallWindow +import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows @Composable fun SettingsThemeScreen( @@ -58,7 +58,7 @@ enum class ThemeOption( DARK({ stringResource(R.string.settingsOptionThemeDark) }, AppIcons.CircleBlack), } -@PreviewSmallWindow +@PreviewAllWindows @Composable private fun SettingsThemeScreenPreview() { SwissTransferTheme { diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsValidityPeriodScreen.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsValidityPeriodScreen.kt index 71a463ef9..07880b583 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsValidityPeriodScreen.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsValidityPeriodScreen.kt @@ -26,7 +26,7 @@ import com.infomaniak.swisstransfer.R import com.infomaniak.swisstransfer.ui.screen.main.settings.components.OptionScaffold import com.infomaniak.swisstransfer.ui.screen.main.settings.components.SettingOption import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme -import com.infomaniak.swisstransfer.ui.utils.PreviewSmallWindow +import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows @Composable fun SettingsValidityPeriodScreen( @@ -55,7 +55,7 @@ enum class ValidityPeriodOption( ONE({ pluralStringResource(R.plurals.settingsValidityPeriodValue, 1, 1) }), } -@PreviewSmallWindow +@PreviewAllWindows @Composable private fun SettingsThemeScreenPreview() { SwissTransferTheme { diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/components/OptionScaffold.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/components/OptionScaffold.kt index e9f8fcd33..defed04a6 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/components/OptionScaffold.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/components/OptionScaffold.kt @@ -33,8 +33,7 @@ import com.infomaniak.swisstransfer.ui.components.TopAppBarButton import com.infomaniak.swisstransfer.ui.screen.main.components.SmallWindowTopAppBarScaffold import com.infomaniak.swisstransfer.ui.screen.main.settings.ThemeOption import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme -import com.infomaniak.swisstransfer.ui.utils.PreviewLargeWindow -import com.infomaniak.swisstransfer.ui.utils.PreviewSmallWindow +import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows @Composable fun OptionScaffold( @@ -64,8 +63,7 @@ fun OptionScaffold( } } -@PreviewSmallWindow -@PreviewLargeWindow +@PreviewAllWindows @Composable private fun OptionScaffoldPreview() { SwissTransferTheme { diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/NewTransferScreen.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/NewTransferScreen.kt index 3b775e7ef..e12920249 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/NewTransferScreen.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/NewTransferScreen.kt @@ -20,8 +20,7 @@ package com.infomaniak.swisstransfer.ui.screen.newtransfer import androidx.compose.runtime.Composable import androidx.navigation.compose.rememberNavController import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme -import com.infomaniak.swisstransfer.ui.utils.PreviewLargeWindow -import com.infomaniak.swisstransfer.ui.utils.PreviewSmallWindow +import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows @Composable fun NewTransferScreen(closeActivity: () -> Unit) { @@ -29,8 +28,7 @@ fun NewTransferScreen(closeActivity: () -> Unit) { NewTransferNavHost(navController, closeActivity) } -@PreviewSmallWindow -@PreviewLargeWindow +@PreviewAllWindows @Composable private fun NewTransferPreview() { SwissTransferTheme { diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/ImportFilesScreen.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/ImportFilesScreen.kt index 5226798c3..308a3c6fe 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/ImportFilesScreen.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/ImportFilesScreen.kt @@ -34,8 +34,7 @@ import com.infomaniak.swisstransfer.ui.components.* import com.infomaniak.swisstransfer.ui.screen.newtransfer.NewTransferViewModel import com.infomaniak.swisstransfer.ui.theme.Margin import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme -import com.infomaniak.swisstransfer.ui.utils.PreviewLargeWindow -import com.infomaniak.swisstransfer.ui.utils.PreviewSmallWindow +import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows private const val TOTAL_FILE_SIZE: Long = 50_000_000_000L @@ -111,8 +110,7 @@ private fun getFormattedSizeWithUnits(usedSpace: Long, context: Context): String return Formatter.formatShortFileSize(context, spaceLeft) } -@PreviewSmallWindow -@PreviewLargeWindow +@PreviewAllWindows @Composable private fun ImportFilesScreenPreview() { SwissTransferTheme { diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/UploadSourceChoiceBottomSheet.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/UploadSourceChoiceBottomSheet.kt index 7c762f125..f250c329f 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/UploadSourceChoiceBottomSheet.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/UploadSourceChoiceBottomSheet.kt @@ -32,8 +32,7 @@ import com.infomaniak.swisstransfer.ui.images.icons.Folder import com.infomaniak.swisstransfer.ui.images.icons.PolaroidLandscape import com.infomaniak.swisstransfer.ui.theme.Margin import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme -import com.infomaniak.swisstransfer.ui.utils.PreviewLargeWindow -import com.infomaniak.swisstransfer.ui.utils.PreviewSmallWindow +import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows @Composable fun UploadSourceChoiceBottomSheet( @@ -79,8 +78,7 @@ fun UploadSourceChoiceBottomSheet( } } -@PreviewSmallWindow -@PreviewLargeWindow +@PreviewAllWindows @Composable private fun UploadSourceChoiceBottomSheetPreview() { SwissTransferTheme { @@ -88,7 +86,7 @@ private fun UploadSourceChoiceBottomSheetPreview() { UploadSourceChoiceBottomSheet( isBottomSheetVisible = { true }, onFilePickerClicked = {}, - closeBottomSheet = {} + closeBottomSheet = {}, ) } } diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/utils/AccountUtils.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/utils/AccountUtils.kt new file mode 100644 index 000000000..6f57db9e5 --- /dev/null +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/utils/AccountUtils.kt @@ -0,0 +1,29 @@ +/* + * 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 . + */ +package com.infomaniak.swisstransfer.ui.utils + +import com.infomaniak.multiplatform_swisstransfer.SwissTransferInjection + +object AccountUtils { + + private const val DEFAULT_USER_ID = 0 + + suspend fun init(swissTransferInjection: SwissTransferInjection) { + swissTransferInjection.accountManager.loadUser(userId = DEFAULT_USER_ID) + } +} diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/utils/MultiplePreview.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/utils/MultiplePreview.kt index 97dbec6b4..b7b22e5af 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/utils/MultiplePreview.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/utils/MultiplePreview.kt @@ -67,3 +67,8 @@ annotation class PreviewSmallWindow device = "spec:id=reference_tablet,shape=Normal,width=1280,height=800,unit=dp,dpi=240", ) annotation class PreviewLargeWindow + +// Small + Large +@PreviewSmallWindow +@PreviewLargeWindow +annotation class PreviewAllWindows diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index f28fca5bd..63238dcee 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -16,7 +16,7 @@ kotlin = "2.0.20" lifecycleRuntimeKtx = "2.8.6" navigation = "2.8.1" serialization = "1.7.1" -swisstransfer = "0.1.1" +swisstransfer = "0.3.0" sentry = "4.12.0" sentry-android = "7.15.0"