diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt index 629e6ed8..53e0320e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt @@ -673,11 +673,7 @@ class ThreadActivity : SimpleActivity() { loadAttachmentPreview(attachmentView, compressedUri) } else { toast(R.string.compress_error) - thread_attachments_wrapper.removeView(attachmentView) - attachmentSelections.remove(originalUriString) - if (attachmentSelections.isEmpty()) { - thread_attachments_holder.beGone() - } + removeAttachment(attachmentView, originalUriString) } checkSendMessageAvailability() attachmentView.thread_attachment_progress.beGone() @@ -691,11 +687,7 @@ class ThreadActivity : SimpleActivity() { val attachmentView = layoutInflater.inflate(R.layout.item_attachment, null).apply { thread_attachments_wrapper.addView(this) thread_remove_attachment.setOnClickListener { - thread_attachments_wrapper.removeView(this) - attachmentSelections.remove(originalUri) - if (attachmentSelections.isEmpty()) { - thread_attachments_holder.beGone() - } + removeAttachment(this, originalUri) } } @@ -734,6 +726,14 @@ class ThreadActivity : SimpleActivity() { .into(attachmentView.thread_attachment_preview) } + private fun removeAttachment(attachmentView: View, originalUri: String) { + thread_attachments_wrapper.removeView(attachmentView) + attachmentSelections.remove(originalUri) + if (attachmentSelections.isEmpty()) { + thread_attachments_holder.beGone() + } + } + private fun checkSendMessageAvailability() { if (thread_type_message.text.isNotEmpty() || (attachmentSelections.isNotEmpty() && !attachmentSelections.values.any { it.isPending })) { thread_send_message.isClickable = true