From 46bf2c5be7e9d3097da736d8448ddd325aae8702 Mon Sep 17 00:00:00 2001 From: Nick Nikolaou Date: Thu, 2 Feb 2012 21:56:56 +0000 Subject: [PATCH] Add discard confirmation dialog when pressing back --- res/values/strings.xml | 3 ++ src/com/fsck/k9/activity/MessageCompose.java | 42 +++++++++++++++++--- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index f2666ff53..9fd5973aa 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1030,6 +1030,9 @@ Welcome to K-9 Mail setup. K-9 is an open source mail client for Android origin Save draft message? Save or Discard this message? + Discard message? + Are you sure you want to discard this message? + Refuse to save draft message. Refuse to save draft message marked encrypted. diff --git a/src/com/fsck/k9/activity/MessageCompose.java b/src/com/fsck/k9/activity/MessageCompose.java index 2eac71f19..a24423eb3 100644 --- a/src/com/fsck/k9/activity/MessageCompose.java +++ b/src/com/fsck/k9/activity/MessageCompose.java @@ -83,6 +83,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc private static final int DIALOG_SAVE_OR_DISCARD_DRAFT_MESSAGE = 1; private static final int DIALOG_REFUSE_TO_SAVE_DRAFT_MARKED_ENCRYPTED = 2; private static final int DIALOG_CONTINUE_WITHOUT_PUBLIC_KEY = 3; + private static final int DIALOG_CONFIRM_DISCARD_ON_BACK = 4; private static final long INVALID_DRAFT_ID = MessagingController.INVALID_MESSAGE_ID; @@ -2051,13 +2052,21 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc @Override public void onBackPressed() { - if (mEncryptCheckbox.isChecked()) { - showDialog(DIALOG_REFUSE_TO_SAVE_DRAFT_MARKED_ENCRYPTED); - } else if (!mDraftNeedsSaving || isDraftsFolderDisabled()) { - Toast.makeText(MessageCompose.this, getString(R.string.message_discarded_toast), Toast.LENGTH_LONG).show(); - super.onBackPressed(); + if (mDraftNeedsSaving) { + if (mEncryptCheckbox.isChecked()) { + showDialog(DIALOG_REFUSE_TO_SAVE_DRAFT_MARKED_ENCRYPTED); + } else if (isDraftsFolderDisabled()) { + showDialog(DIALOG_CONFIRM_DISCARD_ON_BACK); + } else { + showDialog(DIALOG_SAVE_OR_DISCARD_DRAFT_MESSAGE); + } } else { - showDialog(DIALOG_SAVE_OR_DISCARD_DRAFT_MESSAGE); + // Check if editing an existing draft. + if (mDraftId == INVALID_DRAFT_ID) { + onDiscard(); + } else { + super.onBackPressed(); + } } } @@ -2118,6 +2127,27 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc } }) .create(); + case DIALOG_CONFIRM_DISCARD_ON_BACK: + return new AlertDialog.Builder(this) + .setTitle(R.string.confirm_discard_draft_message_title) + .setMessage(R.string.confirm_discard_draft_message) + .setPositiveButton(R.string.cancel_action, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int whichButton) { + dismissDialog(DIALOG_CONFIRM_DISCARD_ON_BACK); + } + }) + .setNegativeButton(R.string.discard_action, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int whichButton) { + dismissDialog(DIALOG_CONFIRM_DISCARD_ON_BACK); + Toast.makeText(MessageCompose.this, + getString(R.string.message_discarded_toast), + Toast.LENGTH_LONG).show(); + onDiscard(); + } + }) + .create(); } return super.onCreateDialog(id); }