From 57b9321a1efc59a71722f980704063f17ac77df5 Mon Sep 17 00:00:00 2001 From: ashley willis Date: Tue, 1 Nov 2011 03:02:29 -0500 Subject: [PATCH 1/4] issue-1424: saving duplicate or similar drafts fixed. --- src/com/fsck/k9/activity/MessageCompose.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/com/fsck/k9/activity/MessageCompose.java b/src/com/fsck/k9/activity/MessageCompose.java index 9ccd357c9..de1431c84 100644 --- a/src/com/fsck/k9/activity/MessageCompose.java +++ b/src/com/fsck/k9/activity/MessageCompose.java @@ -106,6 +106,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc private static final String STATE_REFERENCES = "com.fsck.k9.activity.MessageCompose.references"; private static final String STATE_KEY_MESSAGE_FORMAT = "com.fsck.k9.activity.MessageCompose.messageFormat"; private static final String STATE_KEY_READ_RECEIPT = "com.fsck.k9.activity.MessageCompose.messageReadReceipt"; + private static final String STATE_KEY_DRAFT_NEEDS_SAVING = "com.fsck.k9.activity.MessageCompose.mDraftNeedsSaving"; private static final int MSG_PROGRESS_ON = 1; private static final int MSG_PROGRESS_OFF = 2; @@ -789,7 +790,6 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc @Override public void onPause() { super.onPause(); - saveIfNeeded(); MessagingController.getInstance(getApplication()).removeListener(mListener); } @@ -804,7 +804,6 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); - saveIfNeeded(); ArrayList attachments = new ArrayList(); for (int i = 0, count = mAttachments.getChildCount(); i < count; i++) { View view = mAttachments.getChildAt(i); @@ -825,6 +824,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc outState.putSerializable(STATE_KEY_HTML_QUOTE, mQuotedHtmlContent); outState.putSerializable(STATE_KEY_MESSAGE_FORMAT, mMessageFormat); outState.putBoolean(STATE_KEY_READ_RECEIPT, mReadReceipt); + outState.putBoolean(STATE_KEY_DRAFT_NEEDS_SAVING, mDraftNeedsSaving); } @Override @@ -859,13 +859,13 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc mPgpData = (PgpData) savedInstanceState.getSerializable(STATE_PGP_DATA); mInReplyTo = savedInstanceState.getString(STATE_IN_REPLY_TO); mReferences = savedInstanceState.getString(STATE_REFERENCES); + mDraftNeedsSaving = savedInstanceState.getBoolean(STATE_KEY_DRAFT_NEEDS_SAVING); initializeCrypto(); updateFrom(); updateSignature(); updateEncryptLayout(); - mDraftNeedsSaving = false; } private void updateTitle() { @@ -1427,7 +1427,6 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc } private void onSave() { - mDraftNeedsSaving = true; saveIfNeeded(); finish(); } @@ -2644,10 +2643,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc Message draftMessage = messagingController.saveDraft(mAccount, message); mDraftUid = draftMessage.getUid(); - // Don't display the toast if the user is just changing the orientation - if ((getChangingConfigurations() & ActivityInfo.CONFIG_ORIENTATION) == 0) { - mHandler.sendEmptyMessage(MSG_SAVED_DRAFT); - } + mHandler.sendEmptyMessage(MSG_SAVED_DRAFT); return null; } } From a021ab71de6f6f53481e15b841cc8351441a1023 Mon Sep 17 00:00:00 2001 From: ashley willis Date: Tue, 1 Nov 2011 22:12:51 -0500 Subject: [PATCH 2/4] Override onStop() to save email as draft when activity is changed (go to home screen, call received) --- src/com/fsck/k9/activity/MessageCompose.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/com/fsck/k9/activity/MessageCompose.java b/src/com/fsck/k9/activity/MessageCompose.java index de1431c84..80582e028 100644 --- a/src/com/fsck/k9/activity/MessageCompose.java +++ b/src/com/fsck/k9/activity/MessageCompose.java @@ -793,6 +793,20 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc MessagingController.getInstance(getApplication()).removeListener(mListener); } + // Save email as draft when activity is changed (go to home screen, call received) + @Override + public void onStop() { + super.onStop(); + // don't do this if only changing orientations + if ((getChangingConfigurations() & ActivityInfo.CONFIG_ORIENTATION) == 0) { + // don't do this if selecting signature or if "Encrypt" is checked + if (!mPreventDraftSaving && !mEncryptCheckbox.isChecked()){ + saveIfNeeded(); + finish(); + } + } + } + /** * The framework handles most of the fields, but we need to handle stuff that we * dynamically show and hide: From 7f582f5a38a1dcb568a049f0d39fce0f7297f0a8 Mon Sep 17 00:00:00 2001 From: ashley willis Date: Thu, 3 Nov 2011 15:38:53 -0500 Subject: [PATCH 3/4] added mIgnoreOnStop for when adding an attachment. --- src/com/fsck/k9/activity/MessageCompose.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/com/fsck/k9/activity/MessageCompose.java b/src/com/fsck/k9/activity/MessageCompose.java index 80582e028..98168b514 100644 --- a/src/com/fsck/k9/activity/MessageCompose.java +++ b/src/com/fsck/k9/activity/MessageCompose.java @@ -212,6 +212,8 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc private boolean mDraftNeedsSaving = false; private boolean mPreventDraftSaving = false; + private boolean mIgnoreOnStop = false; + /** * The draft uid of this message. This is used when saving drafts so that the same draft is * overwritten instead of being created anew. This property is null until the first save. @@ -784,6 +786,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc @Override public void onResume() { super.onResume(); + mIgnoreOnStop = false; MessagingController.getInstance(getApplication()).addListener(mListener); } @@ -799,8 +802,8 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc super.onStop(); // don't do this if only changing orientations if ((getChangingConfigurations() & ActivityInfo.CONFIG_ORIENTATION) == 0) { - // don't do this if selecting signature or if "Encrypt" is checked - if (!mPreventDraftSaving && !mEncryptCheckbox.isChecked()){ + // don't do this if selecting signature or if "Encrypt" is checked or if adding an attachment + if (!mPreventDraftSaving && !mEncryptCheckbox.isChecked() && !mIgnoreOnStop){ saveIfNeeded(); finish(); } @@ -1467,6 +1470,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc * Kick off a picker for whatever kind of MIME types we'll accept and let Android take over. */ private void onAddAttachment() { + mIgnoreOnStop = true; if (K9.isGalleryBuggy()) { if (K9.useGalleryBugWorkaround()) { Toast.makeText(MessageCompose.this, @@ -2626,7 +2630,6 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc private class SaveMessageTask extends AsyncTask { @Override protected Void doInBackground(Void... params) { - /* * Create the message from all the data the user has entered. */ From 2b77c6e35ce67d91b39b50dbb068dc6e879b68f3 Mon Sep 17 00:00:00 2001 From: ashley willis Date: Fri, 4 Nov 2011 02:33:56 -0500 Subject: [PATCH 4/4] moved code from onStop() to onPause() since onStop() may never be called. --- src/com/fsck/k9/activity/MessageCompose.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/com/fsck/k9/activity/MessageCompose.java b/src/com/fsck/k9/activity/MessageCompose.java index 98168b514..f2558e54f 100644 --- a/src/com/fsck/k9/activity/MessageCompose.java +++ b/src/com/fsck/k9/activity/MessageCompose.java @@ -794,12 +794,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc public void onPause() { super.onPause(); MessagingController.getInstance(getApplication()).removeListener(mListener); - } - - // Save email as draft when activity is changed (go to home screen, call received) - @Override - public void onStop() { - super.onStop(); + // Save email as draft when activity is changed (go to home screen, call received) or screen locked // don't do this if only changing orientations if ((getChangingConfigurations() & ActivityInfo.CONFIG_ORIENTATION) == 0) { // don't do this if selecting signature or if "Encrypt" is checked or if adding an attachment