forked from upstream-mirrors/quik
#274 - Fixed image sending for GIFs
This commit is contained in:
@@ -25,8 +25,10 @@ import android.net.Uri
|
|||||||
import android.provider.Telephony
|
import android.provider.Telephony
|
||||||
import model.MmsPart
|
import model.MmsPart
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
import util.extensions.isImage
|
||||||
import util.extensions.isSmil
|
import util.extensions.isSmil
|
||||||
import util.extensions.isText
|
import util.extensions.isText
|
||||||
|
import util.extensions.isVideo
|
||||||
import java.io.BufferedReader
|
import java.io.BufferedReader
|
||||||
import java.io.InputStreamReader
|
import java.io.InputStreamReader
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@@ -46,8 +48,8 @@ class CursorToPartImpl @Inject constructor(private val context: Context) : Curso
|
|||||||
val data = from.getString(from.getColumnIndexOrThrow(Telephony.Mms.Part._DATA))
|
val data = from.getString(from.getColumnIndexOrThrow(Telephony.Mms.Part._DATA))
|
||||||
|
|
||||||
when {
|
when {
|
||||||
isSmil() -> {
|
isSmil() || isImage() || isVideo() -> {
|
||||||
// Do nothing
|
// Do nothing special
|
||||||
}
|
}
|
||||||
|
|
||||||
isText() -> {
|
isText() -> {
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ package interactor
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
import com.google.android.mms.ContentType
|
||||||
import com.klinker.android.send_message.Message
|
import com.klinker.android.send_message.Message
|
||||||
import com.klinker.android.send_message.Settings
|
import com.klinker.android.send_message.Settings
|
||||||
import com.klinker.android.send_message.Transaction
|
import com.klinker.android.send_message.Transaction
|
||||||
@@ -57,15 +58,26 @@ class SendMessage @Inject constructor(
|
|||||||
val settings = Settings()
|
val settings = Settings()
|
||||||
val message = Message(body, addresses.toTypedArray())
|
val message = Message(body, addresses.toTypedArray())
|
||||||
|
|
||||||
val bitmaps = attachments.map { uri -> RxImageConverters.uriToBitmap(context, uri).blockingFirst() }
|
// Add the GIFs as attachments. The app currently can't compress them, which may result
|
||||||
val totalBytes = bitmaps.sumBy { it.allocationByteCount }
|
// in a lot of these messages failing to send
|
||||||
|
// TODO Add support for GIF compression
|
||||||
|
attachments
|
||||||
|
.filter { uri -> context.contentResolver.getType(uri) == ContentType.IMAGE_GIF }
|
||||||
|
.map { uri -> context.contentResolver.openInputStream(uri) }
|
||||||
|
.map { inputStream -> inputStream.readBytes() }
|
||||||
|
.forEach { bitmap -> message.addMedia(bitmap, ContentType.IMAGE_GIF) }
|
||||||
|
|
||||||
bitmaps
|
// Compress the images and add them as attachments
|
||||||
|
var totalImageBytes = 0
|
||||||
|
attachments
|
||||||
|
.filter { uri -> context.contentResolver.getType(uri) != ContentType.IMAGE_GIF }
|
||||||
|
.map { uri -> RxImageConverters.uriToBitmap(context, uri).blockingFirst() }
|
||||||
|
.also { totalImageBytes = it.sumBy { it.allocationByteCount } }
|
||||||
.map { bitmap ->
|
.map { bitmap ->
|
||||||
val byteRatio = bitmap.allocationByteCount / totalBytes.toFloat()
|
val byteRatio = bitmap.allocationByteCount / totalImageBytes.toFloat()
|
||||||
shrink(bitmap, (prefs.mmsSize.get() * 1024 * byteRatio).toInt())
|
shrink(bitmap, (prefs.mmsSize.get() * 1024 * byteRatio).toInt())
|
||||||
}
|
}
|
||||||
.forEach { bitmap -> message.addMedia(bitmap, "image/jpeg") }
|
.forEach { bitmap -> message.addMedia(bitmap, ContentType.IMAGE_JPEG) }
|
||||||
|
|
||||||
val transaction = Transaction(context, settings)
|
val transaction = Transaction(context, settings)
|
||||||
transaction.sendNewMessage(message, threadId)
|
transaction.sendNewMessage(message, threadId)
|
||||||
|
|||||||
Reference in New Issue
Block a user