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 all commits
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,15 @@ enum class FileType(val icon: ImageVector, private val colorLight: Color, privat
}

companion object {
//TODO Move this method into Core2
fun guessMimeTypeFromFileName(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 = guessMimeTypeFromFileName(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.guessMimeTypeFromFileName(fileToImport.fileName),
localPath = copiedFile.toUri().toString(),
)
)
Expand Down
Loading