Skip to content

Commit

Permalink
fix: Attachments UI not correctly updating in Tablet mode
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinBoulongne committed Dec 12, 2024
1 parent 765a248 commit ce6904d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -78,13 +76,9 @@ class AttachmentAdapter(

override fun getItemCount(): Int = runCatchingRealm { attachments.count() }.getOrDefault(0)

fun setAttachments(newList: List<Attachable>) = runCatchingRealm {
fun submitList(newList: List<Attachable>) = runCatchingRealm {
attachments.clear()
attachments.addAll(newList)
}

fun submitList(newList: List<Attachment>) {
setAttachments(newList.filterNot { it.disposition == AttachmentDisposition.INLINE })
notifyDataSetChanged()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class ThreadAdapter(
bindHeader(message)
bindAlerts(message.uid)
bindCalendarEvent(message)
bindAttachment(message)
bindAttachments(message)
bindContent(message)

onExpandOrCollapseMessage(message, shouldTrack = false)
Expand Down Expand Up @@ -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
Expand All @@ -482,7 +482,7 @@ class ThreadAdapter(
)
}

attachmentAdapter.setAttachments(attachments)
attachmentAdapter.submitList(attachments)

attachmentLayout.attachmentsSizeText.text = totalAttachmentsSize
attachmentLayout.attachmentsInfo.setOnClickListener { threadAdapterCallbacks?.onDownloadAllClicked?.invoke(message) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit ce6904d

Please sign in to comment.