Loading data/src/main/java/com/moez/QKSMS/repository/MessageRepositoryImpl.kt +8 −3 Original line number Diff line number Diff line Loading @@ -235,10 +235,9 @@ class MessageRepositoryImpl @Inject constructor( parts += MMSPart("text", ContentType.TEXT_PLAIN, body.toByteArray()) } // Add the GIFs as attachments. The app currently can't compress them, which may result // in a lot of these messages failing to send // TODO Add support for GIF compression // Add the GIFs as attachments parts += attachments .mapNotNull { attachment -> attachment as? Attachment.Image } .filter { attachment -> attachment.isGif(context) } .mapNotNull { attachment -> attachment.getUri() } .map { uri -> ImageUtils.compressGif(context, uri, prefs.mmsSize.get() * 1024) } Loading @@ -247,6 +246,7 @@ class MessageRepositoryImpl @Inject constructor( // Compress the images and add them as attachments var totalImageBytes = 0 parts += attachments .mapNotNull { attachment -> attachment as? Attachment.Image } .filter { attachment -> !attachment.isGif(context) } .mapNotNull { attachment -> attachment.getUri() } .mapNotNull { uri -> tryOrNull { imageRepository.loadImage(uri) } } Loading @@ -257,6 +257,11 @@ class MessageRepositoryImpl @Inject constructor( } .map { bitmap -> MMSPart("image", ContentType.IMAGE_JPEG, bitmap) } // Send contacts parts += attachments .mapNotNull { attachment -> attachment as? Attachment.Contact } .map { attachment -> attachment.vCard.toByteArray() } .map { vCard -> MMSPart("contact", ContentType.TEXT_VCARD, vCard) } val transaction = Transaction(context) transaction.sendNewMessage(subId, threadId, addresses.map(PhoneNumberUtils::stripSeparators), parts, null) Loading domain/src/main/java/com/moez/QKSMS/interactor/SendScheduledMessage.kt +1 −1 Original line number Diff line number Diff line Loading @@ -47,7 +47,7 @@ class SendScheduledMessage @Inject constructor( } .map { message -> val threadId = TelephonyCompat.getOrCreateThreadId(context, message.recipients) val attachments = message.attachments.mapNotNull(Uri::parse).map { Attachment(it) } val attachments = message.attachments.mapNotNull(Uri::parse).map { Attachment.Image(it) } SendMessage.Params(message.subId, threadId, message.recipients, message.body, attachments) } .flatMap(sendMessage::buildObservable) Loading domain/src/main/java/com/moez/QKSMS/model/Attachment.kt +23 −13 Original line number Diff line number Diff line Loading @@ -23,7 +23,12 @@ import android.net.Uri import android.os.Build import androidx.core.view.inputmethod.InputContentInfoCompat data class Attachment(private val uri: Uri? = null, private val inputContent: InputContentInfoCompat? = null) { sealed class Attachment { data class Image( private val uri: Uri? = null, private val inputContent: InputContentInfoCompat? = null ) : Attachment() { fun getUri(): Uri? { return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) { Loading @@ -40,5 +45,10 @@ data class Attachment(private val uri: Uri? = null, private val inputContent: In context.contentResolver.getType(uri) == "image/gif" } } } data class Contact(val vCard: String) : Attachment() } class Attachments(attachments: List<Attachment>): List<Attachment> by attachments presentation/src/main/java/com/moez/QKSMS/feature/compose/AttachmentAdapter.kt +36 −4 Original line number Diff line number Diff line Loading @@ -25,22 +25,39 @@ import com.bumptech.glide.Glide import com.moez.QKSMS.R import com.moez.QKSMS.common.base.QkAdapter import com.moez.QKSMS.common.base.QkViewHolder import com.moez.QKSMS.extensions.mapNotNull import com.moez.QKSMS.model.Attachment import ezvcard.Ezvcard import io.reactivex.Observable import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.schedulers.Schedulers import io.reactivex.subjects.PublishSubject import io.reactivex.subjects.Subject import kotlinx.android.synthetic.main.attachment_list_item.view.* import kotlinx.android.synthetic.main.attachment_contact_list_item.view.* import kotlinx.android.synthetic.main.attachment_image_list_item.view.* import javax.inject.Inject class AttachmentAdapter @Inject constructor( private val context: Context ) : QkAdapter<Attachment>() { companion object { private const val VIEW_TYPE_IMAGE = 0 private const val VIEW_TYPE_CONTACT = 1 } val attachmentDeleted: Subject<Attachment> = PublishSubject.create() override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder { val view = LayoutInflater.from(parent.context).inflate(R.layout.attachment_list_item, parent, false) val inflater = LayoutInflater.from(parent.context) val view = when (viewType) { VIEW_TYPE_IMAGE -> inflater.inflate(R.layout.attachment_image_list_item, parent, false) .apply { thumbnailBounds.clipToOutline = true } view.thumbnailBounds.clipToOutline = true VIEW_TYPE_CONTACT -> inflater.inflate(R.layout.attachment_contact_list_item, parent, false) else -> null!! // Impossible } return QkViewHolder(view).apply { view.setOnClickListener { Loading @@ -54,7 +71,22 @@ class AttachmentAdapter @Inject constructor( val attachment = getItem(position) val view = holder.itemView Glide.with(context).load(attachment.getUri()).into(view.thumbnail) when (attachment) { is Attachment.Image -> Glide.with(context) .load(attachment.getUri()) .into(view.thumbnail) is Attachment.Contact -> Observable.just(attachment.vCard) .mapNotNull { vCard -> Ezvcard.parse(vCard).first() } .subscribeOn(Schedulers.computation()) .observeOn(AndroidSchedulers.mainThread()) .subscribe { vcard -> view.name?.text = vcard.formattedName.value } } } override fun getItemViewType(position: Int) = when (getItem(position)) { is Attachment.Image -> VIEW_TYPE_IMAGE is Attachment.Contact -> VIEW_TYPE_CONTACT } } No newline at end of file presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeActivity.kt +0 −1 Original line number Diff line number Diff line Loading @@ -65,7 +65,6 @@ import java.text.SimpleDateFormat import java.util.* import javax.inject.Inject class ComposeActivity : QkThemedActivity(), ComposeView { companion object { Loading Loading
data/src/main/java/com/moez/QKSMS/repository/MessageRepositoryImpl.kt +8 −3 Original line number Diff line number Diff line Loading @@ -235,10 +235,9 @@ class MessageRepositoryImpl @Inject constructor( parts += MMSPart("text", ContentType.TEXT_PLAIN, body.toByteArray()) } // Add the GIFs as attachments. The app currently can't compress them, which may result // in a lot of these messages failing to send // TODO Add support for GIF compression // Add the GIFs as attachments parts += attachments .mapNotNull { attachment -> attachment as? Attachment.Image } .filter { attachment -> attachment.isGif(context) } .mapNotNull { attachment -> attachment.getUri() } .map { uri -> ImageUtils.compressGif(context, uri, prefs.mmsSize.get() * 1024) } Loading @@ -247,6 +246,7 @@ class MessageRepositoryImpl @Inject constructor( // Compress the images and add them as attachments var totalImageBytes = 0 parts += attachments .mapNotNull { attachment -> attachment as? Attachment.Image } .filter { attachment -> !attachment.isGif(context) } .mapNotNull { attachment -> attachment.getUri() } .mapNotNull { uri -> tryOrNull { imageRepository.loadImage(uri) } } Loading @@ -257,6 +257,11 @@ class MessageRepositoryImpl @Inject constructor( } .map { bitmap -> MMSPart("image", ContentType.IMAGE_JPEG, bitmap) } // Send contacts parts += attachments .mapNotNull { attachment -> attachment as? Attachment.Contact } .map { attachment -> attachment.vCard.toByteArray() } .map { vCard -> MMSPart("contact", ContentType.TEXT_VCARD, vCard) } val transaction = Transaction(context) transaction.sendNewMessage(subId, threadId, addresses.map(PhoneNumberUtils::stripSeparators), parts, null) Loading
domain/src/main/java/com/moez/QKSMS/interactor/SendScheduledMessage.kt +1 −1 Original line number Diff line number Diff line Loading @@ -47,7 +47,7 @@ class SendScheduledMessage @Inject constructor( } .map { message -> val threadId = TelephonyCompat.getOrCreateThreadId(context, message.recipients) val attachments = message.attachments.mapNotNull(Uri::parse).map { Attachment(it) } val attachments = message.attachments.mapNotNull(Uri::parse).map { Attachment.Image(it) } SendMessage.Params(message.subId, threadId, message.recipients, message.body, attachments) } .flatMap(sendMessage::buildObservable) Loading
domain/src/main/java/com/moez/QKSMS/model/Attachment.kt +23 −13 Original line number Diff line number Diff line Loading @@ -23,7 +23,12 @@ import android.net.Uri import android.os.Build import androidx.core.view.inputmethod.InputContentInfoCompat data class Attachment(private val uri: Uri? = null, private val inputContent: InputContentInfoCompat? = null) { sealed class Attachment { data class Image( private val uri: Uri? = null, private val inputContent: InputContentInfoCompat? = null ) : Attachment() { fun getUri(): Uri? { return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) { Loading @@ -40,5 +45,10 @@ data class Attachment(private val uri: Uri? = null, private val inputContent: In context.contentResolver.getType(uri) == "image/gif" } } } data class Contact(val vCard: String) : Attachment() } class Attachments(attachments: List<Attachment>): List<Attachment> by attachments
presentation/src/main/java/com/moez/QKSMS/feature/compose/AttachmentAdapter.kt +36 −4 Original line number Diff line number Diff line Loading @@ -25,22 +25,39 @@ import com.bumptech.glide.Glide import com.moez.QKSMS.R import com.moez.QKSMS.common.base.QkAdapter import com.moez.QKSMS.common.base.QkViewHolder import com.moez.QKSMS.extensions.mapNotNull import com.moez.QKSMS.model.Attachment import ezvcard.Ezvcard import io.reactivex.Observable import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.schedulers.Schedulers import io.reactivex.subjects.PublishSubject import io.reactivex.subjects.Subject import kotlinx.android.synthetic.main.attachment_list_item.view.* import kotlinx.android.synthetic.main.attachment_contact_list_item.view.* import kotlinx.android.synthetic.main.attachment_image_list_item.view.* import javax.inject.Inject class AttachmentAdapter @Inject constructor( private val context: Context ) : QkAdapter<Attachment>() { companion object { private const val VIEW_TYPE_IMAGE = 0 private const val VIEW_TYPE_CONTACT = 1 } val attachmentDeleted: Subject<Attachment> = PublishSubject.create() override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder { val view = LayoutInflater.from(parent.context).inflate(R.layout.attachment_list_item, parent, false) val inflater = LayoutInflater.from(parent.context) val view = when (viewType) { VIEW_TYPE_IMAGE -> inflater.inflate(R.layout.attachment_image_list_item, parent, false) .apply { thumbnailBounds.clipToOutline = true } view.thumbnailBounds.clipToOutline = true VIEW_TYPE_CONTACT -> inflater.inflate(R.layout.attachment_contact_list_item, parent, false) else -> null!! // Impossible } return QkViewHolder(view).apply { view.setOnClickListener { Loading @@ -54,7 +71,22 @@ class AttachmentAdapter @Inject constructor( val attachment = getItem(position) val view = holder.itemView Glide.with(context).load(attachment.getUri()).into(view.thumbnail) when (attachment) { is Attachment.Image -> Glide.with(context) .load(attachment.getUri()) .into(view.thumbnail) is Attachment.Contact -> Observable.just(attachment.vCard) .mapNotNull { vCard -> Ezvcard.parse(vCard).first() } .subscribeOn(Schedulers.computation()) .observeOn(AndroidSchedulers.mainThread()) .subscribe { vcard -> view.name?.text = vcard.formattedName.value } } } override fun getItemViewType(position: Int) = when (getItem(position)) { is Attachment.Image -> VIEW_TYPE_IMAGE is Attachment.Contact -> VIEW_TYPE_CONTACT } } No newline at end of file
presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeActivity.kt +0 −1 Original line number Diff line number Diff line Loading @@ -65,7 +65,6 @@ import java.text.SimpleDateFormat import java.util.* import javax.inject.Inject class ComposeActivity : QkThemedActivity(), ComposeView { companion object { Loading