Inject the context in the constructor
This commit is contained in:
parent
afa3149504
commit
c794843bb2
@ -28,9 +28,8 @@ import java.io.File
|
|||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
internal class ImageCompressor @Inject constructor() {
|
internal class ImageCompressor @Inject constructor(private val context: Context) {
|
||||||
suspend fun compress(
|
suspend fun compress(
|
||||||
context: Context,
|
|
||||||
imageFile: File,
|
imageFile: File,
|
||||||
desiredWidth: Int,
|
desiredWidth: Int,
|
||||||
desiredHeight: Int,
|
desiredHeight: Int,
|
||||||
@ -46,7 +45,7 @@ internal class ImageCompressor @Inject constructor() {
|
|||||||
}
|
}
|
||||||
} ?: return@withContext imageFile
|
} ?: return@withContext imageFile
|
||||||
|
|
||||||
val destinationFile = createDestinationFile(context)
|
val destinationFile = createDestinationFile()
|
||||||
|
|
||||||
runCatching {
|
runCatching {
|
||||||
destinationFile.outputStream().use {
|
destinationFile.outputStream().use {
|
||||||
@ -118,7 +117,7 @@ internal class ImageCompressor @Inject constructor() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createDestinationFile(context: Context): File {
|
private fun createDestinationFile(): File {
|
||||||
return File.createTempFile(UUID.randomUUID().toString(), null, context.cacheDir)
|
return File.createTempFile(UUID.randomUUID().toString(), null, context.cacheDir)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -156,7 +156,7 @@ internal class UploadContentWorker(val context: Context, params: WorkerParameter
|
|||||||
// Do not compress gif
|
// Do not compress gif
|
||||||
&& attachment.mimeType != MimeTypes.Gif
|
&& attachment.mimeType != MimeTypes.Gif
|
||||||
&& params.compressBeforeSending) {
|
&& params.compressBeforeSending) {
|
||||||
fileToUpload = imageCompressor.compress(context, workingFile, MAX_IMAGE_SIZE, MAX_IMAGE_SIZE)
|
fileToUpload = imageCompressor.compress(workingFile, MAX_IMAGE_SIZE, MAX_IMAGE_SIZE)
|
||||||
.also { compressedFile ->
|
.also { compressedFile ->
|
||||||
// Get new Bitmap size
|
// Get new Bitmap size
|
||||||
compressedFile.inputStream().use {
|
compressedFile.inputStream().use {
|
||||||
|
Loading…
Reference in New Issue
Block a user