Skip to content

Commit

Permalink
refactor: Make Previews great again!
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinBoulongne committed Nov 7, 2024
1 parent b1ae78c commit 9d129ba
Show file tree
Hide file tree
Showing 11 changed files with 193 additions and 419 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand All @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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<FileUi>) {
SwissTransferTheme {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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<FileUi>) {
SwissTransferTheme {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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<FileUi>) {
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)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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<TransferUi>) {
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 = {})
}
}
}
Loading

0 comments on commit 9d129ba

Please sign in to comment.