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
@@ -49,7 +49,13 @@ class MediaCompressor {
onError: (Int) -> Unit, onError: (Int) -> Unit,
mediaQuality: CompressorQuality, 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() checkNotInMainThread()
if (contentType?.startsWith("video", true) == true) { if (contentType?.startsWith("video", true) == true) {
@@ -122,11 +128,7 @@ class MediaCompressor {
} }
}, },
) )
} else if ( } else if (contentType?.startsWith("image", true) == true && !contentType.contains("gif") && !contentType.contains("svg")) {
contentType?.startsWith("image", true) == true &&
!contentType.contains("gif") &&
!contentType.contains("svg")
) {
val imageQuality = val imageQuality =
when (mediaQuality) { when (mediaQuality) {
CompressorQuality.VERY_LOW -> 40 CompressorQuality.VERY_LOW -> 40
@@ -154,10 +156,6 @@ class MediaCompressor {
} else { } else {
onReady(uri, contentType, null) 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( private fun from(
@@ -165,8 +163,7 @@ class MediaCompressor {
contentType: String?, contentType: String?,
context: Context, context: Context,
): File { ): File {
val extension = val extension = contentType?.let { MimeTypeMap.getSingleton().getExtensionFromMimeType(it) } ?: ""
contentType?.let { MimeTypeMap.getSingleton().getExtensionFromMimeType(it) } ?: ""
val inputStream = context.contentResolver.openInputStream(uri!!) val inputStream = context.contentResolver.openInputStream(uri!!)
val fileName: String = UUID.randomUUID().toString() + ".$extension" val fileName: String = UUID.randomUUID().toString() + ".$extension"