add a List extension for determining Mimetype of multiple uris

This commit is contained in:
tibbi 2017-10-22 22:55:58 +02:00
parent f29a17f42e
commit 7e9e2d6d3a

View file

@ -0,0 +1,24 @@
package com.simplemobiletools.commons.extensions
import android.net.Uri
import java.util.*
fun List<Uri>.getMimeType(): String {
val mimeGroups = HashSet<String>(size)
val subtypes = HashSet<String>(size)
forEach {
val parts = it.path.getMimeTypeFromPath().split("/")
if (parts.size == 2) {
mimeGroups.add(parts.getOrElse(0, { "" }))
subtypes.add(parts.getOrElse(1, { "" }))
} else {
return "*/*"
}
}
return when {
subtypes.size == 1 -> "${mimeGroups.first()}/${subtypes.first()}"
mimeGroups.size == 1 -> "${mimeGroups.first()}/*"
else -> "*/*"
}
}