Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Put the correct mimeType when importing files #190

Merged
merged 3 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}

tevincent marked this conversation as resolved.
Show resolved Hide resolved
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
Loading