Fix assert fail during onSaveInstanceState()

Selected attachment from GalleryGridView will be destroyed when same
attachment is already existed in DraftMessageData. It will make assert
fail during onSaveInstanceState() because mDestroyed in MessagePartData
is true already.
It destroys existing attachment and replaces with new attachment instead
so that selected attachments could be maintained correctly.

Test: 1) Select one image in GalleryMediaChooser.
      2) Reopen the chooser and long-press same image again to enter to
      the multi-selection mode.
      3) Long-press the attachment on draft message to open
      AttachmentChooser.
      4) Check Assert fail.

Change-Id: I029d778779260d0097ce30bf5338fceba05e1f77
Signed-off-by: Taesu Lee <taesu82.lee@samsung.com>
This commit is contained in:
Taesu Lee
2020-03-31 13:32:52 +09:00
parent f19e916a0d
commit b41ce08cab

View File

@@ -339,11 +339,23 @@ public class DraftMessageData extends BindableData implements ReadDraftDataActio
*/
private boolean addOneAttachmentNoNotify(final MessagePartData attachment) {
Assert.isTrue(attachment.isAttachment());
// Check duplication.
for (final MessagePartData existingAttachment : mAttachments) {
if (existingAttachment.getContentUri().equals(attachment.getContentUri())) {
// Destroy existing attachment and replace with new attachment instead of destroying
// new one so that mSelectedImages in GalleryGridView could be maintained correctly.
mAttachments.remove(existingAttachment);
existingAttachment.destroyAsync();
addAttachment(attachment, null /*pendingAttachment*/);
return false;
}
}
final boolean reachedLimit = getAttachmentCount() >= getAttachmentLimit();
if (reachedLimit || containsAttachment(attachment.getContentUri())) {
// Never go over the limit. Never add duplicated attachments.
if (reachedLimit) {
// Never go over the limit.
attachment.destroyAsync();
return reachedLimit;
return true;
} else {
addAttachment(attachment, null /*pendingAttachment*/);
return false;