Don't confirm if discarding empty message
When the user chooses to discard a message in compose,
don't ask for confirmation if the message has no content
(subject, body, attachment).
b/17496056
Change-Id: I597039dacf2afcb71d6dfd614c10e23025f901de
diff --git a/src/com/android/mail/compose/ComposeActivity.java b/src/com/android/mail/compose/ComposeActivity.java
index e4ef81f..b2756b4 100644
--- a/src/com/android/mail/compose/ComposeActivity.java
+++ b/src/com/android/mail/compose/ComposeActivity.java
@@ -2339,7 +2339,7 @@
: (Intent.ACTION_SEND.equals(action)
|| Intent.ACTION_SEND_MULTIPLE.equals(action)
|| Intent.ACTION_SENDTO.equals(action)
- || shouldSave()));
+ || isDraftDirty()));
final MenuItem helpItem = menu.findItem(R.id.help_info_menu_item);
final MenuItem sendFeedbackItem = menu.findItem(R.id.feedback_menu_item);
@@ -2810,14 +2810,14 @@
*/
public void updateSaveUi() {
if (mSave != null) {
- mSave.setEnabled((shouldSave() && !isBlank()));
+ mSave.setEnabled((isDraftDirty() && !isBlank()));
}
}
/**
- * Returns true if we need to save the current draft.
+ * Returns true if the current draft is modified from the version we previously saved.
*/
- private boolean shouldSave() {
+ private boolean isDraftDirty() {
synchronized (mDraftLock) {
// The message should only be saved if:
// It hasn't been sent AND
@@ -3661,9 +3661,15 @@
}
private void doDiscard() {
- final DialogFragment frag = new DiscardConfirmDialogFragment();
- frag.show(getFragmentManager(), "discard confirm");
+ // Only need to ask for confirmation if the draft is in a dirty state.
+ if (isDraftDirty()) {
+ final DialogFragment frag = new DiscardConfirmDialogFragment();
+ frag.show(getFragmentManager(), "discard confirm");
+ } else {
+ doDiscardWithoutConfirmation();
+ }
}
+
/**
* Effectively discard the current message.
*
@@ -3705,7 +3711,7 @@
return;
}
- if (shouldSave()) {
+ if (isDraftDirty()) {
doSave(!mAddingAttachment /* show toast */);
}
}