diff --git a/app/src/main/java/com/infomaniak/mail/ui/main/thread/AttachmentAdapter.kt b/app/src/main/java/com/infomaniak/mail/ui/main/thread/AttachmentAdapter.kt index bdf38f558a..0f92ec78e4 100644 --- a/app/src/main/java/com/infomaniak/mail/ui/main/thread/AttachmentAdapter.kt +++ b/app/src/main/java/com/infomaniak/mail/ui/main/thread/AttachmentAdapter.kt @@ -24,8 +24,6 @@ import androidx.recyclerview.widget.RecyclerView.Adapter import androidx.recyclerview.widget.RecyclerView.ViewHolder import com.infomaniak.mail.R import com.infomaniak.mail.data.models.Attachable -import com.infomaniak.mail.data.models.Attachment -import com.infomaniak.mail.data.models.Attachment.AttachmentDisposition import com.infomaniak.mail.databinding.ItemAttachmentBinding import com.infomaniak.mail.ui.main.thread.AttachmentAdapter.AttachmentViewHolder import com.infomaniak.mail.utils.Utils.runCatchingRealm @@ -78,13 +76,9 @@ class AttachmentAdapter( override fun getItemCount(): Int = runCatchingRealm { attachments.count() }.getOrDefault(0) - fun setAttachments(newList: List) = runCatchingRealm { + fun submitList(newList: List) = runCatchingRealm { attachments.clear() attachments.addAll(newList) - } - - fun submitList(newList: List) { - setAttachments(newList.filterNot { it.disposition == AttachmentDisposition.INLINE }) notifyDataSetChanged() } diff --git a/app/src/main/java/com/infomaniak/mail/ui/main/thread/ThreadAdapter.kt b/app/src/main/java/com/infomaniak/mail/ui/main/thread/ThreadAdapter.kt index 43f7fb04df..9e995ce30e 100644 --- a/app/src/main/java/com/infomaniak/mail/ui/main/thread/ThreadAdapter.kt +++ b/app/src/main/java/com/infomaniak/mail/ui/main/thread/ThreadAdapter.kt @@ -203,7 +203,7 @@ class ThreadAdapter( bindHeader(message) bindAlerts(message.uid) bindCalendarEvent(message) - bindAttachment(message) + bindAttachments(message) bindContent(message) onExpandOrCollapseMessage(message, shouldTrack = false) @@ -462,7 +462,7 @@ class ThreadAdapter( private fun ItemMessageBinding.areOneOrMoreAlertsVisible() = alerts.children.any { it.isVisible } @SuppressLint("SetTextI18n") - private fun MessageViewHolder.bindAttachment(message: Message) = with(binding) { + private fun MessageViewHolder.bindAttachments(message: Message) = with(binding) { if (!message.hasAttachable) { attachmentLayout.root.isVisible = false @@ -482,7 +482,7 @@ class ThreadAdapter( ) } - attachmentAdapter.setAttachments(attachments) + attachmentAdapter.submitList(attachments) attachmentLayout.attachmentsSizeText.text = totalAttachmentsSize attachmentLayout.attachmentsInfo.setOnClickListener { threadAdapterCallbacks?.onDownloadAllClicked?.invoke(message) } diff --git a/app/src/main/java/com/infomaniak/mail/ui/newMessage/NewMessageFragment.kt b/app/src/main/java/com/infomaniak/mail/ui/newMessage/NewMessageFragment.kt index c96697ca29..d81820bdc6 100644 --- a/app/src/main/java/com/infomaniak/mail/ui/newMessage/NewMessageFragment.kt +++ b/app/src/main/java/com/infomaniak/mail/ui/newMessage/NewMessageFragment.kt @@ -56,6 +56,7 @@ import com.infomaniak.mail.R import com.infomaniak.mail.data.LocalSettings import com.infomaniak.mail.data.LocalSettings.ExternalContent import com.infomaniak.mail.data.models.Attachment +import com.infomaniak.mail.data.models.Attachment.AttachmentDisposition import com.infomaniak.mail.data.models.draft.Draft import com.infomaniak.mail.data.models.draft.Draft.DraftAction import com.infomaniak.mail.data.models.draft.Draft.DraftMode @@ -601,7 +602,9 @@ class NewMessageFragment : Fragment() { // When removing an Attachment, both counts will be the same, because the Adapter is already notified. // We don't want to notify it again, because it will cancel the nice animation. - if (attachments.count() != attachmentAdapter.itemCount) attachmentAdapter.submitList(attachments) + if (attachments.count() != attachmentAdapter.itemCount) { + attachmentAdapter.submitList(attachments.filterNot { it.disposition == AttachmentDisposition.INLINE }) + } if (attachments.isEmpty()) TransitionManager.beginDelayedTransition(binding.root) binding.attachmentsRecyclerView.isVisible = attachments.isNotEmpty()