From 9d129baa1f4c355559e8a6f6c1f251f8cd548fc3 Mon Sep 17 00:00:00 2001 From: Kevin Boulongne Date: Fri, 1 Nov 2024 09:01:46 +0100 Subject: [PATCH] refactor: Make Previews great again! --- .../swisstransfer/ui/components/FileItem.kt | 6 +- .../ui/components/FileItemList.kt | 6 +- .../ui/components/SwissTransferTopAppBar.kt | 6 +- .../transfer/TransferFilePreview.kt | 79 ++++++------- .../ui/components/transfer/TransferItem.kt | 73 ++---------- .../components/transfer/TransferItemList.kt | 102 ++-------------- .../ui/previewparameter/ListPreviewData.kt | 111 ++++++++++++++++++ ...ovider.kt => PreviewParameterProviders.kt} | 31 +---- .../ui/screen/main/received/ReceivedScreen.kt | 95 +-------------- .../ui/screen/main/sent/SentListScreen.kt | 37 ++---- .../transferdetails/TransferDetailsScreen.kt | 66 +---------- 11 files changed, 193 insertions(+), 419 deletions(-) create mode 100644 app/src/main/java/com/infomaniak/swisstransfer/ui/previewparameter/ListPreviewData.kt rename app/src/main/java/com/infomaniak/swisstransfer/ui/previewparameter/{FileUiListPreviewParameterProvider.kt => PreviewParameterProviders.kt} (52%) 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 934ca3887..1ffa23d60 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 @@ -17,6 +17,7 @@ */ package com.infomaniak.swisstransfer.ui.components +import android.content.res.Configuration import androidx.compose.foundation.BorderStroke import androidx.compose.foundation.background import androidx.compose.foundation.layout.* @@ -26,6 +27,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.unit.dp import com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui.FileUi @@ -35,7 +37,6 @@ 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.HumanReadableSizeUtils -import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows @Composable fun FileItem( @@ -122,7 +123,8 @@ private fun FileItemContent( } } -@PreviewAllWindows +@Preview(name = "Light") +@Preview(name = "Dark", uiMode = Configuration.UI_MODE_NIGHT_YES or Configuration.UI_MODE_TYPE_NORMAL) @Composable private fun FileItemPreview(@PreviewParameter(FileUiListPreviewParameter::class) files: List) { 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 8fff79a9d..583e0fcc2 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 @@ -17,19 +17,20 @@ */ package com.infomaniak.swisstransfer.ui.components +import android.content.res.Configuration import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.height import androidx.compose.foundation.lazy.grid.* import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier +import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.unit.dp import com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui.FileUi import com.infomaniak.swisstransfer.ui.previewparameter.FileUiListPreviewParameter import com.infomaniak.swisstransfer.ui.theme.Margin import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme -import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows @Composable fun FileItemList( @@ -74,7 +75,8 @@ fun FileItemList( } } -@PreviewAllWindows +@Preview(name = "Light") +@Preview(name = "Dark", uiMode = Configuration.UI_MODE_NIGHT_YES or Configuration.UI_MODE_TYPE_NORMAL) @Composable private fun FileItemListPreview(@PreviewParameter(FileUiListPreviewParameter::class) files: List) { SwissTransferTheme { 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 7e8a0e79e..0619bfd9f 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 @@ -17,19 +17,20 @@ */ package com.infomaniak.swisstransfer.ui.components +import android.content.res.Configuration import androidx.annotation.StringRes import androidx.compose.material3.* import androidx.compose.runtime.Composable import androidx.compose.runtime.Immutable import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.res.stringResource +import androidx.compose.ui.tooling.preview.Preview import com.infomaniak.swisstransfer.R import com.infomaniak.swisstransfer.ui.images.AppImages.AppIcons 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.PreviewAllWindows @Composable fun SwissTransferTopAppBar( @@ -83,7 +84,8 @@ data class TopAppBarButton( } } -@PreviewAllWindows +@Preview(name = "Light") +@Preview(name = "Dark", uiMode = Configuration.UI_MODE_NIGHT_YES or Configuration.UI_MODE_TYPE_NORMAL) @Composable private fun SwissTransferTopAppBarPreview() { SwissTransferTheme { diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/transfer/TransferFilePreview.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/transfer/TransferFilePreview.kt index 491be0af3..0aeb11f0d 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/transfer/TransferFilePreview.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/transfer/TransferFilePreview.kt @@ -17,28 +17,45 @@ */ package com.infomaniak.swisstransfer.ui.components.transfer +import android.content.res.Configuration import androidx.compose.foundation.background -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.* +import androidx.compose.material3.Card +import androidx.compose.material3.CardDefaults import androidx.compose.material3.Surface import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.tooling.preview.PreviewParameter import com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui.FileUi import com.infomaniak.swisstransfer.ui.components.SmallFileItem import com.infomaniak.swisstransfer.ui.components.SmallFileTileSize +import com.infomaniak.swisstransfer.ui.previewparameter.FileUiListPreviewParameter import com.infomaniak.swisstransfer.ui.theme.CustomShapes import com.infomaniak.swisstransfer.ui.theme.Margin import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme -import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows @Composable fun TransferFilePreview(file: FileUi? = null, remainingFilesCount: Int? = null) { Row { - if (file != null) { + if (file == null) { + Box( + contentAlignment = Alignment.Center, + modifier = Modifier + .size(Margin.Giant) + .clip(CustomShapes.SMALL) + .background(SwissTransferTheme.colors.transferFilePreviewOverflow), + ) { + Text( + text = "+$remainingFilesCount", + color = SwissTransferTheme.colors.onTransferFilePreviewOverflow, + style = SwissTransferTheme.typography.bodyRegular, + ) + } + } else { // TODO: Temporary code to be able to test the view, while waiting real Transfers data // AsyncImage( // model = ImageRequest.Builder(LocalContext.current) @@ -54,50 +71,28 @@ fun TransferFilePreview(file: FileUi? = null, remainingFilesCount: Int? = null) // .background(SwissTransferTheme.colors.transferFilePreviewOverflow), // ) SmallFileItem(file = file, smallFileTileSize = SmallFileTileSize.SMALL) - } else { - Box( - contentAlignment = Alignment.Center, - modifier = Modifier - .size(Margin.Giant) - .clip(CustomShapes.SMALL) - .background(SwissTransferTheme.colors.transferFilePreviewOverflow), - ) { - Text( - text = "+$remainingFilesCount", - color = SwissTransferTheme.colors.onTransferFilePreviewOverflow, - style = SwissTransferTheme.typography.bodyRegular, - ) - } } } } -@PreviewAllWindows +@Preview(name = "Light") +@Preview(name = "Dark", uiMode = Configuration.UI_MODE_NIGHT_YES or Configuration.UI_MODE_TYPE_NORMAL) @Composable -private fun Preview() { +private fun Preview(@PreviewParameter(FileUiListPreviewParameter::class) files: List) { SwissTransferTheme { Surface { - Row { - TransferFilePreview( - file = FileUi( - fileName = "The 5-Step Guide to Not Breaking Your Code.txt", - uid = "The 5-Step Guide to Not Breaking Your Code.txt", - fileSize = 57_689_032L, - mimeType = null, - localPath = "", - ), - ) - TransferFilePreview( - file = - FileUi( - fileName = "Introduction to Turning It Off and On Again.pptx", - uid = "Introduction to Turning It Off and On Again.pptx", - fileSize = 89_723_143L, - mimeType = null, - localPath = "", - ), - ) - TransferFilePreview(remainingFilesCount = 42) + Card( + shape = CustomShapes.NONE, + colors = CardDefaults.cardColors(containerColor = SwissTransferTheme.materialColors.surfaceContainerHighest), + ) { + Row( + modifier = Modifier.padding(Margin.Mini), + horizontalArrangement = Arrangement.spacedBy(Margin.Mini), + ) { + TransferFilePreview(file = files[0]) + TransferFilePreview(file = files[1]) + TransferFilePreview(remainingFilesCount = 42) + } } } } diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/transfer/TransferItem.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/transfer/TransferItem.kt index 0d19ac8f5..d2f1ac0d3 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/transfer/TransferItem.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/transfer/TransferItem.kt @@ -17,6 +17,7 @@ */ package com.infomaniak.swisstransfer.ui.components.transfer +import android.content.res.Configuration import androidx.compose.foundation.layout.* import androidx.compose.material3.* import androidx.compose.runtime.Composable @@ -25,23 +26,22 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.tooling.preview.PreviewParameter import com.infomaniak.core2.FORMAT_DATE_SIMPLE import com.infomaniak.core2.FORMAT_DATE_TITLE import com.infomaniak.core2.format -import com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui.FileUi import com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui.TransferUi import com.infomaniak.swisstransfer.R import com.infomaniak.swisstransfer.ui.components.TextDotText import com.infomaniak.swisstransfer.ui.images.AppImages.AppIcons import com.infomaniak.swisstransfer.ui.images.icons.ChevronRightThick +import com.infomaniak.swisstransfer.ui.previewparameter.TransferUiListPreviewParameter import com.infomaniak.swisstransfer.ui.theme.CustomShapes import com.infomaniak.swisstransfer.ui.theme.Margin import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme import com.infomaniak.swisstransfer.ui.utils.HumanReadableSizeUtils -import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows -import java.util.Calendar import java.util.Date -import java.util.UUID @OptIn(ExperimentalLayoutApi::class) @Composable @@ -116,70 +116,13 @@ fun TransferItem(transfer: TransferUi, onClick: () -> Unit) { } } -@PreviewAllWindows +@Preview(name = "Light") +@Preview(name = "Dark", uiMode = Configuration.UI_MODE_NIGHT_YES or Configuration.UI_MODE_TYPE_NORMAL) @Composable -private fun Preview() { +private fun Preview(@PreviewParameter(TransferUiListPreviewParameter::class) transfers: List) { SwissTransferTheme { Surface { - TransferItem( - transfer = TransferUi( - uuid = UUID.randomUUID().toString(), - createdDateTimestamp = Date().time - 30L * 86_400_000L, - expirationDateTimestamp = Calendar.getInstance().apply { - time = Date() - set(Calendar.DATE, get(Calendar.DATE) + 1) - }.time.time, - sizeUploaded = 57_689_032L, - downloadLimit = 10, - downloadLeft = 8, - message = "Coucou c'est moi le message de description du transfert.", - files = listOf( - FileUi( - uid = UUID.randomUUID().toString(), - fileName = "The 5-Step Guide to Not Breaking Your Code (1).txt", - fileSize = 57_689_032L, - mimeType = null, - localPath = null, - ), - FileUi( - uid = UUID.randomUUID().toString(), - fileName = "Introduction to Turning It Off and On Again (1).pptx", - fileSize = 89_723_143L, - mimeType = null, - localPath = null, - ), - FileUi( - uid = UUID.randomUUID().toString(), - fileName = "Learning to Copy and Paste: A Complete Guide (1).docx", - fileSize = 237_866_728L, - mimeType = null, - localPath = null, - ), - FileUi( - uid = UUID.randomUUID().toString(), - fileName = "The 5-Step Guide to Not Breaking Your Code (2).txt", - fileSize = 57_689_032L, - mimeType = null, - localPath = null, - ), - FileUi( - uid = UUID.randomUUID().toString(), - fileName = "Introduction to Turning It Off and On Again (2).pptx", - fileSize = 89_723_143L, - mimeType = null, - localPath = null, - ), - FileUi( - uid = UUID.randomUUID().toString(), - fileName = "Learning to Copy and Paste: A Complete Guide (2).docx", - fileSize = 237_866_728L, - mimeType = null, - localPath = null, - ), - ), - ), - onClick = {}, - ) + TransferItem(transfer = transfers.first(), onClick = {}) } } } diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/transfer/TransferItemList.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/transfer/TransferItemList.kt index 8b5bb60bb..f42a4c505 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/transfer/TransferItemList.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/transfer/TransferItemList.kt @@ -17,6 +17,7 @@ */ package com.infomaniak.swisstransfer.ui.components.transfer +import android.content.res.Configuration import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.height @@ -26,15 +27,13 @@ import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource -import com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui.FileUi +import androidx.compose.ui.tooling.preview.Preview +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.theme.Margin import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme -import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows -import java.util.Calendar -import java.util.Date -import java.util.UUID @Composable fun TransferItemList( @@ -67,97 +66,10 @@ fun TransferItemList( } } -@PreviewAllWindows +@Preview(name = "Light") +@Preview(name = "Dark", uiMode = Configuration.UI_MODE_NIGHT_YES or Configuration.UI_MODE_TYPE_NORMAL) @Composable -private fun Preview() { - - val files = listOf( - FileUi( - uid = UUID.randomUUID().toString(), - fileName = "The 5-Step Guide to Not Breaking Your Code (1).txt", - fileSize = 57_689_032L, - mimeType = null, - localPath = null, - ), - FileUi( - uid = UUID.randomUUID().toString(), - fileName = "Introduction to Turning It Off and On Again (1).pptx", - fileSize = 89_723_143L, - mimeType = null, - localPath = null, - ), - FileUi( - uid = UUID.randomUUID().toString(), - fileName = "Learning to Copy and Paste: A Complete Guide (1).docx", - fileSize = 237_866_728L, - mimeType = null, - localPath = null, - ), - FileUi( - uid = UUID.randomUUID().toString(), - fileName = "The 5-Step Guide to Not Breaking Your Code (2).txt", - fileSize = 57_689_032L, - mimeType = null, - localPath = null, - ), - FileUi( - uid = UUID.randomUUID().toString(), - fileName = "Introduction to Turning It Off and On Again (2).pptx", - fileSize = 89_723_143L, - mimeType = null, - localPath = null, - ), - FileUi( - uid = UUID.randomUUID().toString(), - fileName = "Learning to Copy and Paste: A Complete Guide (2).docx", - fileSize = 237_866_728L, - mimeType = null, - localPath = null, - ), - ) - - val transfers = listOf( - TransferUi( - uuid = UUID.randomUUID().toString(), - createdDateTimestamp = Date().time - 30L * 86_400_000L, - expirationDateTimestamp = Calendar.getInstance().apply { - time = Date() - set(Calendar.DATE, get(Calendar.DATE) + 1) - }.time.time, - sizeUploaded = 57_689_032L, - downloadLimit = 10, - downloadLeft = 8, - message = "Coucou c'est moi le message de description du transfert.", - files = files, - ), - TransferUi( - uuid = UUID.randomUUID().toString(), - createdDateTimestamp = Date().time - 5L * 86_400_000L, - expirationDateTimestamp = Calendar.getInstance().apply { - time = Date() - set(Calendar.DATE, get(Calendar.DATE) + 4) - }.time.time, - sizeUploaded = 89_723_143L, - downloadLimit = 2, - downloadLeft = 2, - message = null, - files = files, - ), - TransferUi( - uuid = UUID.randomUUID().toString(), - createdDateTimestamp = Date().time - 0.5f.toLong() * 86_400_000L, - expirationDateTimestamp = Calendar.getInstance().apply { - time = Date() - set(Calendar.DATE, get(Calendar.DATE) + 7) - }.time.time, - sizeUploaded = 237_866_728L, - downloadLimit = 420_069, - downloadLeft = 402_690, - message = "3ème transfert. RAS.", - files = files, - ), - ) - +private fun Preview(@PreviewParameter(TransferUiListPreviewParameter::class) transfers: List) { SwissTransferTheme { Surface { TransferItemList(transfers = transfers, onClick = {}) diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/previewparameter/ListPreviewData.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/previewparameter/ListPreviewData.kt new file mode 100644 index 000000000..c6b1dda60 --- /dev/null +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/previewparameter/ListPreviewData.kt @@ -0,0 +1,111 @@ +/* + * 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.previewparameter + +import com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui.FileUi +import com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui.TransferUi +import java.util.Calendar +import java.util.Date +import java.util.UUID + +val filesPreviewData = listOf( + FileUi( + uid = UUID.randomUUID().toString(), + fileName = "The 5-Step Guide to Not Breaking Your Code.txt", + fileSize = 57_689_032L, + mimeType = null, + localPath = null, + ), + FileUi( + uid = UUID.randomUUID().toString(), + fileName = "Introduction to Turning It Off and On Again.pptx", + fileSize = 98_723_143L, + mimeType = null, + localPath = null, + ), + FileUi( + fileName = "Opening images tutorial.png", + uid = "Opening images tutorial.png", + fileSize = 456_782L, + mimeType = null, + localPath = "https://picsum.photos/200/300", + ), + FileUi( + fileName = "How to not get fired.pdf", + uid = "How to not get fired.pdf", + fileSize = 10_302_130L, + mimeType = null, + localPath = "", + ), + FileUi( + uid = UUID.randomUUID().toString(), + fileName = "Learning to Copy and Paste: A Complete Guide.docx", + fileSize = 237_866_728L, + mimeType = null, + localPath = null, + ), + FileUi( + fileName = "The 5 step guide to turning it off and on again.docx", + uid = "The 5 step guide to turning it off and on again.docx", + fileSize = 89_723_143L, + mimeType = null, + localPath = "", + ), +) + +val transfersPreviewData = listOf( + TransferUi( + uuid = UUID.randomUUID().toString(), + createdDateTimestamp = Date().time - 30L * 86_400_000L, + expirationDateTimestamp = Calendar.getInstance().apply { + time = Date() + set(Calendar.DATE, get(Calendar.DATE) + 3) + }.time.time, + sizeUploaded = 57_689_032L, + downloadLimit = 1, + downloadLeft = 1, + message = "Coucou c'est moi le message de description du transfert.", + files = filesPreviewData, + ), + TransferUi( + uuid = UUID.randomUUID().toString(), + createdDateTimestamp = Date().time - 5L * 86_400_000L, + expirationDateTimestamp = Calendar.getInstance().apply { + time = Date() + set(Calendar.DATE, get(Calendar.DATE) + 5) + }.time.time, + sizeUploaded = 89_723_143L, + downloadLimit = 20, + downloadLeft = 0, + message = null, + files = filesPreviewData, + ), + TransferUi( + uuid = UUID.randomUUID().toString(), + createdDateTimestamp = Date().time - 0.5f.toLong() * 86_400_000L, + expirationDateTimestamp = Calendar.getInstance().apply { + time = Date() + set(Calendar.DATE, get(Calendar.DATE) - 4) + }.time.time, + sizeUploaded = 237_866_728L, + downloadLimit = 250, + downloadLeft = 123, + message = "3ème transfert. RAS.", + files = filesPreviewData, + ), +) diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/previewparameter/FileUiListPreviewParameterProvider.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/previewparameter/PreviewParameterProviders.kt similarity index 52% rename from app/src/main/java/com/infomaniak/swisstransfer/ui/previewparameter/FileUiListPreviewParameterProvider.kt rename to app/src/main/java/com/infomaniak/swisstransfer/ui/previewparameter/PreviewParameterProviders.kt index ed5152de1..938e540c6 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/previewparameter/FileUiListPreviewParameterProvider.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/previewparameter/PreviewParameterProviders.kt @@ -19,31 +19,12 @@ package com.infomaniak.swisstransfer.ui.previewparameter import androidx.compose.ui.tooling.preview.PreviewParameterProvider import com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui.FileUi +import com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui.TransferUi class FileUiListPreviewParameter : PreviewParameterProvider> { - override val values: Sequence> = sequenceOf( - listOf( - FileUi( - fileName = "How to not get fired.pdf", - uid = "How to not get fired.pdf", - fileSize = 10302130, - mimeType = null, - localPath = "", - ), - FileUi( - fileName = "Opening images tutorial.png", - uid = "Opening images tutorial.png", - fileSize = 456782, - mimeType = null, - localPath = "https://picsum.photos/200/300", - ), - FileUi( - fileName = "The 5 step guide to turning it off and on again.docx", - uid = "The 5 step guide to turning it off and on again.docx", - fileSize = 89723143, - mimeType = null, - localPath = "", - ), - ) - ) + override val values: Sequence> = sequenceOf(filesPreviewData) +} + +class TransferUiListPreviewParameter : PreviewParameterProvider> { + override val values: Sequence> = sequenceOf(transfersPreviewData) } 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 81a0ad899..d5044b0d9 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 @@ -26,23 +26,20 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle -import com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui.FileUi -import com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui.TransferUi import com.infomaniak.swisstransfer.R import com.infomaniak.swisstransfer.ui.components.EmptyState import com.infomaniak.swisstransfer.ui.components.transfer.TransferExpiredBottomSheet import com.infomaniak.swisstransfer.ui.components.transfer.TransferItemList import com.infomaniak.swisstransfer.ui.images.AppImages.AppIllus 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.theme.Margin import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows -import java.util.Calendar import java.util.Date -import java.util.UUID @Composable fun ReceivedScreen( @@ -78,97 +75,9 @@ private fun ReceivedScreen( description = stringResource(R.string.noTransferReceivedDescription), ) } else { - - val files = listOf( - FileUi( - uid = UUID.randomUUID().toString(), - fileName = "The 5-Step Guide to Not Breaking Your Code (1).txt", - fileSize = 57_689_032L, - mimeType = null, - localPath = null, - ), - FileUi( - uid = UUID.randomUUID().toString(), - fileName = "Introduction to Turning It Off and On Again (1).pptx", - fileSize = 89_723_143L, - mimeType = null, - localPath = null, - ), - FileUi( - uid = UUID.randomUUID().toString(), - fileName = "Learning to Copy and Paste: A Complete Guide (1).docx", - fileSize = 237_866_728L, - mimeType = null, - localPath = null, - ), - FileUi( - uid = UUID.randomUUID().toString(), - fileName = "The 5-Step Guide to Not Breaking Your Code (2).txt", - fileSize = 57_689_032L, - mimeType = null, - localPath = null, - ), - FileUi( - uid = UUID.randomUUID().toString(), - fileName = "Introduction to Turning It Off and On Again (2).pptx", - fileSize = 89_723_143L, - mimeType = null, - localPath = null, - ), - FileUi( - uid = UUID.randomUUID().toString(), - fileName = "Learning to Copy and Paste: A Complete Guide (2).docx", - fileSize = 237_866_728L, - mimeType = null, - localPath = null, - ), - ) - - val transfers = listOf( - TransferUi( - uuid = UUID.randomUUID().toString(), - createdDateTimestamp = Date().time - 30L * 86_400_000L, - expirationDateTimestamp = Calendar.getInstance().apply { - time = Date() - set(Calendar.DATE, get(Calendar.DATE) + 3) - }.time.time, - sizeUploaded = 57_689_032L, - downloadLimit = 1, - downloadLeft = 1, - message = "Coucou c'est moi le message de description du transfert.", - files = files, - ), - TransferUi( - uuid = UUID.randomUUID().toString(), - createdDateTimestamp = Date().time - 5L * 86_400_000L, - expirationDateTimestamp = Calendar.getInstance().apply { - time = Date() - set(Calendar.DATE, get(Calendar.DATE) + 5) - }.time.time, - sizeUploaded = 89_723_143L, - downloadLimit = 20, - downloadLeft = 0, - message = null, - files = files, - ), - TransferUi( - uuid = UUID.randomUUID().toString(), - createdDateTimestamp = Date().time - 0.5f.toLong() * 86_400_000L, - expirationDateTimestamp = Calendar.getInstance().apply { - time = Date() - set(Calendar.DATE, get(Calendar.DATE) - 4) - }.time.time, - sizeUploaded = 237_866_728L, - downloadLimit = 250, - downloadLeft = 123, - message = "3ème transfert. RAS.", - files = files, - ), - ) - TransferItemList( modifier = Modifier.padding(Margin.Medium), - transfers = transfers, + transfers = transfersPreviewData, // TODO: Use real data onClick = { transfer -> when { transfer.expiresInDays < 0 -> { 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 67d46a009..41e928167 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 @@ -21,43 +21,20 @@ import androidx.compose.foundation.layout.padding import androidx.compose.material3.Surface import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier -import com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui.FileUi +import androidx.compose.ui.tooling.preview.PreviewParameter +import com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui.TransferUi import com.infomaniak.swisstransfer.ui.components.FileItemList +import com.infomaniak.swisstransfer.ui.previewparameter.TransferUiListPreviewParameter +import com.infomaniak.swisstransfer.ui.previewparameter.filesPreviewData import com.infomaniak.swisstransfer.ui.theme.Margin import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows @Composable fun SentListScreen(transfers: List) { - - // TODO: Remove this when `transfers` contains the real data. - val transfers = listOf( - FileUi( - fileName = "The 5-Step Guide to Not Breaking Your Code.txt", - uid = "The 5-Step Guide to Not Breaking Your Code.txt", - fileSize = 57_689_032L, - mimeType = null, - localPath = "", - ), - FileUi( - fileName = "Introduction to Turning It Off and On Again.pptx", - uid = "Introduction to Turning It Off and On Again.pptx", - fileSize = 89_723_143L, - mimeType = null, - localPath = "", - ), - FileUi( - fileName = "Learning to Copy and Paste: A Complete Guide.docx", - uid = "Learning to Copy and Paste: A Complete Guide.docx", - fileSize = 237_866_728L, - mimeType = null, - localPath = "", - ), - ) - FileItemList( modifier = Modifier.padding(Margin.Medium), - files = transfers, + files = filesPreviewData, // TODO: Use real data isRemoveButtonVisible = true, isCheckboxVisible = { false }, isUidChecked = { false }, @@ -67,10 +44,10 @@ fun SentListScreen(transfers: List) { @PreviewAllWindows @Composable -private fun SentListScreenPreview() { +private fun Preview(@PreviewParameter(TransferUiListPreviewParameter::class) transfers: List) { SwissTransferTheme { Surface { - SentListScreen(transfers = listOf(Unit)) + SentListScreen(transfers) } } } diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/transferdetails/TransferDetailsScreen.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/transferdetails/TransferDetailsScreen.kt index 51859a4ef..c2fc792a0 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/transferdetails/TransferDetailsScreen.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/transferdetails/TransferDetailsScreen.kt @@ -37,20 +37,18 @@ import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel import com.infomaniak.core2.FORMAT_DATE_FULL import com.infomaniak.core2.format -import com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui.FileUi import com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui.TransferUi import com.infomaniak.swisstransfer.R import com.infomaniak.swisstransfer.ui.components.* import com.infomaniak.swisstransfer.ui.images.AppImages.AppIcons import com.infomaniak.swisstransfer.ui.images.icons.* +import com.infomaniak.swisstransfer.ui.previewparameter.transfersPreviewData import com.infomaniak.swisstransfer.ui.screen.main.components.SmallWindowTopAppBarScaffold 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.shareText -import java.util.Calendar import java.util.Date -import java.util.UUID @Composable fun TransferDetailsScreen( @@ -59,65 +57,7 @@ fun TransferDetailsScreen( transferDetailsViewModel: TransferDetailsViewModel = hiltViewModel(), ) { - val transferFiles = listOf( - FileUi( - uid = UUID.randomUUID().toString(), - fileName = "The 5-Step Guide to Not Breaking Your Code (1).txt", - fileSize = 57_689_032L, - mimeType = null, - localPath = null, - ), - FileUi( - uid = UUID.randomUUID().toString(), - fileName = "Introduction to Turning It Off and On Again (1).pptx", - fileSize = 89_723_143L, - mimeType = null, - localPath = null, - ), - FileUi( - uid = UUID.randomUUID().toString(), - fileName = "Learning to Copy and Paste: A Complete Guide (1).docx", - fileSize = 237_866_728L, - mimeType = null, - localPath = null, - ), - FileUi( - uid = UUID.randomUUID().toString(), - fileName = "The 5-Step Guide to Not Breaking Your Code (2).txt", - fileSize = 57_689_032L, - mimeType = null, - localPath = null, - ), - FileUi( - uid = UUID.randomUUID().toString(), - fileName = "Introduction to Turning It Off and On Again (2).pptx", - fileSize = 89_723_143L, - mimeType = null, - localPath = null, - ), - FileUi( - uid = UUID.randomUUID().toString(), - fileName = "Learning to Copy and Paste: A Complete Guide (2).docx", - fileSize = 237_866_728L, - mimeType = null, - localPath = null, - ), - ) - - val transfer = TransferUi( - uuid = UUID.randomUUID().toString(), - createdDateTimestamp = Date().time - 30L * 86_400_000L, - expirationDateTimestamp = Calendar.getInstance().apply { - time = Date() - set(Calendar.DATE, get(Calendar.DATE) + 3) - }.time.time, - sizeUploaded = 57_689_032L, - downloadLimit = 250, - downloadLeft = 42, - message = "Coucou c'est moi le message de description du transfert.", - files = transferFiles, - ) - + val transfer = transfersPreviewData.first() // TODO: Use real data val transferSenderEmail: String? = "john.smith@ik.me" // TODO val transferLink = "https://chk.me/83azQOl" // TODO @@ -139,7 +79,7 @@ fun TransferDetailsScreen( modifier = Modifier .weight(1.0f) .padding(horizontal = Margin.Medium), - files = transferFiles, // TODO + files = transfer.files, isRemoveButtonVisible = false, isCheckboxVisible = { isMultiselectOn }, isUidChecked = { fileUid -> transferDetailsViewModel.checkedFiles[fileUid] ?: false },