From bf0333ba31b02d4ff1a8f1b867df09aef5195be0 Mon Sep 17 00:00:00 2001 From: Valentin CAULIER Date: Mon, 16 Mar 2015 16:29:42 +0100 Subject: [PATCH] Beginning MessageReference update to immutable object --- .../fsck/k9/activity/MessageReference.java | 63 ++++++++++++++++--- 1 file changed, 56 insertions(+), 7 deletions(-) diff --git a/k9mail/src/main/java/com/fsck/k9/activity/MessageReference.java b/k9mail/src/main/java/com/fsck/k9/activity/MessageReference.java index 131b0715a..7d480dd88 100644 --- a/k9mail/src/main/java/com/fsck/k9/activity/MessageReference.java +++ b/k9mail/src/main/java/com/fsck/k9/activity/MessageReference.java @@ -20,12 +20,29 @@ public class MessageReference implements Parcelable { public String accountUuid; public String folderName; public String uid; - public Flag flag = null; + public Flag flag; /** + * @deprecated MessageReference should be immutable now, and this way, it won't be possible to modify it anymore + * * Initialize an empty MessageReference. */ + @Deprecated public MessageReference() { + this.accountUuid = null; + this.folderName = null; + this.uid = null; + this.flag = null; + } + + /** + * Initialize a new MessageReference. + */ + public MessageReference(String accountUuid, String folderName, String uid, Flag flag) { + this.accountUuid = accountUuid; + this.folderName = folderName; + this.uid = uid; + this.flag = flag; } // Version identifier for use when serializing. This will allow us to introduce future versions @@ -34,7 +51,7 @@ public class MessageReference implements Parcelable { private static final String IDENTITY_SEPARATOR = ":"; /** - * Initialize a MessageReference from a seraialized identity. + * Initialize a MessageReference from a serialized identity. * @param identity Serialized identity. * @throws MessagingException On missing or corrupted identity. */ @@ -61,6 +78,9 @@ public class MessageReference implements Parcelable { throw new MessagingException("Could not thaw message flag '" + flagString + "'", ie); } } + else { + flag = null; + } if (K9.DEBUG) Log.d(K9.LOG_TAG, "Thawed " + toString()); @@ -156,12 +176,17 @@ public class MessageReference implements Parcelable { public static final Creator CREATOR = new Creator() { @Override public MessageReference createFromParcel(Parcel source) { - MessageReference ref = new MessageReference(); - ref.uid = source.readString(); - ref.accountUuid = source.readString(); - ref.folderName = source.readString(); + MessageReference ref; + String uid = source.readString(); + String accountUuid = source.readString(); + String folderName = source.readString(); String flag = source.readString(); - if (flag != null) ref.flag = Flag.valueOf(flag); + if (flag != null){ + ref = new MessageReference(uid, accountUuid, folderName, Flag.valueOf(flag)); + } + else { + ref = new MessageReference(uid, accountUuid, folderName, null); + } return ref; } @@ -183,4 +208,28 @@ public class MessageReference implements Parcelable { dest.writeString(folderName); dest.writeString(flag == null ? null : flag.name()); } + + public String getAccountUuid(){ + return accountUuid; + } + + public String getFolderName(){ + return folderName; + } + + public String getUid(){ + return uid; + } + + public MessageReference withModifiedUid(String newUid){ + return new MessageReference(accountUuid, folderName, newUid, flag); + } + + public MessageReference withModifiedFlag(Flag newFlag){ + return new MessageReference(accountUuid, folderName, uid, newFlag); + } + + public Flag getFlag(){ + return flag; + } }