mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-26 11:26:01 +03:00
updating the known SDK mimetypes and making use of them for the intent switches
This commit is contained in:
parent
59ef8e10c8
commit
169ac9d0a0
2 changed files with 19 additions and 5 deletions
|
@ -33,9 +33,15 @@ object MimeTypes {
|
|||
|
||||
const val Ogg = "audio/ogg"
|
||||
|
||||
const val PlainText = "text/plain"
|
||||
|
||||
fun String?.normalizeMimeType() = if (this == BadJpg) Jpeg else this
|
||||
|
||||
fun String?.isMimeTypeImage() = this?.startsWith("image/").orFalse()
|
||||
fun String?.isMimeTypeVideo() = this?.startsWith("video/").orFalse()
|
||||
fun String?.isMimeTypeAudio() = this?.startsWith("audio/").orFalse()
|
||||
fun String?.isMimeTypeApplication() = this?.startsWith("application/").orFalse()
|
||||
fun String?.isMimeTypeFile() = this?.startsWith("file/").orFalse()
|
||||
fun String?.isMimeTypeText() = this?.startsWith("text/").orFalse()
|
||||
fun String?.isMimeTypeAny() = this?.startsWith("*/").orFalse()
|
||||
}
|
||||
|
|
|
@ -19,6 +19,14 @@ package im.vector.app.features.attachments
|
|||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import org.matrix.android.sdk.api.session.content.ContentAttachmentData
|
||||
import org.matrix.android.sdk.api.util.MimeTypes
|
||||
import org.matrix.android.sdk.api.util.MimeTypes.isMimeTypeAny
|
||||
import org.matrix.android.sdk.api.util.MimeTypes.isMimeTypeApplication
|
||||
import org.matrix.android.sdk.api.util.MimeTypes.isMimeTypeAudio
|
||||
import org.matrix.android.sdk.api.util.MimeTypes.isMimeTypeFile
|
||||
import org.matrix.android.sdk.api.util.MimeTypes.isMimeTypeImage
|
||||
import org.matrix.android.sdk.api.util.MimeTypes.isMimeTypeText
|
||||
import org.matrix.android.sdk.api.util.MimeTypes.isMimeTypeVideo
|
||||
import javax.inject.Inject
|
||||
|
||||
class ShareIntentHandler @Inject constructor(
|
||||
|
@ -34,11 +42,11 @@ class ShareIntentHandler @Inject constructor(
|
|||
fun handleIncomingShareIntent(intent: Intent, onFile: (List<ContentAttachmentData>) -> Unit, onPlainText: (String) -> Unit): Boolean {
|
||||
val type = intent.resolveType(context) ?: return false
|
||||
return when {
|
||||
type == "text/plain" -> handlePlainText(intent, onPlainText)
|
||||
type.startsWith("image") -> onFile(multiPickerIncomingFiles.image(intent)).let { true }
|
||||
type.startsWith("video") -> onFile(multiPickerIncomingFiles.video(intent)).let { true }
|
||||
type.startsWith("audio") -> onFile(multiPickerIncomingFiles.audio(intent)).let { true }
|
||||
type.startsWith("application") || type.startsWith("file") || type.startsWith("text") || type.startsWith("*") -> {
|
||||
type == MimeTypes.PlainText -> handlePlainText(intent, onPlainText)
|
||||
type.isMimeTypeImage() -> onFile(multiPickerIncomingFiles.image(intent)).let { true }
|
||||
type.isMimeTypeVideo() -> onFile(multiPickerIncomingFiles.video(intent)).let { true }
|
||||
type.isMimeTypeAudio() -> onFile(multiPickerIncomingFiles.audio(intent)).let { true }
|
||||
type.isMimeTypeApplication() || type.isMimeTypeFile() || type.isMimeTypeText() || type.isMimeTypeAny() -> {
|
||||
onFile(multiPickerIncomingFiles.file(intent)).let { true }
|
||||
}
|
||||
else -> false
|
||||
|
|
Loading…
Reference in a new issue