1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-12-23 16:18:50 -05:00

Updating other classes to use new constructor and getters of

MessageReference
This commit is contained in:
Valentin CAULIER 2015-03-16 16:30:28 +01:00
parent bf0333ba31
commit 3e84c20c9b
8 changed files with 70 additions and 89 deletions

View File

@ -71,7 +71,8 @@ public class MessageReferenceTest {
@Test
public void equalsWithAnObjectShouldReturnFalse() {
MessageReference messageReference = new MessageReference();
// null : creating a new empty MessageReference
MessageReference messageReference = new MessageReference(null, null, null, null);
Object object = new Object();
assertFalse(messageReference.equals(object));
@ -125,21 +126,14 @@ public class MessageReferenceTest {
}
private MessageReference createMessageReference(String accountUuid, String folderName, String uid) {
MessageReference messageReference = new MessageReference();
messageReference.accountUuid = accountUuid;
messageReference.folderName = folderName;
messageReference.uid = uid;
MessageReference messageReference = new MessageReference(accountUuid, folderName, uid, null);
return messageReference;
}
private MessageReference createMessageReferenceWithFlag(String accountUuid, String folderName, String uid,
Flag flag) {
MessageReference messageReference = new MessageReference();
messageReference.accountUuid = accountUuid;
messageReference.folderName = folderName;
messageReference.uid = uid;
messageReference.flag = flag;
MessageReference messageReference = new MessageReference(accountUuid, folderName, uid, flag);
return messageReference;
}

View File

@ -544,7 +544,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
}
final String accountUuid = (mMessageReference != null) ?
mMessageReference.accountUuid :
mMessageReference.getAccountUuid() :
intent.getStringExtra(EXTRA_ACCOUNT);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
@ -786,9 +786,9 @@ public class MessageCompose extends K9Activity implements OnClickListener,
*/
MessagingController.getInstance(getApplication()).addListener(mListener);
final Account account = Preferences.getPreferences(this).getAccount(mMessageReference.accountUuid);
final String folderName = mMessageReference.folderName;
final String sourceMessageUid = mMessageReference.uid;
final Account account = Preferences.getPreferences(this).getAccount(mMessageReference.getAccountUuid());
final String folderName = mMessageReference.getFolderName();
final String sourceMessageUid = mMessageReference.getUid();
MessagingController.getInstance(getApplication()).loadMessageForView(account, folderName, sourceMessageUid, null);
}
@ -798,7 +798,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
}
if (mAction == Action.REPLY || mAction == Action.REPLY_ALL) {
mMessageReference.flag = Flag.ANSWERED;
mMessageReference = mMessageReference.withModifiedFlag(Flag.ANSWERED);
}
if (mAction == Action.REPLY || mAction == Action.REPLY_ALL ||
@ -811,7 +811,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
}
if (mAction == Action.FORWARD) {
mMessageReference.flag = Flag.FORWARDED;
mMessageReference = mMessageReference.withModifiedFlag(Flag.FORWARDED);
}
mEncryptLayout = findViewById(R.id.layout_encrypt);
@ -1771,15 +1771,15 @@ public class MessageCompose extends K9Activity implements OnClickListener,
}
sendMessage();
if (mMessageReference != null && mMessageReference.flag != null) {
if (mMessageReference != null && mMessageReference.getFlag() != null) {
if (K9.DEBUG) {
Log.d(K9.LOG_TAG, "Setting referenced message (" + mMessageReference.folderName + ", " + mMessageReference.uid + ") flag to " + mMessageReference.flag);
Log.d(K9.LOG_TAG, "Setting referenced message (" + mMessageReference.getFolderName() + ", " + mMessageReference.getUid() + ") flag to " + mMessageReference.getFlag());
}
final Account account = Preferences.getPreferences(this).getAccount(mMessageReference.accountUuid);
final String folderName = mMessageReference.folderName;
final String sourceMessageUid = mMessageReference.uid;
MessagingController.getInstance(getApplication()).setFlag(account, folderName, sourceMessageUid, mMessageReference.flag, true);
final Account account = Preferences.getPreferences(this).getAccount(mMessageReference.getAccountUuid());
final String folderName = mMessageReference.getFolderName();
final String sourceMessageUid = mMessageReference.getUid();
MessagingController.getInstance(getApplication()).setFlag(account, folderName, sourceMessageUid, mMessageReference.getFlag(), true);
}
mDraftNeedsSaving = false;
@ -2351,9 +2351,9 @@ public class MessageCompose extends K9Activity implements OnClickListener,
if (mMessageReference != null) { // shouldn't happen...
// TODO - Should we check if mSourceMessageBody is already present and bypass the MessagingController call?
MessagingController.getInstance(getApplication()).addListener(mListener);
final Account account = Preferences.getPreferences(this).getAccount(mMessageReference.accountUuid);
final String folderName = mMessageReference.folderName;
final String sourceMessageUid = mMessageReference.uid;
final Account account = Preferences.getPreferences(this).getAccount(mMessageReference.getAccountUuid());
final String folderName = mMessageReference.getFolderName();
final String sourceMessageUid = mMessageReference.getUid();
MessagingController.getInstance(getApplication()).loadMessageForView(account, folderName, sourceMessageUid, null);
}
break;
@ -2876,7 +2876,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
// Check if this is a valid account in our database
Preferences prefs = Preferences.getPreferences(getApplicationContext());
Account account = prefs.getAccount(messageReference.accountUuid);
Account account = prefs.getAccount(messageReference.getAccountUuid());
if (account != null) {
mMessageReference = messageReference;
}
@ -3392,7 +3392,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
class Listener extends MessagingListener {
@Override
public void loadMessageForViewStarted(Account account, String folder, String uid) {
if ((mMessageReference == null) || !mMessageReference.uid.equals(uid)) {
if ((mMessageReference == null) || !mMessageReference.getUid().equals(uid)) {
return;
}
@ -3401,7 +3401,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
@Override
public void loadMessageForViewFinished(Account account, String folder, String uid, Message message) {
if ((mMessageReference == null) || !mMessageReference.uid.equals(uid)) {
if ((mMessageReference == null) || !mMessageReference.getUid().equals(uid)) {
return;
}
@ -3410,7 +3410,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
@Override
public void loadMessageForViewBodyAvailable(Account account, String folder, String uid, final Message message) {
if ((mMessageReference == null) || !mMessageReference.uid.equals(uid)) {
if ((mMessageReference == null) || !mMessageReference.getUid().equals(uid)) {
return;
}
@ -3441,7 +3441,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
@Override
public void loadMessageForViewFailed(Account account, String folder, String uid, Throwable t) {
if ((mMessageReference == null) || !mMessageReference.uid.equals(uid)) {
if ((mMessageReference == null) || !mMessageReference.getUid().equals(uid)) {
return;
}
mHandler.sendEmptyMessage(MSG_PROGRESS_OFF);
@ -3452,13 +3452,13 @@ public class MessageCompose extends K9Activity implements OnClickListener,
public void messageUidChanged(Account account, String folder, String oldUid, String newUid) {
// Track UID changes of the source message
if (mMessageReference != null) {
final Account sourceAccount = Preferences.getPreferences(MessageCompose.this).getAccount(mMessageReference.accountUuid);
final String sourceFolder = mMessageReference.folderName;
final String sourceMessageUid = mMessageReference.uid;
final Account sourceAccount = Preferences.getPreferences(MessageCompose.this).getAccount(mMessageReference.getAccountUuid());
final String sourceFolder = mMessageReference.getFolderName();
final String sourceMessageUid = mMessageReference.getUid();
if (account.equals(sourceAccount) && (folder.equals(sourceFolder))) {
if (oldUid.equals(sourceMessageUid)) {
mMessageReference.uid = newUid;
mMessageReference = mMessageReference.withModifiedUid(newUid);
}
if ((mSourceMessage != null) && (oldUid.equals(mSourceMessage.getUid()))) {
mSourceMessage.setUid(newUid);
@ -3602,7 +3602,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
* to the old message's uid.
*/
if (mMessageReference != null) {
message.setUid(mMessageReference.uid);
message.setUid(mMessageReference.getUid());
}
}

View File

@ -379,10 +379,7 @@ public class MessageList extends K9Activity implements MessageListFragmentListen
Collection<Account> accounts = Preferences.getPreferences(this).getAvailableAccounts();
for (Account account : accounts) {
if (String.valueOf(account.getAccountNumber()).equals(accountId)) {
mMessageReference = new MessageReference();
mMessageReference.accountUuid = account.getUuid();
mMessageReference.folderName = segmentList.get(1);
mMessageReference.uid = segmentList.get(2);
mMessageReference = new MessageReference(account.getUuid(), segmentList.get(1), segmentList.get(2), null);
break;
}
}
@ -431,8 +428,8 @@ public class MessageList extends K9Activity implements MessageListFragmentListen
if (mMessageReference != null) {
mSearch = new LocalSearch();
mSearch.addAccountUuid(mMessageReference.accountUuid);
mSearch.addAllowedFolder(mMessageReference.folderName);
mSearch.addAccountUuid(mMessageReference.getAccountUuid());
mSearch.addAllowedFolder(mMessageReference.getFolderName());
}
if (mSearch == null) {
@ -1168,8 +1165,8 @@ public class MessageList extends K9Activity implements MessageListFragmentListen
@Override
public void openMessage(MessageReference messageReference) {
Preferences prefs = Preferences.getPreferences(getApplicationContext());
Account account = prefs.getAccount(messageReference.accountUuid);
String folderName = messageReference.folderName;
Account account = prefs.getAccount(messageReference.getAccountUuid());
String folderName = messageReference.getFolderName();
if (folderName.equals(account.getDraftsFolderName())) {
MessageCompose.actionEditDraft(this, messageReference);

View File

@ -4936,7 +4936,7 @@ public class MessagingController implements Runnable {
String initialFolder = message.getFolder().getName();
/* only go to folder if all messages are in the same folder, else go to folder list */
for (MessageReference ref : allRefs) {
if (!TextUtils.equals(initialFolder, ref.folderName)) {
if (!TextUtils.equals(initialFolder, ref.getFolderName())) {
initialFolder = null;
break;
}
@ -5008,8 +5008,8 @@ public class MessagingController implements Runnable {
}
private TaskStackBuilder buildMessageViewBackStack(Context context, MessageReference message) {
Account account = Preferences.getPreferences(context).getAccount(message.accountUuid);
TaskStackBuilder stack = buildMessageListBackStack(context, account, message.folderName);
Account account = Preferences.getPreferences(context).getAccount(message.getAccountUuid());
TaskStackBuilder stack = buildMessageListBackStack(context, account, message.getFolderName());
stack.addNextIntent(MessageList.actionDisplayMessageIntent(context, message));
return stack;
}

View File

@ -2007,9 +2007,9 @@ public class MessageListFragment extends Fragment implements OnItemClickListener
String uid = cursor.getString(UID_COLUMN);
String folderName = cursor.getString(FOLDER_NAME_COLUMN);
if (account.getUuid().equals(mActiveMessage.accountUuid) &&
folderName.equals(mActiveMessage.folderName) &&
uid.equals(mActiveMessage.uid)) {
if (account.getUuid().equals(mActiveMessage.getAccountUuid()) &&
folderName.equals(mActiveMessage.getFolderName()) &&
uid.equals(mActiveMessage.getUid())) {
int res = R.attr.messageListActiveItemBackgroundColor;
TypedValue outValue = new TypedValue();
@ -2992,11 +2992,7 @@ public class MessageListFragment extends Fragment implements OnItemClickListener
for (int i = 0, len = mAdapter.getCount(); i < len; i++) {
Cursor cursor = (Cursor) mAdapter.getItem(i);
MessageReference ref = new MessageReference();
ref.accountUuid = cursor.getString(ACCOUNT_UUID_COLUMN);
ref.folderName = cursor.getString(FOLDER_NAME_COLUMN);
ref.uid = cursor.getString(UID_COLUMN);
MessageReference ref = new MessageReference(cursor.getString(ACCOUNT_UUID_COLUMN), cursor.getString(FOLDER_NAME_COLUMN), cursor.getString(UID_COLUMN), null);
messageRefs.add(ref);
}
@ -3058,10 +3054,7 @@ public class MessageListFragment extends Fragment implements OnItemClickListener
private MessageReference getReferenceForPosition(int position) {
Cursor cursor = (Cursor) mAdapter.getItem(position);
MessageReference ref = new MessageReference();
ref.accountUuid = cursor.getString(ACCOUNT_UUID_COLUMN);
ref.folderName = cursor.getString(FOLDER_NAME_COLUMN);
ref.uid = cursor.getString(UID_COLUMN);
MessageReference ref = new MessageReference(cursor.getString(ACCOUNT_UUID_COLUMN), cursor.getString(FOLDER_NAME_COLUMN), cursor.getString(UID_COLUMN), null);
return ref;
}
@ -3091,9 +3084,9 @@ public class MessageListFragment extends Fragment implements OnItemClickListener
String folderName = cursor.getString(FOLDER_NAME_COLUMN);
String uid = cursor.getString(UID_COLUMN);
if (accountUuid.equals(messageReference.accountUuid) &&
folderName.equals(messageReference.folderName) &&
uid.equals(messageReference.uid)) {
if (accountUuid.equals(messageReference.getAccountUuid()) &&
folderName.equals(messageReference.getFolderName()) &&
uid.equals(messageReference.getUid())) {
return i;
}
}
@ -3330,12 +3323,12 @@ public class MessageListFragment extends Fragment implements OnItemClickListener
StringBuilder query = new StringBuilder();
List<String> queryArgs = new ArrayList<String>();
if (needConditions) {
boolean selectActive = mActiveMessage != null && mActiveMessage.accountUuid.equals(accountUuid);
boolean selectActive = mActiveMessage != null && mActiveMessage.getAccountUuid().equals(accountUuid);
if (selectActive) {
query.append("(" + MessageColumns.UID + " = ? AND " + SpecialColumns.FOLDER_NAME + " = ?) OR (");
queryArgs.add(mActiveMessage.uid);
queryArgs.add(mActiveMessage.folderName);
queryArgs.add(mActiveMessage.getUid());
queryArgs.add(mActiveMessage.getFolderName());
}
SqlQueryBuilder.buildWhereClause(account, mSearch.getConditions(), query, queryArgs);

View File

@ -271,7 +271,7 @@ public class MessageViewFragment extends Fragment implements OnClickListener,
}
Context appContext = getActivity().getApplicationContext();
mAccount = Preferences.getPreferences(appContext).getAccount(mMessageReference.accountUuid);
mAccount = Preferences.getPreferences(appContext).getAccount(mMessageReference.getAccountUuid());
if (resetPgpData) {
// start with fresh, empty PGP data
@ -282,7 +282,7 @@ public class MessageViewFragment extends Fragment implements OnClickListener,
mMessageView.resetView();
mMessageView.resetHeaderView();
mController.loadMessageForView(mAccount, mMessageReference.folderName, mMessageReference.uid, mListener);
mController.loadMessageForView(mAccount, mMessageReference.getFolderName(), mMessageReference.getUid(), mListener);
mFragmentListener.updateMenu();
}
@ -340,7 +340,7 @@ public class MessageViewFragment extends Fragment implements OnClickListener,
}
private void refileMessage(String dstFolder) {
String srcFolder = mMessageReference.folderName;
String srcFolder = mMessageReference.getFolderName();
LocalMessage messageToMove = mMessage;
mFragmentListener.showNextMessageOrReturn();
mController.moveMessage(mAccount, srcFolder, messageToMove, dstFolder, null);
@ -417,7 +417,7 @@ public class MessageViewFragment extends Fragment implements OnClickListener,
private void startRefileActivity(int activity) {
Intent intent = new Intent(getActivity(), ChooseFolder.class);
intent.putExtra(ChooseFolder.EXTRA_ACCOUNT, mAccount.getUuid());
intent.putExtra(ChooseFolder.EXTRA_CUR_FOLDER, mMessageReference.folderName);
intent.putExtra(ChooseFolder.EXTRA_CUR_FOLDER, mMessageReference.getFolderName());
intent.putExtra(ChooseFolder.EXTRA_SEL_FOLDER, mAccount.getLastSelectedFolderName());
intent.putExtra(ChooseFolder.EXTRA_MESSAGE, mMessageReference);
startActivityForResult(intent, activity);
@ -493,7 +493,7 @@ public class MessageViewFragment extends Fragment implements OnClickListener,
return;
}
mMessageView.downloadRemainderButton().setEnabled(false);
mController.loadMessageForViewRemote(mAccount, mMessageReference.folderName, mMessageReference.uid, mListener);
mController.loadMessageForViewRemote(mAccount, mMessageReference.getFolderName(), mMessageReference.getUid(), mListener);
}
@Override
@ -516,12 +516,12 @@ public class MessageViewFragment extends Fragment implements OnClickListener,
}
public void moveMessage(MessageReference reference, String destFolderName) {
mController.moveMessage(mAccount, mMessageReference.folderName, mMessage,
mController.moveMessage(mAccount, mMessageReference.getFolderName(), mMessage,
destFolderName, null);
}
public void copyMessage(MessageReference reference, String destFolderName) {
mController.copyMessage(mAccount, mMessageReference.folderName, mMessage,
mController.copyMessage(mAccount, mMessageReference.getFolderName(), mMessage,
destFolderName, null);
}
@ -529,8 +529,8 @@ public class MessageViewFragment extends Fragment implements OnClickListener,
@Override
public void loadMessageForViewHeadersAvailable(final Account account, String folder, String uid,
final Message message) {
if (!mMessageReference.uid.equals(uid) || !mMessageReference.folderName.equals(folder)
|| !mMessageReference.accountUuid.equals(account.getUuid())) {
if (!mMessageReference.getUid().equals(uid) || !mMessageReference.getFolderName().equals(folder)
|| !mMessageReference.getAccountUuid().equals(account.getUuid())) {
return;
}
@ -577,9 +577,9 @@ public class MessageViewFragment extends Fragment implements OnClickListener,
public void loadMessageForViewBodyAvailable(final Account account, String folder,
String uid, final Message message) {
if (!(message instanceof LocalMessage) ||
!mMessageReference.uid.equals(uid) ||
!mMessageReference.folderName.equals(folder) ||
!mMessageReference.accountUuid.equals(account.getUuid())) {
!mMessageReference.getUid().equals(uid) ||
!mMessageReference.getFolderName().equals(folder) ||
!mMessageReference.getAccountUuid().equals(account.getUuid())) {
return;
}
@ -601,8 +601,8 @@ public class MessageViewFragment extends Fragment implements OnClickListener,
@Override
public void loadMessageForViewFailed(Account account, String folder, String uid, final Throwable t) {
if (!mMessageReference.uid.equals(uid) || !mMessageReference.folderName.equals(folder)
|| !mMessageReference.accountUuid.equals(account.getUuid())) {
if (!mMessageReference.getUid().equals(uid) || !mMessageReference.getFolderName().equals(folder)
|| !mMessageReference.getAccountUuid().equals(account.getUuid())) {
return;
}
mHandler.post(new Runnable() {
@ -624,8 +624,8 @@ public class MessageViewFragment extends Fragment implements OnClickListener,
@Override
public void loadMessageForViewFinished(Account account, String folder, String uid, final Message message) {
if (!mMessageReference.uid.equals(uid) || !mMessageReference.folderName.equals(folder)
|| !mMessageReference.accountUuid.equals(account.getUuid())) {
if (!mMessageReference.getUid().equals(uid) || !mMessageReference.getFolderName().equals(folder)
|| !mMessageReference.getAccountUuid().equals(account.getUuid())) {
return;
}
mHandler.post(new Runnable() {
@ -639,8 +639,8 @@ public class MessageViewFragment extends Fragment implements OnClickListener,
@Override
public void loadMessageForViewStarted(Account account, String folder, String uid) {
if (!mMessageReference.uid.equals(uid) || !mMessageReference.folderName.equals(folder)
|| !mMessageReference.accountUuid.equals(account.getUuid())) {
if (!mMessageReference.getUid().equals(uid) || !mMessageReference.getFolderName().equals(folder)
|| !mMessageReference.getAccountUuid().equals(account.getUuid())) {
return;
}
mHandler.post(new Runnable() {
@ -830,12 +830,12 @@ public class MessageViewFragment extends Fragment implements OnClickListener,
}
public boolean canMessageBeArchived() {
return (!mMessageReference.folderName.equals(mAccount.getArchiveFolderName())
return (!mMessageReference.getFolderName().equals(mAccount.getArchiveFolderName())
&& mAccount.hasArchiveFolder());
}
public boolean canMessageBeMovedToSpam() {
return (!mMessageReference.folderName.equals(mAccount.getSpamFolderName())
return (!mMessageReference.getFolderName().equals(mAccount.getSpamFolderName())
&& mAccount.hasSpamFolder());
}

View File

@ -576,10 +576,7 @@ public class LocalMessage extends MimeMessage {
public MessageReference makeMessageReference() {
if (mReference == null) {
mReference = new MessageReference();
mReference.folderName = getFolder().getName();
mReference.uid = mUid;
mReference.accountUuid = getFolder().getAccountUuid();
mReference = new MessageReference(getFolder().getAccountUuid(), getFolder().getName(), mUid, null);
}
return mReference;
}

View File

@ -80,7 +80,7 @@ public class NotificationActionService extends CoreService {
List<MessageReference> refs =
intent.getParcelableArrayListExtra(EXTRA_MESSAGE_LIST);
for (MessageReference ref : refs) {
controller.setFlag(account, ref.folderName, ref.uid, Flag.SEEN, true);
controller.setFlag(account, ref.getFolderName(), ref.getUid(), Flag.SEEN, true);
}
} else if (DELETE_ALL_ACTION.equals(action)) {
if (K9.DEBUG)