Fixes Issue 1341

Pass around simple Serializable MessageReference objects containing
account UUID, folder name and message UID so that MessageView can
traverse lists of messages which span folders and accounts.
This commit is contained in:
Daniel Applebaum 2010-04-24 14:59:27 +00:00
parent 35a73ea0b0
commit a2f4391501
3 changed files with 116 additions and 69 deletions

View file

@ -705,14 +705,23 @@ public class MessageList
else else
{ {
// Need to get the list before the sort starts // Need to get the list before the sort starts
ArrayList<String> messageUids = new ArrayList<String>(); ArrayList<MessageReference> messageRefs = new ArrayList<MessageReference>();
for (MessageInfoHolder holder : mAdapter.messages) for (MessageInfoHolder holder : mAdapter.messages)
{ {
messageUids.add(holder.uid); MessageReference ref = new MessageReference();
ref.accountUuid = holder.message.getFolder().getAccount().getUuid();
ref.folderName = holder.message.getFolder().getName();
ref.uid = holder.uid;
messageRefs.add(ref);
} }
MessageReference ref = new MessageReference();
ref.accountUuid = message.message.getFolder().getAccount().getUuid();
ref.folderName = message.message.getFolder().getName();
ref.uid = message.uid;
Log.i(K9.LOG_TAG, "MessageList sending message " + ref);
MessageView.actionView(this, message.account, message.folder.name, message.uid, messageUids); MessageView.actionView(this, ref, messageRefs);
} }
/* /*
* We set read=true here for UI performance reasons. The actual value will * We set read=true here for UI performance reasons. The actual value will

View file

@ -0,0 +1,34 @@
package com.fsck.k9.activity;
import java.io.Serializable;
public class MessageReference implements Serializable
{
String accountUuid;
String folderName;
String uid;
public boolean equals(Object o)
{
if (o instanceof MessageReference == false)
{
return false;
}
MessageReference other = (MessageReference)o;
if ((accountUuid == other.accountUuid || (accountUuid != null && accountUuid.equals(other.accountUuid)))
&& (folderName == other.folderName || (folderName != null && folderName.equals(other.folderName)))
&& (uid == other.uid || (uid != null && uid.equals(other.uid))))
{
return true;
}
return false;
}
public String toString()
{
return "MessageReference{accountUuid = '" +
accountUuid
+ "', folderName = '" + folderName
+ "', uid = '" + uid
+ "'}";
}
}

View file

@ -41,10 +41,8 @@ import java.util.List;
public class MessageView extends K9Activity implements OnClickListener public class MessageView extends K9Activity implements OnClickListener
{ {
private static final String EXTRA_ACCOUNT = "com.fsck.k9.MessageView_account"; private static final String EXTRA_MESSAGE_REFERENCE = "com.fsck.k9.MessageView_messageReference";
private static final String EXTRA_FOLDER = "com.fsck.k9.MessageView_folder"; private static final String EXTRA_MESSAGE_REFERENCES = "com.fsck.k9.MessageView_messageReferences";
private static final String EXTRA_MESSAGE = "com.fsck.k9.MessageView_message";
private static final String EXTRA_MESSAGE_UIDS = "com.fsck.k9.MessageView_messageUids";
private static final String EXTRA_NEXT = "com.fsck.k9.MessageView_next"; private static final String EXTRA_NEXT = "com.fsck.k9.MessageView_next";
private static final int ACTIVITY_CHOOSE_FOLDER_MOVE = 1; private static final int ACTIVITY_CHOOSE_FOLDER_MOVE = 1;
@ -70,9 +68,8 @@ public class MessageView extends K9Activity implements OnClickListener
View previous_scrolling; View previous_scrolling;
private Account mAccount; private Account mAccount;
private String mFolder; private MessageReference mMessageReference;
private String mMessageUid; private ArrayList<MessageReference> mMessageReferences;
private ArrayList<String> mMessageUids;
private Message mMessage; private Message mMessage;
@ -82,8 +79,8 @@ public class MessageView extends K9Activity implements OnClickListener
private int mLastDirection = PREVIOUS; private int mLastDirection = PREVIOUS;
private String mNextMessageUid = null; private MessageReference mNextMessage = null;
private String mPreviousMessageUid = null; private MessageReference mPreviousMessage = null;
@ -410,18 +407,16 @@ public class MessageView extends K9Activity implements OnClickListener
public ImageView iconView; public ImageView iconView;
} }
public static void actionView(Context context, Account account, String folder, String messageUid, ArrayList<String> folderUids) public static void actionView(Context context, MessageReference messRef, List<MessageReference> messReferences)
{ {
actionView(context, account, folder, messageUid, folderUids, null); actionView(context, messRef, messReferences, null);
} }
public static void actionView(Context context, Account account, String folder, String messageUid, ArrayList<String> folderUids, Bundle extras) public static void actionView(Context context, MessageReference messRef, List<MessageReference> messReferences, Bundle extras)
{ {
Intent i = new Intent(context, MessageView.class); Intent i = new Intent(context, MessageView.class);
i.putExtra(EXTRA_ACCOUNT, account.getUuid()); i.putExtra(EXTRA_MESSAGE_REFERENCE, messRef);
i.putExtra(EXTRA_FOLDER, folder); i.putExtra(EXTRA_MESSAGE_REFERENCES, (Serializable)messReferences);
i.putExtra(EXTRA_MESSAGE, messageUid);
i.putExtra(EXTRA_MESSAGE_UIDS, folderUids);
if (extras != null) if (extras != null)
{ {
i.putExtras(extras); i.putExtras(extras);
@ -517,21 +512,15 @@ public class MessageView extends K9Activity implements OnClickListener
if (icicle!=null) if (icicle!=null)
{ {
String accountUuid = icicle.getString(EXTRA_ACCOUNT); mMessageReference = (MessageReference)icicle.getSerializable(EXTRA_MESSAGE_REFERENCE);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid); mMessageReferences = (ArrayList<MessageReference>)icicle.getSerializable(EXTRA_MESSAGE_REFERENCES);
mFolder = icicle.getString(EXTRA_FOLDER);
mMessageUid = icicle.getString(EXTRA_MESSAGE);
mMessageUids = icicle.getStringArrayList(EXTRA_MESSAGE_UIDS);
} }
else else
{ {
if (uri==null) if (uri==null)
{ {
String accountUuid = intent.getStringExtra(EXTRA_ACCOUNT); mMessageReference = (MessageReference)intent.getSerializableExtra(EXTRA_MESSAGE_REFERENCE);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid); mMessageReferences = (ArrayList<MessageReference>)intent.getSerializableExtra(EXTRA_MESSAGE_REFERENCES);
mFolder = intent.getStringExtra(EXTRA_FOLDER);
mMessageUid = intent.getStringExtra(EXTRA_MESSAGE);
mMessageUids = intent.getStringArrayListExtra(EXTRA_MESSAGE_UIDS);
} }
else else
{ {
@ -556,9 +545,13 @@ public class MessageView extends K9Activity implements OnClickListener
Toast.makeText(this, "Invalid account id: " + accountId, Toast.LENGTH_LONG).show(); Toast.makeText(this, "Invalid account id: " + accountId, Toast.LENGTH_LONG).show();
return; return;
} }
mFolder = segmentList.get(1);
mMessageUid = segmentList.get(2); mMessageReference = new MessageReference();
mMessageUids = new ArrayList<String>(); mMessageReference.accountUuid = mAccount.getUuid();
mMessageReference.folderName = segmentList.get(1);
mMessageReference.uid = segmentList.get(2);
mMessageReferences = new ArrayList<MessageReference>();
} }
else else
{ {
@ -568,6 +561,8 @@ public class MessageView extends K9Activity implements OnClickListener
} }
} }
} }
if (K9.DEBUG)
Log.d(K9.LOG_TAG, "MessageView got message " + mMessageReference);
next = findViewById(R.id.next); next = findViewById(R.id.next);
previous = findViewById(R.id.previous); previous = findViewById(R.id.previous);
@ -584,7 +579,8 @@ public class MessageView extends K9Activity implements OnClickListener
{ {
next.requestFocus(); next.requestFocus();
} }
// Perhaps the hideButtons should be global, instead of account-specific
mAccount = Preferences.getPreferences(this).getAccount(mMessageReference.accountUuid);
Account.HideButtons hideButtons = mAccount.getHideMessageViewButtons(); Account.HideButtons hideButtons = mAccount.getHideMessageViewButtons();
//MessagingController.getInstance(getApplication()).addListener(mListener); //MessagingController.getInstance(getApplication()).addListener(mListener);
@ -608,21 +604,24 @@ public class MessageView extends K9Activity implements OnClickListener
showButtons(); showButtons();
} }
} }
displayMessage(mMessageUid); displayMessage(mMessageReference);
} }
@Override @Override
protected void onSaveInstanceState(Bundle outState) protected void onSaveInstanceState(Bundle outState)
{ {
outState.putString(EXTRA_ACCOUNT, mAccount.getUuid()); outState.putSerializable(EXTRA_MESSAGE_REFERENCE, mMessageReference);
outState.putString(EXTRA_FOLDER, mFolder); outState.putSerializable(EXTRA_MESSAGE_REFERENCES, mMessageReferences);
outState.putString(EXTRA_MESSAGE, mMessageUid);
outState.putStringArrayList(EXTRA_MESSAGE_UIDS, mMessageUids);
} }
private void displayMessage(String uid) private void displayMessage(MessageReference ref)
{ {
mMessageUid = uid; mMessageReference = ref;
if (K9.DEBUG)
Log.d(K9.LOG_TAG, "MessageView displaying message " + mMessageReference);
mAccount = Preferences.getPreferences(this).getAccount(ref.accountUuid);
mMessageContentView.getSettings().setBlockNetworkImage(true); mMessageContentView.getSettings().setBlockNetworkImage(true);
K9.setBlockNetworkLoads(mMessageContentView.getSettings(), true); K9.setBlockNetworkLoads(mMessageContentView.getSettings(), true);
@ -630,8 +629,8 @@ public class MessageView extends K9Activity implements OnClickListener
findSurroundingMessagesUid(); findSurroundingMessagesUid();
boolean enableNext = (mNextMessageUid != null); boolean enableNext = (mNextMessage != null);
boolean enablePrev = (mPreviousMessageUid != null); boolean enablePrev = (mPreviousMessage != null);
if (next.isEnabled() != enableNext) if (next.isEnabled() != enableNext)
next.setEnabled(enableNext); next.setEnabled(enableNext);
@ -645,8 +644,8 @@ public class MessageView extends K9Activity implements OnClickListener
MessagingController.getInstance(getApplication()).loadMessageForView( MessagingController.getInstance(getApplication()).loadMessageForView(
mAccount, mAccount,
mFolder, mMessageReference.folderName,
mMessageUid, mMessageReference.uid,
mListener); mListener);
mTopView.scrollTo(0, 0); mTopView.scrollTo(0, 0);
@ -683,14 +682,14 @@ public class MessageView extends K9Activity implements OnClickListener
private void findSurroundingMessagesUid() private void findSurroundingMessagesUid()
{ {
mNextMessageUid = mPreviousMessageUid = null; mNextMessage = mPreviousMessage = null;
int i = mMessageUids.indexOf(mMessageUid); int i = mMessageReferences.indexOf(mMessageReference);
if (i < 0) if (i < 0)
return; return;
if (i != 0) if (i != 0)
mNextMessageUid = mMessageUids.get(i - 1); mNextMessage = mMessageReferences.get(i - 1);
if (i != (mMessageUids.size() - 1)) if (i != (mMessageReferences.size() - 1))
mPreviousMessageUid = mMessageUids.get(i + 1); mPreviousMessage = mMessageReferences.get(i + 1);
} }
@Override @Override
@ -708,25 +707,25 @@ public class MessageView extends K9Activity implements OnClickListener
findSurroundingMessagesUid(); findSurroundingMessagesUid();
// Remove this message's Uid locally // Remove this message's Uid locally
mMessageUids.remove(messageToDelete.getUid()); mMessageReferences.remove(messageToDelete.getUid());
MessagingController.getInstance(getApplication()).deleteMessages( MessagingController.getInstance(getApplication()).deleteMessages(
new Message[] { messageToDelete }, new Message[] { messageToDelete },
null); null);
if (mLastDirection == NEXT && mNextMessageUid != null) if (mLastDirection == NEXT && mNextMessage != null)
{ {
onNext(K9.isAnimations()); onNext(K9.isAnimations());
} }
else if (mLastDirection == PREVIOUS && mPreviousMessageUid != null) else if (mLastDirection == PREVIOUS && mPreviousMessage != null)
{ {
onPrevious(K9.isAnimations()); onPrevious(K9.isAnimations());
} }
else if (mNextMessageUid != null) else if (mNextMessage != null)
{ {
onNext(K9.isAnimations()); onNext(K9.isAnimations());
} }
else if (mPreviousMessageUid != null) else if (mPreviousMessage != null)
{ {
onPrevious(K9.isAnimations()); onPrevious(K9.isAnimations());
} }
@ -835,8 +834,8 @@ public class MessageView extends K9Activity implements OnClickListener
} }
Intent intent = new Intent(this, ChooseFolder.class); Intent intent = new Intent(this, ChooseFolder.class);
intent.putExtra(ChooseFolder.EXTRA_ACCOUNT, mAccount.getUuid()); intent.putExtra(ChooseFolder.EXTRA_ACCOUNT, mAccount.getUuid());
intent.putExtra(ChooseFolder.EXTRA_CUR_FOLDER, mFolder); intent.putExtra(ChooseFolder.EXTRA_CUR_FOLDER, mMessageReference.folderName);
intent.putExtra(ChooseFolder.EXTRA_MESSAGE_UID, mMessageUid); intent.putExtra(ChooseFolder.EXTRA_MESSAGE_UID, mMessageReference);
startActivityForResult(intent, ACTIVITY_CHOOSE_FOLDER_MOVE); startActivityForResult(intent, ACTIVITY_CHOOSE_FOLDER_MOVE);
} }
@ -854,8 +853,8 @@ public class MessageView extends K9Activity implements OnClickListener
} }
Intent intent = new Intent(this, ChooseFolder.class); Intent intent = new Intent(this, ChooseFolder.class);
intent.putExtra(ChooseFolder.EXTRA_ACCOUNT, mAccount.getUuid()); intent.putExtra(ChooseFolder.EXTRA_ACCOUNT, mAccount.getUuid());
intent.putExtra(ChooseFolder.EXTRA_CUR_FOLDER, mFolder); intent.putExtra(ChooseFolder.EXTRA_CUR_FOLDER, mMessageReference.folderName);
intent.putExtra(ChooseFolder.EXTRA_MESSAGE_UID, mMessageUid); intent.putExtra(ChooseFolder.EXTRA_MESSAGE_UID, mMessageReference);
startActivityForResult(intent, ACTIVITY_CHOOSE_FOLDER_COPY); startActivityForResult(intent, ACTIVITY_CHOOSE_FOLDER_COPY);
} }
@ -875,7 +874,7 @@ public class MessageView extends K9Activity implements OnClickListener
String srcFolderName = data.getStringExtra(ChooseFolder.EXTRA_CUR_FOLDER); String srcFolderName = data.getStringExtra(ChooseFolder.EXTRA_CUR_FOLDER);
String uid = data.getStringExtra(ChooseFolder.EXTRA_MESSAGE_UID); String uid = data.getStringExtra(ChooseFolder.EXTRA_MESSAGE_UID);
if (uid.equals(mMessageUid) && srcFolderName.equals(mFolder)) if (uid.equals(mMessageReference) && srcFolderName.equals(mMessageReference.folderName))
{ {
switch (requestCode) switch (requestCode)
@ -906,7 +905,7 @@ public class MessageView extends K9Activity implements OnClickListener
@Override @Override
protected void onNext(boolean animate) protected void onNext(boolean animate)
{ {
if (mNextMessageUid == null) if (mNextMessage == null)
{ {
Toast.makeText(this, getString(R.string.end_of_folder), Toast.LENGTH_SHORT).show(); Toast.makeText(this, getString(R.string.end_of_folder), Toast.LENGTH_SHORT).show();
return; return;
@ -916,14 +915,14 @@ public class MessageView extends K9Activity implements OnClickListener
{ {
mTopView.startAnimation(outToLeftAnimation()); mTopView.startAnimation(outToLeftAnimation());
} }
displayMessage(mNextMessageUid); displayMessage(mNextMessage);
next.requestFocus(); next.requestFocus();
} }
@Override @Override
protected void onPrevious(boolean animate) protected void onPrevious(boolean animate)
{ {
if (mPreviousMessageUid == null) if (mPreviousMessage == null)
{ {
Toast.makeText(this, getString(R.string.end_of_folder), Toast.LENGTH_SHORT).show(); Toast.makeText(this, getString(R.string.end_of_folder), Toast.LENGTH_SHORT).show();
return; return;
@ -934,7 +933,7 @@ public class MessageView extends K9Activity implements OnClickListener
{ {
mTopView.startAnimation(inFromRightAnimation()); mTopView.startAnimation(inFromRightAnimation());
} }
displayMessage(mPreviousMessageUid); displayMessage(mPreviousMessage);
previous.requestFocus(); previous.requestFocus();
} }
@ -944,7 +943,7 @@ public class MessageView extends K9Activity implements OnClickListener
{ {
MessagingController.getInstance(getApplication()).setFlag( MessagingController.getInstance(getApplication()).setFlag(
mAccount, mAccount,
mFolder, mMessageReference.folderName,
new String[] { mMessage.getUid() }, new String[] { mMessage.getUid() },
Flag.SEEN, Flag.SEEN,
false); false);
@ -1324,7 +1323,8 @@ public class MessageView extends K9Activity implements OnClickListener
public void loadMessageForViewHeadersAvailable(Account account, String folder, String uid, public void loadMessageForViewHeadersAvailable(Account account, String folder, String uid,
final Message message) final Message message)
{ {
if (!mMessageUid.equals(uid)) if (!mMessageReference.uid.equals(uid) || !mMessageReference.folderName.equals(folder)
|| !mMessageReference.accountUuid.equals(account.getUuid()))
{ {
return; return;
} }
@ -1358,7 +1358,8 @@ public class MessageView extends K9Activity implements OnClickListener
public void loadMessageForViewBodyAvailable(Account account, String folder, String uid, public void loadMessageForViewBodyAvailable(Account account, String folder, String uid,
Message message) Message message)
{ {
if (!mMessageUid.equals(uid)) if (!mMessageReference.uid.equals(uid) || !mMessageReference.folderName.equals(folder)
|| !mMessageReference.accountUuid.equals(account.getUuid()))
{ {
return; return;
} }
@ -1445,7 +1446,8 @@ public class MessageView extends K9Activity implements OnClickListener
public void loadMessageForViewFailed(Account account, String folder, String uid, public void loadMessageForViewFailed(Account account, String folder, String uid,
final Throwable t) final Throwable t)
{ {
if (!mMessageUid.equals(uid)) if (!mMessageReference.uid.equals(uid) || !mMessageReference.folderName.equals(folder)
|| !mMessageReference.accountUuid.equals(account.getUuid()))
{ {
return; return;
} }
@ -1475,7 +1477,8 @@ public class MessageView extends K9Activity implements OnClickListener
public void loadMessageForViewFinished(Account account, String folder, String uid, public void loadMessageForViewFinished(Account account, String folder, String uid,
Message message) Message message)
{ {
if (!mMessageUid.equals(uid)) if (!mMessageReference.uid.equals(uid) || !mMessageReference.folderName.equals(folder)
|| !mMessageReference.accountUuid.equals(account.getUuid()))
{ {
return; return;
} }
@ -1492,7 +1495,8 @@ public class MessageView extends K9Activity implements OnClickListener
@Override @Override
public void loadMessageForViewStarted(Account account, String folder, String uid) public void loadMessageForViewStarted(Account account, String folder, String uid)
{ {
if (!mMessageUid.equals(uid)) if (!mMessageReference.uid.equals(uid) || !mMessageReference.folderName.equals(folder)
|| !mMessageReference.accountUuid.equals(account.getUuid()))
{ {
return; return;
} }