diff --git a/FileTypes/src/main/java/com/infomaniak/library/filetypes/FileType.kt b/FileTypes/src/main/java/com/infomaniak/library/filetypes/FileType.kt index 489340d3b..6caf08b2c 100644 --- a/FileTypes/src/main/java/com/infomaniak/library/filetypes/FileType.kt +++ b/FileTypes/src/main/java/com/infomaniak/library/filetypes/FileType.kt @@ -46,9 +46,14 @@ enum class FileType(val icon: ImageVector, private val colorLight: Color, privat } companion object { + fun getMimeTypeFromFileName(fileName: String): String? { + return fileName.extractExtension()?.let { extension -> + MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension) + } + } + fun guessFromFileName(fileName: String): FileType { - val extension = fileName.extractExtension() ?: return UNKNOWN - val mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension) ?: return UNKNOWN + val mimeType = getMimeTypeFromFileName(fileName) ?: return UNKNOWN return guessFromMimeType(mimeType) } diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/ImportationFilesManager.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/ImportationFilesManager.kt index d51755307..4041cc999 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/ImportationFilesManager.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/ImportationFilesManager.kt @@ -23,6 +23,7 @@ import android.database.Cursor import android.net.Uri import android.provider.OpenableColumns import androidx.core.net.toUri +import com.infomaniak.library.filetypes.FileType import com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui.FileUi import com.infomaniak.sentry.SentryLog import com.infomaniak.swisstransfer.ui.utils.FileNameUtils @@ -103,7 +104,7 @@ class ImportationFilesManager @Inject constructor( uid = fileToImport.fileName, fileName = fileToImport.fileName, fileSize = fileToImport.fileSizeInBytes, - mimeType = null, + mimeType = FileType.getMimeTypeFromFileName(fileToImport.fileName), localPath = copiedFile.toUri().toString(), ) ) diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/utils/FileUiExt.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/utils/FileUiExt.kt index 1ae514a8e..5b9d485b7 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/utils/FileUiExt.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/utils/FileUiExt.kt @@ -20,6 +20,6 @@ package com.infomaniak.swisstransfer.ui.utils import com.infomaniak.library.filetypes.FileType import com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui.FileUi -val FileUi.fileType: FileType get() = mimeType?.let { FileType.guessFromMimeType(it) } ?: FileType.guessFromFileName(fileName) +val FileUi.fileType: FileType get() = FileType.guessFromFileName(fileName) val FileUi.hasPreview: Boolean get() = fileType == FileType.IMAGE