Clean up conversion of fbandroid/libraries/fbcore/src/main/java/com/facebook/common/media/MediaUtils.kt
@@ -17,45 +17,30 @@ object MediaUtils {
@JvmField // Additional mime types that we know to be a particular media type but which may not be
// supported natively on the device.
val ADDITIONAL_ALLOWED_MIME_TYPES =
- ImmutableMap.of("mkv", "video/x-matroska", "glb", "model/gltf-binary")
+ mapOf(
+ "mkv" to "video/x-matroska",
+ "glb" to "model/gltf-binary",
+ )
- @JvmStatic
- fun isPhoto(mimeType: String?): Boolean {
- return mimeType != null && mimeType.startsWith("image/")
- }
+ @JvmStatic fun isPhoto(mimeType: String?): Boolean = mimeType?.startsWith("image/") ?: false
- @JvmStatic
- fun isVideo(mimeType: String?): Boolean {
- return mimeType != null && mimeType.startsWith("video/")
- }
+ @JvmStatic fun isVideo(mimeType: String?): Boolean = mimeType?.startsWith("video/") ?: false
- @JvmStatic
- fun isThreeD(mimeType: String?): Boolean {
- return mimeType != null && mimeType == "model/gltf-binary"
- }
+ @JvmStatic fun isThreeD(mimeType: String?): Boolean = mimeType == "model/gltf-binary"
@JvmStatic
fun extractMime(@NonNull path: String): String? {
- var extension = extractExtension(path)
- if (extension == null) {
- return null
- }
- extension = extension.toLowerCase(Locale.US)
- var mimeType = MimeTypeMapWrapper.getMimeTypeFromExtension(extension)
+ val extension = extractExtension(path)?.toLowerCase(Locale.US) ?: return null
// If we did not find a mime type for the extension specified, check our additional
// extension/mime-type mappings.
- if (mimeType == null) {
- mimeType = ADDITIONAL_ALLOWED_MIME_TYPES[extension]
- }
- return mimeType
+ return MimeTypeMapWrapper.getMimeTypeFromExtension(extension)
+ ?: ADDITIONAL_ALLOWED_MIME_TYPES[extension]
}
private fun extractExtension(@NonNull path: String): String? {
val pos = path.lastIndexOf('.')
- return if (pos < 0 || pos == path.length - 1) {
- null
- } else path.substring(pos + 1)
+ return if (pos < 0 || pos == path.length - 1) null else path.substring(pos + 1)
}
/**
