Exit early if UNCOMPRESSED is selected

This commit is contained in:
David Kaspar 2024-10-02 17:47:53 +02:00
parent e3858dc830
commit 32783794ee

View File

@ -49,7 +49,13 @@ class MediaCompressor {
onError: (Int) -> Unit,
mediaQuality: CompressorQuality,
) {
if (mediaQuality != CompressorQuality.UNCOMPRESSED) {
// Skip compression if user selected uncompressed
if (mediaQuality == CompressorQuality.UNCOMPRESSED) {
Log.d("MediaCompressor", "UNCOMPRESSED quality selected, skipping compression.")
onReady(uri, contentType, null)
return
}
checkNotInMainThread()
if (contentType?.startsWith("video", true) == true) {
@ -122,11 +128,7 @@ class MediaCompressor {
}
},
)
} else if (
contentType?.startsWith("image", true) == true &&
!contentType.contains("gif") &&
!contentType.contains("svg")
) {
} else if (contentType?.startsWith("image", true) == true && !contentType.contains("gif") && !contentType.contains("svg")) {
val imageQuality =
when (mediaQuality) {
CompressorQuality.VERY_LOW -> 40
@ -154,10 +156,6 @@ class MediaCompressor {
} else {
onReady(uri, contentType, null)
}
} else {
Log.d("MediaCompressor", "UNCOMPRESSED quality selected, skip compression and continue with original media.")
onReady(uri, contentType, null)
}
}
private fun from(
@ -165,8 +163,7 @@ class MediaCompressor {
contentType: String?,
context: Context,
): File {
val extension =
contentType?.let { MimeTypeMap.getSingleton().getExtensionFromMimeType(it) } ?: ""
val extension = contentType?.let { MimeTypeMap.getSingleton().getExtensionFromMimeType(it) } ?: ""
val inputStream = context.contentResolver.openInputStream(uri!!)
val fileName: String = UUID.randomUUID().toString() + ".$extension"