mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-24 02:12:15 -05:00
Introduced enum for the MessageCompose actions (compose, reply, ...)
This commit is contained in:
parent
3daaecf2c9
commit
01c8e84396
@ -185,6 +185,19 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
|
|||||||
*/
|
*/
|
||||||
private boolean mSourceMessageProcessed = false;
|
private boolean mSourceMessageProcessed = false;
|
||||||
|
|
||||||
|
enum Action {
|
||||||
|
COMPOSE,
|
||||||
|
REPLY,
|
||||||
|
REPLY_ALL,
|
||||||
|
FORWARD,
|
||||||
|
EDIT_DRAFT
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contains the action we're currently performing (e.g. replying to a message)
|
||||||
|
*/
|
||||||
|
private Action mAction;
|
||||||
|
|
||||||
private enum QuotedTextMode {
|
private enum QuotedTextMode {
|
||||||
NONE,
|
NONE,
|
||||||
SHOW,
|
SHOW,
|
||||||
@ -587,8 +600,26 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
final String action = intent.getAction();
|
if (initFromIntent(intent)) {
|
||||||
initFromIntent(intent);
|
mAction = Action.COMPOSE;
|
||||||
|
} else {
|
||||||
|
String action = intent.getAction();
|
||||||
|
if (ACTION_COMPOSE.equals(action)) {
|
||||||
|
mAction = Action.COMPOSE;
|
||||||
|
} else if (ACTION_REPLY.equals(action)) {
|
||||||
|
mAction = Action.REPLY;
|
||||||
|
} else if (ACTION_REPLY_ALL.equals(action)) {
|
||||||
|
mAction = Action.REPLY_ALL;
|
||||||
|
} else if (ACTION_FORWARD.equals(action)) {
|
||||||
|
mAction = Action.FORWARD;
|
||||||
|
} else if (ACTION_EDIT_DRAFT.equals(action)) {
|
||||||
|
mAction = Action.EDIT_DRAFT;
|
||||||
|
} else {
|
||||||
|
// This shouldn't happen
|
||||||
|
Log.w(K9.LOG_TAG, "MessageCompose was started with an unsupported action");
|
||||||
|
mAction = Action.COMPOSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (mIdentity == null) {
|
if (mIdentity == null) {
|
||||||
mIdentity = mAccount.getIdentity(0);
|
mIdentity = mAccount.getIdentity(0);
|
||||||
@ -609,7 +640,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
|
|||||||
|
|
||||||
mMessageFormat = mAccount.getMessageFormat();
|
mMessageFormat = mAccount.getMessageFormat();
|
||||||
if (mMessageFormat == MessageFormat.AUTO) {
|
if (mMessageFormat == MessageFormat.AUTO) {
|
||||||
if (ACTION_COMPOSE.equals(action)) {
|
if (mAction == Action.COMPOSE) {
|
||||||
mMessageFormat = MessageFormat.TEXT;
|
mMessageFormat = MessageFormat.TEXT;
|
||||||
} else if (mSourceMessageBody != null) {
|
} else if (mSourceMessageBody != null) {
|
||||||
// mSourceMessageBody is set to something when replying to and forwarding decrypted
|
// mSourceMessageBody is set to something when replying to and forwarding decrypted
|
||||||
@ -626,10 +657,8 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
|
|||||||
if (!mSourceMessageProcessed) {
|
if (!mSourceMessageProcessed) {
|
||||||
updateSignature();
|
updateSignature();
|
||||||
|
|
||||||
if (ACTION_REPLY.equals(action) ||
|
if (mAction == Action.REPLY || mAction == Action.REPLY_ALL ||
|
||||||
ACTION_REPLY_ALL.equals(action) ||
|
mAction == Action.FORWARD || mAction == Action.EDIT_DRAFT) {
|
||||||
ACTION_FORWARD.equals(action) ||
|
|
||||||
ACTION_EDIT_DRAFT.equals(action)) {
|
|
||||||
/*
|
/*
|
||||||
* If we need to load the message we add ourself as a message listener here
|
* If we need to load the message we add ourself as a message listener here
|
||||||
* so we can kick it off. Normally we add in onResume but we don't
|
* so we can kick it off. Normally we add in onResume but we don't
|
||||||
@ -644,7 +673,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
|
|||||||
MessagingController.getInstance(getApplication()).loadMessageForView(account, folderName, sourceMessageUid, null);
|
MessagingController.getInstance(getApplication()).loadMessageForView(account, folderName, sourceMessageUid, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ACTION_EDIT_DRAFT.equals(action)) {
|
if (mAction != Action.EDIT_DRAFT) {
|
||||||
String bccAddress = mAccount.getAlwaysBcc();
|
String bccAddress = mAccount.getAlwaysBcc();
|
||||||
if ((bccAddress != null) && !("".equals(bccAddress))) {
|
if ((bccAddress != null) && !("".equals(bccAddress))) {
|
||||||
String[] bccAddresses = bccAddress.split(",");
|
String[] bccAddresses = bccAddress.split(",");
|
||||||
@ -662,14 +691,12 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
|
|||||||
updateTitle();
|
updateTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ACTION_REPLY.equals(action) ||
|
if (mAction == Action.REPLY || mAction == Action.REPLY_ALL) {
|
||||||
ACTION_REPLY_ALL.equals(action)) {
|
|
||||||
mMessageReference.flag = Flag.ANSWERED;
|
mMessageReference.flag = Flag.ANSWERED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ACTION_REPLY.equals(action) ||
|
if (mAction == Action.REPLY || mAction == Action.REPLY_ALL ||
|
||||||
ACTION_REPLY_ALL.equals(action) ||
|
mAction == Action.EDIT_DRAFT) {
|
||||||
ACTION_EDIT_DRAFT.equals(action)) {
|
|
||||||
//change focus to message body.
|
//change focus to message body.
|
||||||
mMessageContentView.requestFocus();
|
mMessageContentView.requestFocus();
|
||||||
} else {
|
} else {
|
||||||
@ -742,12 +769,29 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
|
|||||||
/**
|
/**
|
||||||
* Handle external intents that trigger the message compose activity.
|
* Handle external intents that trigger the message compose activity.
|
||||||
*
|
*
|
||||||
* @param intent The (external) intent that started the activity.
|
* <p>
|
||||||
|
* Supported external intents:
|
||||||
|
* <ul>
|
||||||
|
* <li>{@link Intent#ACTION_VIEW}</li>
|
||||||
|
* <li>{@link Intent#ACTION_SENDTO}</li>
|
||||||
|
* <li>{@link Intent#ACTION_SEND}</li>
|
||||||
|
* <li>{@link Intent#ACTION_SEND_MULTIPLE}</li>
|
||||||
|
* </ul>
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param intent
|
||||||
|
* The (external) intent that started the activity.
|
||||||
|
*
|
||||||
|
* @return {@code true}, if this activity was started by an external intent. {@code false},
|
||||||
|
* otherwise.
|
||||||
*/
|
*/
|
||||||
private void initFromIntent(final Intent intent) {
|
private boolean initFromIntent(final Intent intent) {
|
||||||
|
boolean startedByExternalIntent = false;
|
||||||
final String action = intent.getAction();
|
final String action = intent.getAction();
|
||||||
|
|
||||||
if (Intent.ACTION_VIEW.equals(action) || Intent.ACTION_SENDTO.equals(action)) {
|
if (Intent.ACTION_VIEW.equals(action) || Intent.ACTION_SENDTO.equals(action)) {
|
||||||
|
startedByExternalIntent = true;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Someone has clicked a mailto: link. The address is in the URI.
|
* Someone has clicked a mailto: link. The address is in the URI.
|
||||||
*/
|
*/
|
||||||
@ -770,6 +814,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
|
|||||||
|
|
||||||
if (Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action) ||
|
if (Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action) ||
|
||||||
Intent.ACTION_SENDTO.equals(action)) {
|
Intent.ACTION_SENDTO.equals(action)) {
|
||||||
|
startedByExternalIntent = true;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Note: Here we allow a slight deviation from the documentated behavior.
|
* Note: Here we allow a slight deviation from the documentated behavior.
|
||||||
@ -829,6 +874,8 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
|
|||||||
onAddCcBcc();
|
onAddCcBcc();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return startedByExternalIntent;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean addRecipients(TextView view, List<String> recipients) {
|
private boolean addRecipients(TextView view, List<String> recipients) {
|
||||||
@ -1879,7 +1926,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
|
|||||||
}
|
}
|
||||||
|
|
||||||
// on draft edit, make sure we don't keep previous message UID
|
// on draft edit, make sure we don't keep previous message UID
|
||||||
if (ACTION_EDIT_DRAFT.equals(getIntent().getAction())) {
|
if (mAction == Action.EDIT_DRAFT) {
|
||||||
mMessageReference = null;
|
mMessageReference = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2240,9 +2287,8 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
|
|||||||
* @param message Source message
|
* @param message Source message
|
||||||
*/
|
*/
|
||||||
private void processSourceMessage(Message message) {
|
private void processSourceMessage(Message message) {
|
||||||
String action = getIntent().getAction();
|
|
||||||
try {
|
try {
|
||||||
if (ACTION_REPLY.equals(action) || ACTION_REPLY_ALL.equals(action)) {
|
if (mAction == Action.REPLY || mAction == Action.REPLY_ALL) {
|
||||||
if (message.getSubject() != null) {
|
if (message.getSubject() != null) {
|
||||||
final String subject = PREFIX.matcher(message.getSubject()).replaceFirst("");
|
final String subject = PREFIX.matcher(message.getSubject()).replaceFirst("");
|
||||||
|
|
||||||
@ -2297,7 +2343,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
|
|||||||
// Quote the message and setup the UI.
|
// Quote the message and setup the UI.
|
||||||
populateUIWithQuotedMessage(mAccount.isDefaultQuotedTextShown());
|
populateUIWithQuotedMessage(mAccount.isDefaultQuotedTextShown());
|
||||||
|
|
||||||
if (ACTION_REPLY_ALL.equals(action) || ACTION_REPLY.equals(action)) {
|
if (mAction == Action.REPLY || mAction == Action.REPLY_ALL) {
|
||||||
Identity useIdentity = null;
|
Identity useIdentity = null;
|
||||||
for (Address address : message.getRecipients(RecipientType.TO)) {
|
for (Address address : message.getRecipients(RecipientType.TO)) {
|
||||||
Identity identity = mAccount.findIdentity(address);
|
Identity identity = mAccount.findIdentity(address);
|
||||||
@ -2325,7 +2371,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ACTION_REPLY_ALL.equals(action)) {
|
if (mAction == Action.REPLY_ALL) {
|
||||||
if (message.getReplyTo().length > 0) {
|
if (message.getReplyTo().length > 0) {
|
||||||
for (Address address : message.getFrom()) {
|
for (Address address : message.getFrom()) {
|
||||||
if (!mAccount.isAnIdentity(address)) {
|
if (!mAccount.isAnIdentity(address)) {
|
||||||
@ -2349,7 +2395,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
|
|||||||
mCcWrapper.setVisibility(View.VISIBLE);
|
mCcWrapper.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (ACTION_FORWARD.equals(action)) {
|
} else if (mAction == Action.FORWARD) {
|
||||||
String subject = message.getSubject();
|
String subject = message.getSubject();
|
||||||
if (subject != null && !subject.toLowerCase(Locale.US).startsWith("fwd:")) {
|
if (subject != null && !subject.toLowerCase(Locale.US).startsWith("fwd:")) {
|
||||||
mSubjectView.setText("Fwd: " + subject);
|
mSubjectView.setText("Fwd: " + subject);
|
||||||
@ -2366,7 +2412,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
|
|||||||
mHandler.sendEmptyMessage(MSG_SKIPPED_ATTACHMENTS);
|
mHandler.sendEmptyMessage(MSG_SKIPPED_ATTACHMENTS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (ACTION_EDIT_DRAFT.equals(action)) {
|
} else if (mAction == Action.EDIT_DRAFT) {
|
||||||
String showQuotedTextMode = "NONE";
|
String showQuotedTextMode = "NONE";
|
||||||
|
|
||||||
mDraftId = MessagingController.getInstance(getApplication()).getId(message);
|
mDraftId = MessagingController.getInstance(getApplication()).getId(message);
|
||||||
@ -2643,8 +2689,8 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
|
|||||||
if (mMessageFormat == MessageFormat.HTML) {
|
if (mMessageFormat == MessageFormat.HTML) {
|
||||||
// Strip signature.
|
// Strip signature.
|
||||||
// closing tags such as </div>, </span>, </table>, </pre> will be cut off.
|
// closing tags such as </div>, </span>, </table>, </pre> will be cut off.
|
||||||
if (mAccount.isStripSignature() && (ACTION_REPLY_ALL.equals(getIntent().getAction()) ||
|
if (mAccount.isStripSignature() &&
|
||||||
ACTION_REPLY.equals(getIntent().getAction()))) {
|
(mAction == Action.REPLY || mAction == Action.REPLY_ALL)) {
|
||||||
Matcher dashSignatureHtml = DASH_SIGNATURE_HTML.matcher(content);
|
Matcher dashSignatureHtml = DASH_SIGNATURE_HTML.matcher(content);
|
||||||
if (dashSignatureHtml.find()) {
|
if (dashSignatureHtml.find()) {
|
||||||
Matcher blockquoteStart = BLOCKQUOTE_START.matcher(content);
|
Matcher blockquoteStart = BLOCKQUOTE_START.matcher(content);
|
||||||
@ -2722,8 +2768,8 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
|
|||||||
getBodyTextFromMessage(mSourceMessage, MessageFormat.TEXT), mQuoteStyle));
|
getBodyTextFromMessage(mSourceMessage, MessageFormat.TEXT), mQuoteStyle));
|
||||||
|
|
||||||
} else if (mMessageFormat == MessageFormat.TEXT) {
|
} else if (mMessageFormat == MessageFormat.TEXT) {
|
||||||
if (mAccount.isStripSignature() && (ACTION_REPLY_ALL.equals(getIntent().getAction()) ||
|
if (mAccount.isStripSignature() &&
|
||||||
ACTION_REPLY.equals(getIntent().getAction()))) {
|
(mAction == Action.REPLY || mAction == Action.REPLY_ALL)) {
|
||||||
if (DASH_SIGNATURE_PLAIN.matcher(content).find()) {
|
if (DASH_SIGNATURE_PLAIN.matcher(content).find()) {
|
||||||
content = DASH_SIGNATURE_PLAIN.matcher(content).replaceFirst("\r\n");
|
content = DASH_SIGNATURE_PLAIN.matcher(content).replaceFirst("\r\n");
|
||||||
}
|
}
|
||||||
@ -3097,7 +3143,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
|
|||||||
/*
|
/*
|
||||||
* Save a draft
|
* Save a draft
|
||||||
*/
|
*/
|
||||||
if (ACTION_EDIT_DRAFT.equals(getIntent().getAction())) {
|
if (mAction == Action.EDIT_DRAFT) {
|
||||||
/*
|
/*
|
||||||
* We're saving a previously saved draft, so update the new message's uid
|
* We're saving a previously saved draft, so update the new message's uid
|
||||||
* to the old message's uid.
|
* to the old message's uid.
|
||||||
|
Loading…
Reference in New Issue
Block a user