add a List extension for determining Mimetype of multiple uris
This commit is contained in:
parent
f29a17f42e
commit
7e9e2d6d3a
1 changed files with 24 additions and 0 deletions
|
@ -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 -> "*/*"
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue