Skip to content

Commit

Permalink
fix: Put the correct mimeType when importing files
Browse files Browse the repository at this point in the history
  • Loading branch information
tevincent committed Nov 14, 2024
1 parent d33aec7 commit c9af7bd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c9af7bd

Please sign in to comment.