Skip to content

Commit

Permalink
Use a PreviewParameter to factorize FileUiItem instantiation inside p…
Browse files Browse the repository at this point in the history
…reviews
  • Loading branch information
LunarX committed Oct 18, 2024
1 parent da57824 commit f9bafbe
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ 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.PreviewParameter
import androidx.compose.ui.unit.dp
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
Expand Down Expand Up @@ -129,7 +131,7 @@ private fun FileItemContent(

@PreviewAllWindows
@Composable
private fun FileItemPreview() {
private fun FileItemPreview(@PreviewParameter(FileUiListPreviewParameter::class) files: List<FileUiItem>) {
SwissTransferTheme {
Surface {
Column(
Expand All @@ -140,13 +142,7 @@ private fun FileItemPreview() {
{
var isChecked by remember { mutableStateOf(true) }

val iconFile = object : FileUiItem {
override val fileName: String = "How to not get fired.pdf"
override val uid: String = fileName
override val fileSizeInBytes: Long = 10302130
override val mimeType: String? = null
override val uri: String = ""
}
val iconFile = files[0]
FileItem(
iconFile,
isRemoveButtonVisible = true,
Expand All @@ -158,13 +154,7 @@ private fun FileItemPreview() {

Spacer(modifier = Modifier.height(16.dp))

val imageFile = object : FileUiItem {
override val fileName: String = "Time-Clock-Circle--Streamline-Ultimate.svg (1).png"
override val uid: String = fileName
override val fileSizeInBytes: Long = 456782
override val mimeType: String? = null
override val uri: String = "https://picsum.photos/200/300"
}
val imageFile = files[1]
FileItem(
file = imageFile,
isRemoveButtonVisible = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.unit.dp
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
Expand Down Expand Up @@ -59,27 +61,7 @@ fun FileItemList(

@PreviewAllWindows
@Composable
private fun FileItemListPreview() {
val files = listOf(object : FileUiItem {
override val fileName: String = "The 5-Step Guide to Not Breaking Your Code.txt"
override val uid: String = fileName
override val fileSizeInBytes: Long = 57689032
override val mimeType: String? = null
override val uri: String = ""
}, object : FileUiItem {
override val fileName: String = "Introduction to Turning It Off and On Again.pptx"
override val uid: String = fileName
override val fileSizeInBytes: Long = 89723143
override val mimeType: String? = null
override val uri: String = ""
}, object : FileUiItem {
override val fileName: String = "Learning to Copy and Paste: A Complete Guide.docx"
override val uid: String = fileName
override val fileSizeInBytes: Long = 237866728
override val mimeType: String? = null
override val uri: String = ""
})

private fun FileItemListPreview(@PreviewParameter(FileUiListPreviewParameter::class) files: List<FileUiItem>) {
SwissTransferTheme {
FileItemList(
files = files,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.times
import com.infomaniak.swisstransfer.ui.previewparameter.FileUiListPreviewParameter
import com.infomaniak.swisstransfer.ui.theme.CustomShapes
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme

Expand Down Expand Up @@ -65,32 +67,22 @@ enum class SmallFileTileSize(val size: Dp, val shape: Shape) {
@Preview(name = "Light")
@Preview(name = "Dark", uiMode = Configuration.UI_MODE_NIGHT_YES or Configuration.UI_MODE_TYPE_NORMAL)
@Composable
private fun SmallFileItemPreview() {
private fun SmallFileItemPreview(@PreviewParameter(FileUiListPreviewParameter::class) files: List<FileUiItem>) {
SwissTransferTheme {
Surface(color = SwissTransferTheme.materialColors.surfaceContainerHighest) {
Column(Modifier.padding(16.dp)) {
val file = files[0]

SmallFileItem(
file = object : FileUiItem {
override val fileName: String = "How to not get fired.pdf"
override val uid: String = fileName
override val fileSizeInBytes: Long = 10302130
override val mimeType: String? = null
override val uri: String = ""
},
file = file,
smallFileTileSize = SmallFileTileSize.LARGE,
onRemove = {}
)

Spacer(modifier = Modifier.height(16.dp))

SmallFileItem(
file = object : FileUiItem {
override val fileName: String = "How to not get fired.pdf"
override val uid: String = fileName
override val fileSizeInBytes: Long = 10302130
override val mimeType: String? = null
override val uri: String = ""
},
file = file,
smallFileTileSize = SmallFileTileSize.SMALL,
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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.previewparameter

import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import com.infomaniak.swisstransfer.ui.components.FileUiItem

class FileUiListPreviewParameter : PreviewParameterProvider<List<FileUiItem>> {
override val values: Sequence<List<FileUiItem>> = sequenceOf(
listOf(
object : FileUiItem { // Non-image file
override val fileName: String = "How to not get fired.pdf"
override val uid: String = fileName
override val fileSizeInBytes: Long = 10302130
override val mimeType: String? = null
override val uri: String = ""
},
object : FileUiItem { // Image file
override val fileName: String = "Opening images tutorial.png"
override val uid: String = fileName
override val fileSizeInBytes: Long = 456782
override val mimeType: String? = null
override val uri: String = "https://picsum.photos/200/300"
},
object : FileUiItem {
override val fileName: String = "The 5 step guide to turning it off and on again.docx"
override val uid: String = fileName
override val fileSizeInBytes: Long = 89723143
override val mimeType: String? = null
override val uri: String = ""
},
)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ import androidx.compose.runtime.*
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.infomaniak.swisstransfer.R
import com.infomaniak.swisstransfer.ui.components.*
import com.infomaniak.swisstransfer.ui.previewparameter.FileUiListPreviewParameter
import com.infomaniak.swisstransfer.ui.screen.newtransfer.NewTransferViewModel
import com.infomaniak.swisstransfer.ui.screen.newtransfer.importfiles.components.ImportedFilesCard
import com.infomaniak.swisstransfer.ui.theme.Margin
Expand Down Expand Up @@ -109,18 +111,8 @@ private fun ImportFilesScreen(

@PreviewAllWindows
@Composable
private fun ImportFilesScreenPreview() {
private fun ImportFilesScreenPreview(@PreviewParameter(FileUiListPreviewParameter::class) files: List<FileUiItem>) {
SwissTransferTheme {
ImportFilesScreen({
listOf(
object : FileUiItem {
override val uid = ""
override val fileName = "Time-Clock-Circle--Streamline-Ultimate.svg (1).svg"
override val fileSizeInBytes = 2367832L
override val mimeType = null
override val uri = ""
}
)
}, {}, {}, closeActivity = {})
ImportFilesScreen({ files }, {}, {}, closeActivity = {})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.unit.dp
import com.infomaniak.swisstransfer.R
import com.infomaniak.swisstransfer.ui.components.*
import com.infomaniak.swisstransfer.ui.images.AppImages
import com.infomaniak.swisstransfer.ui.images.icons.AddThick
import com.infomaniak.swisstransfer.ui.images.icons.ChevronRightSmall
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
Expand Down Expand Up @@ -138,21 +140,11 @@ private data class TransferLazyRowKey(
@Preview(name = "Light")
@Preview(name = "Dark", uiMode = Configuration.UI_MODE_NIGHT_YES or Configuration.UI_MODE_TYPE_NORMAL)
@Composable
private fun ImportededFilesCardPreview() {
private fun ImportededFilesCardPreview(@PreviewParameter(FileUiListPreviewParameter::class) files: List<FileUiItem>) {
SwissTransferTheme {
ImportedFilesCard(
modifier = Modifier.padding(Margin.Medium),
files = {
listOf(
object : FileUiItem {
override val uid = ""
override val fileName = "Time-Clock-Circle--Streamline-Ultimate.svg (1).svg"
override val fileSizeInBytes = 234567832L
override val mimeType = null
override val uri = ""
}
)
},
files = { files },
humanReadableSize = { "20 GB" },
showUploadSourceChoiceBottomSheet = {},
removeFileByUid = {}
Expand Down

0 comments on commit f9bafbe

Please sign in to comment.