mirror of
https://github.com/moparisthebest/k-9
synced 2024-12-24 08:38:51 -05:00
Add discard confirmation dialog when pressing back
This commit is contained in:
parent
35b5aebdb3
commit
46bf2c5be7
@ -1030,6 +1030,9 @@ Welcome to K-9 Mail setup. K-9 is an open source mail client for Android origin
|
||||
<string name="save_or_discard_draft_message_dlg_title">Save draft message?</string>
|
||||
<string name="save_or_discard_draft_message_instructions_fmt">Save or Discard this message?</string>
|
||||
|
||||
<string name="confirm_discard_draft_message_title">Discard message?</string>
|
||||
<string name="confirm_discard_draft_message">Are you sure you want to discard this message?</string>
|
||||
|
||||
<string name="refuse_to_save_draft_marked_encrypted_dlg_title">Refuse to save draft message.</string>
|
||||
<string name="refuse_to_save_draft_marked_encrypted_instructions_fmt">Refuse to save draft message marked encrypted.</string>
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user