From 9525ffbe9638043c4204d91ef471924a55647739 Mon Sep 17 00:00:00 2001 From: Abdourahamane Boinaidi Date: Wed, 24 Jul 2024 14:38:36 +0200 Subject: [PATCH 1/4] Add custom Mobile and Tablet multiple previews --- .../swisstransfer/ui/utils/MultiplePreview.kt | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 app/src/main/java/com/infomaniak/swisstransfer/ui/utils/MultiplePreview.kt 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 new file mode 100644 index 000000000..4c3b23105 --- /dev/null +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/utils/MultiplePreview.kt @@ -0,0 +1,70 @@ +/* + * 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 android.content.res.Configuration +import androidx.compose.ui.tooling.preview.Preview + +// Mobile +@Preview( + name = "(1) Mobile portrait light", + group = "Mobile", +) +@Preview( + name = "(2) Mobile portrait dark", + group = "Mobile", + uiMode = Configuration.UI_MODE_NIGHT_YES or Configuration.UI_MODE_TYPE_NORMAL, +) +@Preview( + name = "(3) Mobile landscape light", + group = "Mobile", + device = "spec:parent=pixel_5,orientation=landscape", +) +@Preview( + name = "(4) Mobile landscape dark", + group = "Mobile", + uiMode = Configuration.UI_MODE_NIGHT_YES or Configuration.UI_MODE_TYPE_NORMAL, + device = "spec:parent=pixel_5,orientation=landscape", +) +annotation class PreviewMobile + +// Tablet +@Preview( + name = "(1) lightMode portrait", + group = "Tablet", + device = "spec:width=1280dp,height=800dp,dpi=240,orientation=portrait", +) +@Preview( + name = "(2) darkMode portrait", + group = "Tablet", + uiMode = Configuration.UI_MODE_NIGHT_YES or Configuration.UI_MODE_TYPE_NORMAL, + device = "spec:width=1280dp,height=800dp,dpi=240,orientation=portrait", +) +@Preview( + name = "(3) lightMode landscape", + group = "Tablet", + device = "spec:id=reference_tablet,shape=Normal,width=1280,height=800,unit=dp,dpi=240", +) +@Preview( + name = "(4) darkMode landscape", + group = "Tablet", + uiMode = Configuration.UI_MODE_NIGHT_YES or Configuration.UI_MODE_TYPE_NORMAL, + device = "spec:id=reference_tablet,shape=Normal,width=1280,height=800,unit=dp,dpi=240", +) +annotation class PreviewTablet From 8d13001420b05a063e45d658a81292fca9a3f56b Mon Sep 17 00:00:00 2001 From: Abdourahamane Boinaidi Date: Wed, 24 Jul 2024 14:43:04 +0200 Subject: [PATCH 2/4] Update MainScreen with Multiple previews --- .../ui/screen/main/MainScreen.kt | 24 ++++--------------- 1 file changed, 4 insertions(+), 20 deletions(-) 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 eb92ddd2d..5d38e8d87 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 @@ -18,18 +18,18 @@ package com.infomaniak.swisstransfer.ui.screen.main -import android.content.res.Configuration import androidx.compose.runtime.Composable import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.getValue import androidx.compose.runtime.remember -import androidx.compose.ui.tooling.preview.Preview import androidx.navigation.compose.currentBackStackEntryAsState import androidx.navigation.compose.rememberNavController import com.infomaniak.swisstransfer.ui.navigation.MainNavigation import com.infomaniak.swisstransfer.ui.navigation.MainNavigation.SentDestination import com.infomaniak.swisstransfer.ui.navigation.NavigationDestination.Companion.toDestination import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme +import com.infomaniak.swisstransfer.ui.utils.PreviewMobile +import com.infomaniak.swisstransfer.ui.utils.PreviewTablet @Composable fun MainScreen() { @@ -49,27 +49,11 @@ fun MainScreen() { } } -@Preview(name = "LightMode") -@Preview(name = "DarkMode", uiMode = Configuration.UI_MODE_NIGHT_YES or Configuration.UI_MODE_TYPE_NORMAL) +@PreviewMobile +@PreviewTablet @Composable private fun MainScreenPreview() { SwissTransferTheme { MainScreen() } } - -@Preview(device = "spec:parent=pixel_8_pro,orientation=landscape") -@Composable -private fun MainScreenPortraitPreview() { - SwissTransferTheme { - MainScreen() - } -} - -@Preview(device = "spec:id=reference_tablet,shape=Normal,width=1280,height=800,unit=dp,dpi=240") -@Composable -private fun MainScreenTabletPreview() { - SwissTransferTheme { - MainScreen() - } -} From 803b2f2edf91cd922a3bff243af6c411870819a9 Mon Sep 17 00:00:00 2001 From: Abdourahamane Boinaidi Date: Wed, 24 Jul 2024 14:54:39 +0200 Subject: [PATCH 3/4] Refactor Tablet annotation --- .../infomaniak/swisstransfer/ui/utils/MultiplePreview.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 4c3b23105..f724b06c1 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 @@ -46,23 +46,23 @@ annotation class PreviewMobile // Tablet @Preview( - name = "(1) lightMode portrait", + name = "(1) Tablet portrait light", group = "Tablet", device = "spec:width=1280dp,height=800dp,dpi=240,orientation=portrait", ) @Preview( - name = "(2) darkMode portrait", + name = "(2) Tablet portrait dark", group = "Tablet", uiMode = Configuration.UI_MODE_NIGHT_YES or Configuration.UI_MODE_TYPE_NORMAL, device = "spec:width=1280dp,height=800dp,dpi=240,orientation=portrait", ) @Preview( - name = "(3) lightMode landscape", + name = "(3) Tablet landscape light", group = "Tablet", device = "spec:id=reference_tablet,shape=Normal,width=1280,height=800,unit=dp,dpi=240", ) @Preview( - name = "(4) darkMode landscape", + name = "(4) Tablet landscape dark", group = "Tablet", uiMode = Configuration.UI_MODE_NIGHT_YES or Configuration.UI_MODE_TYPE_NORMAL, device = "spec:id=reference_tablet,shape=Normal,width=1280,height=800,unit=dp,dpi=240", From ca40dbed2486284227527dca183a90ac11ab0471 Mon Sep 17 00:00:00 2001 From: Abdourahamane Boinaidi Date: Thu, 25 Jul 2024 10:08:12 +0200 Subject: [PATCH 4/4] update Tablet preview --- .../com/infomaniak/swisstransfer/ui/utils/MultiplePreview.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 f724b06c1..b92316085 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 @@ -48,13 +48,13 @@ annotation class PreviewMobile @Preview( name = "(1) Tablet portrait light", group = "Tablet", - device = "spec:width=1280dp,height=800dp,dpi=240,orientation=portrait", + device = "spec:id=reference_tablet,shape=Normal,width=1280,height=800,unit=dp,dpi=240", ) @Preview( name = "(2) Tablet portrait dark", group = "Tablet", uiMode = Configuration.UI_MODE_NIGHT_YES or Configuration.UI_MODE_TYPE_NORMAL, - device = "spec:width=1280dp,height=800dp,dpi=240,orientation=portrait", + device = "spec:id=reference_tablet,shape=Normal,width=1280,height=800,unit=dp,dpi=240", ) @Preview( name = "(3) Tablet landscape light",