Skip to content

Commit

Permalink
Turn FileUiItem from interface to data class to make future replaceme…
Browse files Browse the repository at this point in the history
…nt easier
  • Loading branch information
LunarX committed Oct 18, 2024
1 parent 98720e9 commit 0e21cdd
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,27 @@ 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 = ""
},
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 = "",
),
)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,29 @@ import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows

@Composable
fun SentListScreen(transfers: List<Any>) {
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

Expand Down

0 comments on commit 0e21cdd

Please sign in to comment.