From 0e21cdd51e23932d53958a7581084b64d9463f7a Mon Sep 17 00:00:00 2001 From: Gibran Chevalley Date: Mon, 14 Oct 2024 08:31:10 +0200 Subject: [PATCH] Turn FileUiItem from interface to data class to make future replacement easier --- .../swisstransfer/ui/components/FileItem.kt | 16 +++---- .../FileUiListPreviewParameterProvider.kt | 42 +++++++++---------- .../ui/screen/main/received/ReceivedScreen.kt | 42 ++++++++++--------- .../ui/screen/main/sent/SentListScreen.kt | 42 ++++++++++--------- .../newtransfer/TransferFilesManager.kt | 8 +--- 5 files changed, 76 insertions(+), 74 deletions(-) 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 f5f6a2c48..7bdb8f32e 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 @@ -35,14 +35,14 @@ import com.infomaniak.swisstransfer.ui.theme.Margin import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows -// TODO: Get the interface from the shared kmp code -interface FileUiItem { - val uid: String - val fileName: String - val fileSizeInBytes: Long - val mimeType: String? - val uri: String -} +// TODO: Get the data class from the shared kmp code +data class FileUiItem( + val uid: String, + val fileName: String, + val fileSizeInBytes: Long, + val mimeType: String?, + val uri: String, +) @Composable fun FileItem( diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/previewparameter/FileUiListPreviewParameterProvider.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/previewparameter/FileUiListPreviewParameterProvider.kt index 5a3a453ce..d731a27cd 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/previewparameter/FileUiListPreviewParameterProvider.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/previewparameter/FileUiListPreviewParameterProvider.kt @@ -23,27 +23,27 @@ import com.infomaniak.swisstransfer.ui.components.FileUiItem class FileUiListPreviewParameter : PreviewParameterProvider> { override val values: Sequence> = 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 = "" - }, + FileUiItem( + fileName = "How to not get fired.pdf", + uid = "How to not get fired.pdf", + fileSizeInBytes = 10302130, + mimeType = null, + uri = "", + ), + FileUiItem( + fileName = "Opening images tutorial.png", + uid = "Opening images tutorial.png", + fileSizeInBytes = 456782, + mimeType = null, + uri = "https://picsum.photos/200/300", + ), + FileUiItem( + 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", + fileSizeInBytes = 89723143, + mimeType = null, + uri = "", + ), ) ) } 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 1a2f21a73..0761fe748 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 @@ -71,25 +71,29 @@ private fun ReceivedScreen( description = R.string.noTransferReceivedDescription, ) } else { - 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 = "" - }) + val files = listOf( + FileUiItem( + fileName = "The 5-Step Guide to Not Breaking Your Code.txt", + uid = "The 5-Step Guide to Not Breaking Your Code.txt", + fileSizeInBytes = 57689032, + mimeType = null, + uri = "", + ), + FileUiItem( + fileName = "Introduction to Turning It Off and On Again.pptx", + uid = "Introduction to Turning It Off and On Again.pptx", + fileSizeInBytes = 89723143, + mimeType = null, + uri = "", + ), + FileUiItem( + fileName = "Learning to Copy and Paste: A Complete Guide.docx", + uid = "Learning to Copy and Paste: A Complete Guide.docx", + fileSizeInBytes = 237866728, + mimeType = null, + uri = "", + ), + ) FileItemList( modifier = Modifier.padding(Margin.Medium), files = files, 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 2ac1937b4..4b55d2f31 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 @@ -29,25 +29,29 @@ import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows @Composable fun SentListScreen(transfers: List) { - val transfers = 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 = "" - }) + val transfers = listOf( + FileUiItem( + fileName = "The 5-Step Guide to Not Breaking Your Code.txt", + uid = "The 5-Step Guide to Not Breaking Your Code.txt", + fileSizeInBytes = 57689032, + mimeType = null, + uri = "", + ), + FileUiItem( + fileName = "Introduction to Turning It Off and On Again.pptx", + uid = "Introduction to Turning It Off and On Again.pptx", + fileSizeInBytes = 89723143, + mimeType = null, + uri = "", + ), + FileUiItem( + fileName = "Learning to Copy and Paste: A Complete Guide.docx", + uid = "Learning to Copy and Paste: A Complete Guide.docx", + fileSizeInBytes = 237866728, + mimeType = null, + uri = "", + ), + ) FileItemList( modifier = Modifier.padding(Margin.Medium), files = transfers, diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/TransferFilesManager.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/TransferFilesManager.kt index bb1c3fb2a..72a463e93 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/TransferFilesManager.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/TransferFilesManager.kt @@ -50,13 +50,7 @@ class TransferFilesManager @Inject constructor(@ApplicationContext private val a return cursor?.getFileNameAndSize()?.let { (name, size) -> val uniqueName = FileNameUtils.postfixExistingFileNames(name, alreadyUsedFileNames) - object: FileUiItem { - override val fileName: String = uniqueName - override val uid: String = fileName - override val fileSizeInBytes: Long = size - override val mimeType: String? = null - override val uri: String = uri.toString() - } + FileUiItem(fileName = uniqueName, uid = uniqueName, fileSizeInBytes = size, mimeType = null, uri = uri.toString()) } }