Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Attachments UI not correctly updating in Tablet mode #2120

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading