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..d30ba4231 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,18 +35,18 @@ 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 FileUi( + val uid: String, + val fileName: String, + val fileSizeInBytes: Long, + val mimeType: String?, + val uri: String, +) @Composable fun FileItem( - file: FileUiItem, + file: FileUi, isRemoveButtonVisible: Boolean, isCheckboxVisible: Boolean, isChecked: () -> Boolean = { false }, @@ -131,7 +131,7 @@ private fun FileItemContent( @PreviewAllWindows @Composable -private fun FileItemPreview(@PreviewParameter(FileUiListPreviewParameter::class) files: List) { +private fun FileItemPreview(@PreviewParameter(FileUiListPreviewParameter::class) files: List) { SwissTransferTheme { Surface { Column( 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 20acf8f84..cb596ec8e 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 @@ -33,7 +33,7 @@ import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows @Composable fun FileItemList( modifier: Modifier = Modifier, - files: List, + files: List, isRemoveButtonVisible: Boolean, isCheckboxVisible: Boolean, isUidChecked: (String) -> Boolean, @@ -61,7 +61,7 @@ fun FileItemList( @PreviewAllWindows @Composable -private fun FileItemListPreview(@PreviewParameter(FileUiListPreviewParameter::class) files: List) { +private fun FileItemListPreview(@PreviewParameter(FileUiListPreviewParameter::class) files: List) { SwissTransferTheme { FileItemList( files = files, diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/FilePreview.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/FilePreview.kt index 3040a4b0c..e83e17fa7 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/FilePreview.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/FilePreview.kt @@ -42,7 +42,7 @@ import com.infomaniak.swisstransfer.ui.utils.hasPreview @Composable fun FilePreview( - file: FileUiItem, + file: FileUi, circleColor: Color, circleSize: Dp, ) { diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/SmallFileItem.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/SmallFileItem.kt index 07711333c..869b51912 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/SmallFileItem.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/SmallFileItem.kt @@ -37,7 +37,7 @@ import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme @Composable fun SmallFileItem( modifier: Modifier = Modifier, - file: FileUiItem, + file: FileUi, smallFileTileSize: SmallFileTileSize, onRemove: (() -> Unit)? = null, ) { @@ -67,7 +67,7 @@ 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(@PreviewParameter(FileUiListPreviewParameter::class) files: List) { +private fun SmallFileItemPreview(@PreviewParameter(FileUiListPreviewParameter::class) files: List) { SwissTransferTheme { Surface(color = SwissTransferTheme.materialColors.surfaceContainerHighest) { Column(Modifier.padding(16.dp)) { 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..f04da36a5 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 @@ -18,32 +18,32 @@ package com.infomaniak.swisstransfer.ui.previewparameter import androidx.compose.ui.tooling.preview.PreviewParameterProvider -import com.infomaniak.swisstransfer.ui.components.FileUiItem +import com.infomaniak.swisstransfer.ui.components.FileUi -class FileUiListPreviewParameter : PreviewParameterProvider> { - override val values: Sequence> = sequenceOf( +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 = "" - }, + FileUi( + fileName = "How to not get fired.pdf", + uid = "How to not get fired.pdf", + fileSizeInBytes = 10302130, + mimeType = null, + uri = "", + ), + FileUi( + fileName = "Opening images tutorial.png", + uid = "Opening images tutorial.png", + fileSizeInBytes = 456782, + mimeType = null, + uri = "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", + 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..4e64230ca 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 @@ -29,7 +29,7 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.infomaniak.swisstransfer.R import com.infomaniak.swisstransfer.ui.components.EmptyState import com.infomaniak.swisstransfer.ui.components.FileItemList -import com.infomaniak.swisstransfer.ui.components.FileUiItem +import com.infomaniak.swisstransfer.ui.components.FileUi import com.infomaniak.swisstransfer.ui.images.AppImages.AppIllus import com.infomaniak.swisstransfer.ui.images.illus.MascotSearching import com.infomaniak.swisstransfer.ui.screen.main.components.BrandTopAppBarScaffold @@ -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( + FileUi( + 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 = "", + ), + FileUi( + 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 = "", + ), + FileUi( + 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..c1ff2b6b4 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 @@ -22,32 +22,36 @@ import androidx.compose.material3.Surface import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import com.infomaniak.swisstransfer.ui.components.FileItemList -import com.infomaniak.swisstransfer.ui.components.FileUiItem +import com.infomaniak.swisstransfer.ui.components.FileUi 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) { - 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( + FileUi( + 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 = "", + ), + FileUi( + 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 = "", + ), + FileUi( + 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/NewTransferViewModel.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/NewTransferViewModel.kt index 01029191c..4696748f6 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/NewTransferViewModel.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/NewTransferViewModel.kt @@ -20,7 +20,7 @@ package com.infomaniak.swisstransfer.ui.screen.newtransfer import android.net.Uri import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import com.infomaniak.swisstransfer.ui.components.FileUiItem +import com.infomaniak.swisstransfer.ui.components.FileUi import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableStateFlow @@ -32,8 +32,8 @@ import javax.inject.Inject @HiltViewModel class NewTransferViewModel @Inject constructor(private val transferFilesManager: TransferFilesManager) : ViewModel() { - private val _files = MutableStateFlow>(emptyList()) - val files: StateFlow> = _files + private val _files = MutableStateFlow>(emptyList()) + val files: StateFlow> = _files private val _failedFileCount = MutableSharedFlow() val failedFileCount: SharedFlow = _failedFileCount 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..729af2e5b 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 @@ -22,7 +22,7 @@ import android.content.Context import android.database.Cursor import android.net.Uri import android.provider.OpenableColumns -import com.infomaniak.swisstransfer.ui.components.FileUiItem +import com.infomaniak.swisstransfer.ui.components.FileUi import com.infomaniak.swisstransfer.ui.utils.FileNameUtils import dagger.hilt.android.qualifiers.ApplicationContext import javax.inject.Inject @@ -30,9 +30,9 @@ import javax.inject.Singleton @Singleton class TransferFilesManager @Inject constructor(@ApplicationContext private val appContext: Context) { - fun getFiles(uris: List, alreadyUsedFileNames: Set): MutableSet { + fun getFiles(uris: List, alreadyUsedFileNames: Set): MutableSet { val currentUsedFileNames = alreadyUsedFileNames.toMutableSet() - val files = mutableSetOf() + val files = mutableSetOf() uris.forEach { uri -> getFile(uri, currentUsedFileNames)?.let { file -> @@ -44,19 +44,13 @@ class TransferFilesManager @Inject constructor(@ApplicationContext private val a return files } - private fun getFile(uri: Uri, alreadyUsedFileNames: Set): FileUiItem? { + private fun getFile(uri: Uri, alreadyUsedFileNames: Set): FileUi? { val contentResolver: ContentResolver = appContext.contentResolver val cursor: Cursor? = contentResolver.query(uri, null, null, null, null) 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() - } + FileUi(fileName = uniqueName, uid = uniqueName, fileSizeInBytes = size, mimeType = null, uri = uri.toString()) } } diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/ImportFilesScreen.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/ImportFilesScreen.kt index 43648927f..ce5b3d6be 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/ImportFilesScreen.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/ImportFilesScreen.kt @@ -51,7 +51,7 @@ fun ImportFilesScreen( @Composable private fun ImportFilesScreen( - files: () -> List, + files: () -> List, removeFileByUid: (uid: String) -> Unit, addFiles: (List) -> Unit, closeActivity: () -> Unit, @@ -111,7 +111,7 @@ private fun ImportFilesScreen( @PreviewAllWindows @Composable -private fun ImportFilesScreenPreview(@PreviewParameter(FileUiListPreviewParameter::class) files: List) { +private fun ImportFilesScreenPreview(@PreviewParameter(FileUiListPreviewParameter::class) files: List) { SwissTransferTheme { ImportFilesScreen({ files }, {}, {}, closeActivity = {}) } diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/components/ImportedFilesCard.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/components/ImportedFilesCard.kt index ab45c3041..c5b889114 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/components/ImportedFilesCard.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/components/ImportedFilesCard.kt @@ -47,7 +47,7 @@ import kotlinx.parcelize.Parcelize @Composable fun ImportedFilesCard( modifier: Modifier = Modifier, - files: () -> List, + files: () -> List, humanReadableSize: () -> String, showUploadSourceChoiceBottomSheet: () -> Unit, removeFileByUid: (uid: String) -> Unit, @@ -140,7 +140,7 @@ 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(@PreviewParameter(FileUiListPreviewParameter::class) files: List) { +private fun ImportedFilesCardPreview(@PreviewParameter(FileUiListPreviewParameter::class) files: List) { SwissTransferTheme { ImportedFilesCard( modifier = Modifier.padding(Margin.Medium), diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/utils/FileUiItemExt.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/utils/FileUiItemExt.kt index e78f6ccb3..82bcd098e 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/utils/FileUiItemExt.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/utils/FileUiItemExt.kt @@ -18,8 +18,8 @@ package com.infomaniak.swisstransfer.ui.utils import com.infomaniak.library.filetypes.FileType -import com.infomaniak.swisstransfer.ui.components.FileUiItem +import com.infomaniak.swisstransfer.ui.components.FileUi -val FileUiItem.fileType: FileType get() = mimeType?.let { FileType.guessFromMimeType(it) } ?: FileType.guessFromFileName(fileName) +val FileUi.fileType: FileType get() = mimeType?.let { FileType.guessFromMimeType(it) } ?: FileType.guessFromFileName(fileName) -val FileUiItem.hasPreview: Boolean get() = fileType == FileType.IMAGE +val FileUi.hasPreview: Boolean get() = fileType == FileType.IMAGE