Merge "Make it clear that args are immutable"

This commit is contained in:
Todd Kennedy 2011-05-26 16:51:10 -07:00 committed by Android (Google) Code Review
commit 6d4f0d8fa0
3 changed files with 58 additions and 34 deletions

View File

@ -232,17 +232,28 @@ public class MailboxListFragment extends ListFragment implements OnItemClickList
return instance;
}
// Cached arguments. DO NOT use them directly. ALWAYS use getXxxIdArg().
private boolean mArgCacheInitialized;
private long mCachedAccountId;
private long mCachedParentMailboxId;
/**
* The account ID the mailbox is associated with. Do not use directly; instead, use
* {@link #getAccountId()}.
* <p><em>NOTE:</em> Although we cannot force these to be immutable using Java language
* constructs, this <em>must</em> be considered immutable.
*/
private Long mImmutableAccountId;
/**
* We will display the children of this mailbox. May be {@link Mailbox#NO_MAILBOX} to display
* all of the top-level mailboxes. Do NOT use directly; instead, use
* {@link #getParentMailboxId()}.
* <p><em>NOTE:</em> Although we cannot force these to be immutable using Java language
* constructs, this <em>must</em> be considered immutable.
*/
private Long mImmutableParentMailboxId;
private void initializeArgCache() {
if (!mArgCacheInitialized) {
mArgCacheInitialized = true;
mCachedAccountId = getArguments().getLong(ARG_ACCOUNT_ID);
mCachedParentMailboxId = getArguments().getLong(ARG_PARENT_MAILBOX_ID);
}
if (mImmutableAccountId != null) return;
mImmutableAccountId
= getArguments().getLong(ARG_ACCOUNT_ID, Account.NO_ACCOUNT);
mImmutableParentMailboxId
= getArguments().getLong(ARG_PARENT_MAILBOX_ID, Mailbox.NO_MAILBOX);
}
/**
@ -250,7 +261,7 @@ public class MailboxListFragment extends ListFragment implements OnItemClickList
*/
public long getAccountId() {
initializeArgCache();
return mCachedAccountId;
return mImmutableAccountId;
}
/**
@ -258,7 +269,7 @@ public class MailboxListFragment extends ListFragment implements OnItemClickList
*/
public long getParentMailboxId() {
initializeArgCache();
return mCachedParentMailboxId;
return mImmutableParentMailboxId;
}
/**

View File

@ -277,17 +277,26 @@ public class MessageListFragment extends ListFragment
return instance;
}
// Cached arguments. DO NOT use them directly. ALWAYS use getXxxIdArg().
private boolean mArgCacheInitialized;
private long mCachedAccountId;
private long mCachedMailboxId;
/**
* The account ID the mailbox is associated with. Do not use directly; instead, use
* {@link #getAccountId()}.
* <p><em>NOTE:</em> Although we cannot force these to be immutable using Java language
* constructs, this <em>must</em> be considered immutable.
*/
private Long mImmutableAccountId;
/**
* We will display the messages contained by this mailbox. May be one of the special mailbox
* constants such as {@link Mailbox#QUERY_ALL_INBOXES} for combined views. Do NOT use directly;
* instead, use {@link #getMailboxId()}.
* <p><em>NOTE:</em> Although we cannot force these to be immutable using Java language
* constructs, this <em>must</em> be considered immutable.
*/
private Long mImmutableMailboxId;
private void initializeArgCache() {
if (!mArgCacheInitialized) {
mArgCacheInitialized = true;
mCachedAccountId = getArguments().getLong(ARG_ACCOUNT_ID);
mCachedMailboxId = getArguments().getLong(ARG_MAILBOX_ID);
}
if (mImmutableAccountId != null) return;
mImmutableAccountId = getArguments().getLong(ARG_ACCOUNT_ID);
mImmutableMailboxId = getArguments().getLong(ARG_MAILBOX_ID);
}
/**
@ -297,7 +306,7 @@ public class MessageListFragment extends ListFragment
*/
public long getAccountId() {
initializeArgCache();
return mCachedAccountId;
return mImmutableAccountId;
}
/**
@ -305,7 +314,7 @@ public class MessageListFragment extends ListFragment
*/
public long getMailboxId() {
initializeArgCache();
return mCachedMailboxId;
return mImmutableMailboxId;
}
/**
@ -724,10 +733,11 @@ public class MessageListFragment extends ListFragment
/**
* Called when a message on the list is selected
*
* @param messageMailboxId the actual mailbox ID of the message. Note it's different from
* {@link #mMailboxId} in combined mailboxes. ({@link #mMailboxId} can take values such as
* {@link Mailbox#QUERY_ALL_INBOXES})
* @param messageId ID of the msesage to open.
* @param messageMailboxId the actual mailbox ID of the message. Note it's different than
* what is returned by {@link #getMailboxId()} for combined mailboxes.
* ({@link #getMailboxId()} may return special mailbox values such as
* {@link Mailbox#QUERY_ALL_INBOXES})
* @param messageId ID of the message to open.
*/
private void onMessageOpen(final long messageMailboxId, final long messageId) {
new MessageOpenTask(messageMailboxId, messageId).cancelPreviousAndExecuteParallel();

View File

@ -20,6 +20,7 @@ import com.android.email.Email;
import com.android.email.R;
import com.android.emailcommon.mail.MeetingInfo;
import com.android.emailcommon.mail.PackedString;
import com.android.emailcommon.provider.EmailContent.Account;
import com.android.emailcommon.provider.EmailContent.Message;
import com.android.emailcommon.provider.Mailbox;
import com.android.emailcommon.service.EmailServiceConstants;
@ -136,15 +137,17 @@ public class MessageViewFragment extends MessageViewFragmentBase
return instance;
}
// Cached argument. DO NOT use them directly. ALWAYS use getXxxIdArg().
private boolean mArgCacheInitialized;
private long mCachedMessageId;
/**
* We will display the message for this ID. This must never be a special message ID such as
* {@link Message#NO_MESSAGE}. Do NOT use directly; instead, use {@link #getMessageId()}.
* <p><em>NOTE:</em> Although we cannot force these to be immutable using Java language
* constructs, this <em>must</em> be considered immutable.
*/
private Long mImmutableMessageId;
private void initializeArgCache() {
if (!mArgCacheInitialized) {
mArgCacheInitialized = true;
mCachedMessageId = getArguments().getLong(ARG_MESSAGE_ID);
}
if (mImmutableMessageId != null) return;
mImmutableMessageId = getArguments().getLong(ARG_MESSAGE_ID);
}
/**
@ -152,7 +155,7 @@ public class MessageViewFragment extends MessageViewFragmentBase
*/
public long getMessageId() {
initializeArgCache();
return mCachedMessageId;
return mImmutableMessageId;
}
@Override