rebased to latest master

This commit is contained in:
gavine99
2025-02-17 19:10:59 +11:00
parent 0f6c2fb694
commit 94019f5e7a
18 changed files with 1220 additions and 131 deletions
@@ -47,6 +47,7 @@ import dev.octoshrimpy.quik.compat.TelephonyCompat
import dev.octoshrimpy.quik.extensions.anyOf
import dev.octoshrimpy.quik.extensions.isImage
import dev.octoshrimpy.quik.extensions.isVideo
import dev.octoshrimpy.quik.extensions.resourceExists
import dev.octoshrimpy.quik.manager.ActiveConversationManager
import dev.octoshrimpy.quik.manager.KeyManager
import dev.octoshrimpy.quik.model.Attachment
@@ -368,28 +369,31 @@ class MessageRepositoryImpl @Inject constructor(
parts += MMSPart("text", ContentType.TEXT_PLAIN, bytes)
}
// Attach those that can't be compressed (ie. everything but not images)
// Attach those that can't be compressed (ie. everything but images)
parts += attachments
// filter out images
// filter in non-images only
.filter { !it.isImage(context) }
// filter out items that have no data available (ie user may have deleted
// the file from storage)
.filter { it.getResourceBytes(context).isNotEmpty() }
// filter in only items that exist (user may have deleted the file)
.filter { it.uri.resourceExists(context) }
.map {
remainingBytes -= it.getResourceBytes(context).size
MMSPart(
val mmsPart = MMSPart(
it.getName(context),
it.getType(context),
it.getResourceBytes(context)
)
// release the attachment hold on the image bytes so the GC can reclaim
it.releaseResourceBytes()
mmsPart
}
val imageBytesByAttachment = attachments
// filter out non-images
// filter in images only
.filter { it.isImage(context) }
// filter out items that have no data available (ie user may have deleted
// the file from storage)
.filter { it.getResourceBytes(context).isNotEmpty() }
// filter in only items that exist (user may have deleted the file)
.filter { it.uri.resourceExists(context) }
.associateWith {
when (it.getType(context) == "image/gif") {
true -> ImageUtils.getScaledGif(context, it.uri, maxWidth, maxHeight)
@@ -434,6 +438,9 @@ class MessageRepositoryImpl @Inject constructor(
}
Timber.d("Compression attempt $attempts: ${scaledBytes.size / 1024}/${maxBytes.toInt() / 1024}Kb ($width*$height -> $newWidth*$newHeight)")
// release the attachment hold on the image bytes so the GC can reclaim
attachment.releaseResourceBytes()
}
Timber.v("Compressed ${originalBytes.size / 1024}Kb to ${scaledBytes.size / 1024}Kb with a target size of ${maxBytes.toInt() / 1024}Kb in $attempts attempts")