Merge pull request #1310 from k9mail/trimMessageCompose
Move static methods and classes out of MessageCompose
This commit is contained in:
commit
e8d04338e2
8 changed files with 322 additions and 268 deletions
|
@ -67,6 +67,7 @@ import com.fsck.k9.FontSizes;
|
|||
import com.fsck.k9.K9;
|
||||
import com.fsck.k9.Preferences;
|
||||
import com.fsck.k9.R;
|
||||
import com.fsck.k9.activity.compose.MessageActions;
|
||||
import com.fsck.k9.activity.misc.ExtendedAsyncTask;
|
||||
import com.fsck.k9.activity.misc.NonConfigurationInstance;
|
||||
import com.fsck.k9.activity.setup.AccountSettings;
|
||||
|
@ -643,7 +644,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
|
|||
private void onCompose() {
|
||||
Account defaultAccount = Preferences.getPreferences(this).getDefaultAccount();
|
||||
if (defaultAccount != null) {
|
||||
MessageCompose.actionCompose(this, defaultAccount);
|
||||
MessageActions.actionCompose(this, defaultAccount);
|
||||
} else {
|
||||
onAddNewAccount();
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ import com.fsck.k9.FontSizes;
|
|||
import com.fsck.k9.K9;
|
||||
import com.fsck.k9.Preferences;
|
||||
import com.fsck.k9.R;
|
||||
import com.fsck.k9.activity.compose.MessageActions;
|
||||
import com.fsck.k9.activity.setup.AccountSettings;
|
||||
import com.fsck.k9.activity.setup.FolderSettings;
|
||||
import com.fsck.k9.activity.setup.Prefs;
|
||||
|
@ -517,7 +518,7 @@ public class FolderList extends K9ListActivity {
|
|||
return true;
|
||||
|
||||
case R.id.compose:
|
||||
MessageCompose.actionCompose(this, mAccount);
|
||||
MessageActions.actionCompose(this, mAccount);
|
||||
|
||||
return true;
|
||||
|
||||
|
|
|
@ -68,9 +68,12 @@ import com.fsck.k9.R;
|
|||
import com.fsck.k9.activity.compose.ComposeCryptoStatus;
|
||||
import com.fsck.k9.activity.compose.ComposeCryptoStatus.SendErrorState;
|
||||
import com.fsck.k9.activity.compose.CryptoSettingsDialog.OnCryptoModeChangedListener;
|
||||
import com.fsck.k9.activity.compose.IdentityAdapter;
|
||||
import com.fsck.k9.activity.compose.IdentityAdapter.IdentityContainer;
|
||||
import com.fsck.k9.activity.compose.RecipientMvpView;
|
||||
import com.fsck.k9.activity.compose.RecipientPresenter;
|
||||
import com.fsck.k9.activity.compose.RecipientPresenter.CryptoMode;
|
||||
import com.fsck.k9.activity.compose.SaveMessageTask;
|
||||
import com.fsck.k9.activity.loader.AttachmentContentLoader;
|
||||
import com.fsck.k9.activity.loader.AttachmentInfoLoader;
|
||||
import com.fsck.k9.activity.misc.Attachment;
|
||||
|
@ -128,15 +131,15 @@ public class MessageCompose extends K9Activity implements OnClickListener,
|
|||
|
||||
private static final long INVALID_DRAFT_ID = MessagingController.INVALID_MESSAGE_ID;
|
||||
|
||||
private static final String ACTION_COMPOSE = "com.fsck.k9.intent.action.COMPOSE";
|
||||
private static final String ACTION_REPLY = "com.fsck.k9.intent.action.REPLY";
|
||||
private static final String ACTION_REPLY_ALL = "com.fsck.k9.intent.action.REPLY_ALL";
|
||||
private static final String ACTION_FORWARD = "com.fsck.k9.intent.action.FORWARD";
|
||||
private static final String ACTION_EDIT_DRAFT = "com.fsck.k9.intent.action.EDIT_DRAFT";
|
||||
public static final String ACTION_COMPOSE = "com.fsck.k9.intent.action.COMPOSE";
|
||||
public static final String ACTION_REPLY = "com.fsck.k9.intent.action.REPLY";
|
||||
public static final String ACTION_REPLY_ALL = "com.fsck.k9.intent.action.REPLY_ALL";
|
||||
public static final String ACTION_FORWARD = "com.fsck.k9.intent.action.FORWARD";
|
||||
public static final String ACTION_EDIT_DRAFT = "com.fsck.k9.intent.action.EDIT_DRAFT";
|
||||
|
||||
private static final String EXTRA_ACCOUNT = "account";
|
||||
private static final String EXTRA_MESSAGE_BODY = "messageBody";
|
||||
private static final String EXTRA_MESSAGE_REFERENCE = "message_reference";
|
||||
public static final String EXTRA_ACCOUNT = "account";
|
||||
public static final String EXTRA_MESSAGE_BODY = "messageBody";
|
||||
public static final String EXTRA_MESSAGE_REFERENCE = "message_reference";
|
||||
|
||||
private static final String STATE_KEY_ATTACHMENTS =
|
||||
"com.fsck.k9.activity.MessageCompose.attachments";
|
||||
|
@ -169,7 +172,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
|
|||
private static final int MSG_PROGRESS_ON = 1;
|
||||
private static final int MSG_PROGRESS_OFF = 2;
|
||||
private static final int MSG_SKIPPED_ATTACHMENTS = 3;
|
||||
private static final int MSG_SAVED_DRAFT = 4;
|
||||
public static final int MSG_SAVED_DRAFT = 4;
|
||||
private static final int MSG_DISCARDED_DRAFT = 5;
|
||||
private static final int MSG_PERFORM_STALLED_ACTION = 6;
|
||||
|
||||
|
@ -396,91 +399,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
|
|||
private FontSizes mFontSizes = K9.getFontSizes();
|
||||
|
||||
|
||||
/**
|
||||
* Compose a new message using the given account. If account is null the default account
|
||||
* will be used.
|
||||
*/
|
||||
public static void actionCompose(Context context, Account account) {
|
||||
String accountUuid = (account == null) ?
|
||||
Preferences.getPreferences(context).getDefaultAccount().getUuid() :
|
||||
account.getUuid();
|
||||
|
||||
Intent i = new Intent(context, MessageCompose.class);
|
||||
i.putExtra(EXTRA_ACCOUNT, accountUuid);
|
||||
i.setAction(ACTION_COMPOSE);
|
||||
context.startActivity(i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get intent for composing a new message as a reply to the given message. If replyAll is true
|
||||
* the function is reply all instead of simply reply.
|
||||
* @param messageBody optional, for decrypted messages, null if it should be grabbed from the given message
|
||||
*/
|
||||
public static Intent getActionReplyIntent(
|
||||
Context context,
|
||||
LocalMessage message,
|
||||
boolean replyAll,
|
||||
String messageBody) {
|
||||
Intent i = new Intent(context, MessageCompose.class);
|
||||
i.putExtra(EXTRA_MESSAGE_BODY, messageBody);
|
||||
i.putExtra(EXTRA_MESSAGE_REFERENCE, message.makeMessageReference());
|
||||
if (replyAll) {
|
||||
i.setAction(ACTION_REPLY_ALL);
|
||||
} else {
|
||||
i.setAction(ACTION_REPLY);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
public static Intent getActionReplyIntent(Context context, MessageReference messageReference) {
|
||||
Intent intent = new Intent(context, MessageCompose.class);
|
||||
intent.setAction(ACTION_REPLY);
|
||||
intent.putExtra(EXTRA_MESSAGE_REFERENCE, messageReference);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
|
||||
return intent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compose a new message as a reply to the given message. If replyAll is true the function
|
||||
* is reply all instead of simply reply.
|
||||
* @param messageBody optional, for decrypted messages, null if it should be grabbed from the given message
|
||||
*/
|
||||
public static void actionReply(
|
||||
Context context,
|
||||
LocalMessage message,
|
||||
boolean replyAll,
|
||||
String messageBody) {
|
||||
context.startActivity(getActionReplyIntent(context, message, replyAll, messageBody));
|
||||
}
|
||||
|
||||
/**
|
||||
* Compose a new message as a forward of the given message.
|
||||
* @param messageBody optional, for decrypted messages, null if it should be grabbed from the given message
|
||||
*/
|
||||
public static void actionForward(
|
||||
Context context,
|
||||
LocalMessage message,
|
||||
String messageBody) {
|
||||
Intent i = new Intent(context, MessageCompose.class);
|
||||
i.putExtra(EXTRA_MESSAGE_BODY, messageBody);
|
||||
i.putExtra(EXTRA_MESSAGE_REFERENCE, message.makeMessageReference());
|
||||
i.setAction(ACTION_FORWARD);
|
||||
context.startActivity(i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Continue composition of the given message. This action modifies the way this Activity
|
||||
* handles certain actions.
|
||||
* Save will attempt to replace the message in the given folder with the updated version.
|
||||
* Discard will delete the message from the given folder.
|
||||
*/
|
||||
public static void actionEditDraft(Context context, MessageReference messageReference) {
|
||||
Intent i = new Intent(context, MessageCompose.class);
|
||||
i.putExtra(EXTRA_MESSAGE_REFERENCE, messageReference);
|
||||
i.setAction(ACTION_EDIT_DRAFT);
|
||||
context.startActivity(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -2340,8 +2259,8 @@ public class MessageCompose extends K9Activity implements OnClickListener,
|
|||
* contains both the insertion points and potentially modified HTML. The modified HTML should be
|
||||
* used in place of the HTML in the original message.</p>
|
||||
*
|
||||
* <p>This method loosely mimics the HTML forward/reply behavior of BlackBerry OS 4.5/BIS 2.5, which in turn mimics
|
||||
* Outlook 2003 (as best I can tell).</p>
|
||||
* <p>This method loosely mimics the HTML forward/reply behavior of BlackBerry OS 4.5/BIS 2.5,
|
||||
* which in turn mimics Outlook 2003 (as best I can tell).</p>
|
||||
*
|
||||
* @param content Content to examine for HTML insertion points
|
||||
* @return Insertion points and HTML to use for insertion.
|
||||
|
@ -2610,38 +2529,6 @@ public class MessageCompose extends K9Activity implements OnClickListener,
|
|||
}
|
||||
}
|
||||
|
||||
private static class SaveMessageTask extends AsyncTask<Void, Void, Void> {
|
||||
Context context;
|
||||
Account account;
|
||||
Contacts contacts;
|
||||
Handler handler;
|
||||
Message message;
|
||||
long draftId;
|
||||
boolean saveRemotely;
|
||||
|
||||
SaveMessageTask(Context context, Account account, Contacts contacts,
|
||||
Handler handler, Message message, long draftId, boolean saveRemotely) {
|
||||
this.context = context;
|
||||
this.account = account;
|
||||
this.contacts = contacts;
|
||||
this.handler = handler;
|
||||
this.message = message;
|
||||
this.draftId = draftId;
|
||||
this.saveRemotely = saveRemotely;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
final MessagingController messagingController = MessagingController.getInstance(context);
|
||||
Message draftMessage = messagingController.saveDraft(account, message, draftId, saveRemotely);
|
||||
draftId = messagingController.getId(draftMessage);
|
||||
|
||||
android.os.Message msg = android.os.Message.obtain(handler, MSG_SAVED_DRAFT, draftId);
|
||||
handler.sendMessage(msg);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static final int REPLY_WRAP_LINE_WIDTH = 72;
|
||||
private static final int QUOTE_BUFFER_LENGTH = 512; // amount of extra buffer to allocate to accommodate quoting headers or prefixes
|
||||
|
||||
|
@ -2782,139 +2669,10 @@ public class MessageCompose extends K9Activity implements OnClickListener,
|
|||
return insertable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to store an {@link Identity} instance together with the {@link Account} it belongs to.
|
||||
*
|
||||
* @see IdentityAdapter
|
||||
*/
|
||||
static class IdentityContainer {
|
||||
public final Identity identity;
|
||||
public final Account account;
|
||||
|
||||
IdentityContainer(Identity identity, Account account) {
|
||||
this.identity = identity;
|
||||
this.account = account;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapter for the <em>Choose identity</em> list view.
|
||||
*
|
||||
* <p>
|
||||
* Account names are displayed as section headers, identities as selectable list items.
|
||||
* </p>
|
||||
*/
|
||||
static class IdentityAdapter extends BaseAdapter {
|
||||
private LayoutInflater mLayoutInflater;
|
||||
private List<Object> mItems;
|
||||
|
||||
public IdentityAdapter(Context context) {
|
||||
mLayoutInflater = (LayoutInflater) context.getSystemService(
|
||||
Context.LAYOUT_INFLATER_SERVICE);
|
||||
|
||||
List<Object> items = new ArrayList<>();
|
||||
Preferences prefs = Preferences.getPreferences(context.getApplicationContext());
|
||||
Collection<Account> accounts = prefs.getAvailableAccounts();
|
||||
for (Account account : accounts) {
|
||||
items.add(account);
|
||||
List<Identity> identities = account.getIdentities();
|
||||
for (Identity identity : identities) {
|
||||
items.add(new IdentityContainer(identity, account));
|
||||
}
|
||||
}
|
||||
mItems = items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return mItems.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViewTypeCount() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
return (mItems.get(position) instanceof Account) ? 0 : 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(int position) {
|
||||
return (mItems.get(position) instanceof IdentityContainer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return mItems.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasStableIds() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
Object item = mItems.get(position);
|
||||
|
||||
View view = null;
|
||||
if (item instanceof Account) {
|
||||
if (convertView != null && convertView.getTag() instanceof AccountHolder) {
|
||||
view = convertView;
|
||||
} else {
|
||||
view = mLayoutInflater.inflate(R.layout.choose_account_item, parent, false);
|
||||
AccountHolder holder = new AccountHolder();
|
||||
holder.name = (TextView) view.findViewById(R.id.name);
|
||||
holder.chip = view.findViewById(R.id.chip);
|
||||
view.setTag(holder);
|
||||
}
|
||||
|
||||
Account account = (Account) item;
|
||||
AccountHolder holder = (AccountHolder) view.getTag();
|
||||
holder.name.setText(account.getDescription());
|
||||
holder.chip.setBackgroundColor(account.getChipColor());
|
||||
} else if (item instanceof IdentityContainer) {
|
||||
if (convertView != null && convertView.getTag() instanceof IdentityHolder) {
|
||||
view = convertView;
|
||||
} else {
|
||||
view = mLayoutInflater.inflate(R.layout.choose_identity_item, parent, false);
|
||||
IdentityHolder holder = new IdentityHolder();
|
||||
holder.name = (TextView) view.findViewById(R.id.name);
|
||||
holder.description = (TextView) view.findViewById(R.id.description);
|
||||
view.setTag(holder);
|
||||
}
|
||||
|
||||
IdentityContainer identityContainer = (IdentityContainer) item;
|
||||
Identity identity = identityContainer.identity;
|
||||
IdentityHolder holder = (IdentityHolder) view.getTag();
|
||||
holder.name.setText(identity.getDescription());
|
||||
holder.description.setText(getIdentityDescription(identity));
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
static class AccountHolder {
|
||||
public TextView name;
|
||||
public View chip;
|
||||
}
|
||||
|
||||
static class IdentityHolder {
|
||||
public TextView name;
|
||||
public TextView description;
|
||||
}
|
||||
}
|
||||
|
||||
private static String getIdentityDescription(Identity identity) {
|
||||
return String.format("%s <%s>", identity.getName(), identity.getEmail());
|
||||
}
|
||||
|
||||
private void setMessageFormat(SimpleMessageFormat format) {
|
||||
// This method will later be used to enable/disable the rich text editing mode.
|
||||
|
|
|
@ -34,6 +34,7 @@ import com.fsck.k9.K9;
|
|||
import com.fsck.k9.K9.SplitViewMode;
|
||||
import com.fsck.k9.Preferences;
|
||||
import com.fsck.k9.R;
|
||||
import com.fsck.k9.activity.compose.MessageActions;
|
||||
import com.fsck.k9.activity.misc.SwipeGestureDetector.OnSwipeGestureListener;
|
||||
import com.fsck.k9.activity.setup.AccountSettings;
|
||||
import com.fsck.k9.activity.setup.FolderSettings;
|
||||
|
@ -1181,7 +1182,7 @@ public class MessageList extends K9Activity implements MessageListFragmentListen
|
|||
String folderName = messageReference.getFolderName();
|
||||
|
||||
if (folderName.equals(account.getDraftsFolderName())) {
|
||||
MessageCompose.actionEditDraft(this, messageReference);
|
||||
MessageActions.actionEditDraft(this, messageReference);
|
||||
} else {
|
||||
mMessageViewContainer.removeView(mMessageViewPlaceHolder);
|
||||
|
||||
|
@ -1203,27 +1204,27 @@ public class MessageList extends K9Activity implements MessageListFragmentListen
|
|||
|
||||
@Override
|
||||
public void onResendMessage(LocalMessage message) {
|
||||
MessageCompose.actionEditDraft(this, message.makeMessageReference());
|
||||
MessageActions.actionEditDraft(this, message.makeMessageReference());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onForward(LocalMessage message) {
|
||||
MessageCompose.actionForward(this, message, null);
|
||||
MessageActions.actionForward(this, message, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReply(LocalMessage message) {
|
||||
MessageCompose.actionReply(this, message, false, null);
|
||||
MessageActions.actionReply(this, message, false, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReplyAll(LocalMessage message) {
|
||||
MessageCompose.actionReply(this, message, true, null);
|
||||
MessageActions.actionReply(this, message, true, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCompose(Account account) {
|
||||
MessageCompose.actionCompose(this, account);
|
||||
MessageActions.actionCompose(this, account);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1409,17 +1410,17 @@ public class MessageList extends K9Activity implements MessageListFragmentListen
|
|||
|
||||
@Override
|
||||
public void onReply(LocalMessage message, PgpData pgpData) {
|
||||
MessageCompose.actionReply(this, message, false, pgpData.getDecryptedData());
|
||||
MessageActions.actionReply(this, message, false, pgpData.getDecryptedData());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReplyAll(LocalMessage message, PgpData pgpData) {
|
||||
MessageCompose.actionReply(this, message, true, pgpData.getDecryptedData());
|
||||
MessageActions.actionReply(this, message, true, pgpData.getDecryptedData());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onForward(LocalMessage mMessage, PgpData mPgpData) {
|
||||
MessageCompose.actionForward(this, mMessage, mPgpData.getDecryptedData());
|
||||
MessageActions.actionForward(this, mMessage, mPgpData.getDecryptedData());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,151 @@
|
|||
package com.fsck.k9.activity.compose;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.fsck.k9.Account;
|
||||
import com.fsck.k9.Identity;
|
||||
import com.fsck.k9.Preferences;
|
||||
import com.fsck.k9.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Adapter for the <em>Choose identity</em> list view.
|
||||
*
|
||||
* <p>
|
||||
* Account names are displayed as section headers, identities as selectable list items.
|
||||
* </p>
|
||||
*/
|
||||
public class IdentityAdapter extends BaseAdapter {
|
||||
private LayoutInflater mLayoutInflater;
|
||||
private List<Object> mItems;
|
||||
|
||||
public IdentityAdapter(Context context) {
|
||||
mLayoutInflater = (LayoutInflater) context.getSystemService(
|
||||
Context.LAYOUT_INFLATER_SERVICE);
|
||||
|
||||
List<Object> items = new ArrayList<>();
|
||||
Preferences prefs = Preferences.getPreferences(context.getApplicationContext());
|
||||
Collection<Account> accounts = prefs.getAvailableAccounts();
|
||||
for (Account account : accounts) {
|
||||
items.add(account);
|
||||
List<Identity> identities = account.getIdentities();
|
||||
for (Identity identity : identities) {
|
||||
items.add(new IdentityContainer(identity, account));
|
||||
}
|
||||
}
|
||||
mItems = items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return mItems.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViewTypeCount() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
return (mItems.get(position) instanceof Account) ? 0 : 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(int position) {
|
||||
return (mItems.get(position) instanceof IdentityContainer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return mItems.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasStableIds() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
Object item = mItems.get(position);
|
||||
|
||||
View view = null;
|
||||
if (item instanceof Account) {
|
||||
if (convertView != null && convertView.getTag() instanceof AccountHolder) {
|
||||
view = convertView;
|
||||
} else {
|
||||
view = mLayoutInflater.inflate(R.layout.choose_account_item, parent, false);
|
||||
AccountHolder holder = new AccountHolder();
|
||||
holder.name = (TextView) view.findViewById(R.id.name);
|
||||
holder.chip = view.findViewById(R.id.chip);
|
||||
view.setTag(holder);
|
||||
}
|
||||
|
||||
Account account = (Account) item;
|
||||
AccountHolder holder = (AccountHolder) view.getTag();
|
||||
holder.name.setText(account.getDescription());
|
||||
holder.chip.setBackgroundColor(account.getChipColor());
|
||||
} else if (item instanceof IdentityContainer) {
|
||||
if (convertView != null && convertView.getTag() instanceof IdentityHolder) {
|
||||
view = convertView;
|
||||
} else {
|
||||
view = mLayoutInflater.inflate(R.layout.choose_identity_item, parent, false);
|
||||
IdentityHolder holder = new IdentityHolder();
|
||||
holder.name = (TextView) view.findViewById(R.id.name);
|
||||
holder.description = (TextView) view.findViewById(R.id.description);
|
||||
view.setTag(holder);
|
||||
}
|
||||
|
||||
IdentityContainer identityContainer = (IdentityContainer) item;
|
||||
Identity identity = identityContainer.identity;
|
||||
IdentityHolder holder = (IdentityHolder) view.getTag();
|
||||
holder.name.setText(identity.getDescription());
|
||||
holder.description.setText(getIdentityDescription(identity));
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
private static String getIdentityDescription(Identity identity) {
|
||||
return String.format("%s <%s>", identity.getName(), identity.getEmail());
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to store an {@link Identity} instance together with the {@link Account} it belongs to.
|
||||
*
|
||||
* @see IdentityAdapter
|
||||
*/
|
||||
public static class IdentityContainer {
|
||||
public final Identity identity;
|
||||
public final Account account;
|
||||
|
||||
IdentityContainer(Identity identity, Account account) {
|
||||
this.identity = identity;
|
||||
this.account = account;
|
||||
}
|
||||
}
|
||||
|
||||
static class AccountHolder {
|
||||
public TextView name;
|
||||
public View chip;
|
||||
}
|
||||
|
||||
static class IdentityHolder {
|
||||
public TextView name;
|
||||
public TextView description;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
package com.fsck.k9.activity.compose;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.fsck.k9.Account;
|
||||
import com.fsck.k9.Preferences;
|
||||
import com.fsck.k9.activity.MessageCompose;
|
||||
import com.fsck.k9.activity.MessageReference;
|
||||
import com.fsck.k9.mailstore.LocalMessage;
|
||||
|
||||
public class MessageActions {
|
||||
/**
|
||||
* Compose a new message using the given account. If account is null the default account
|
||||
* will be used.
|
||||
*/
|
||||
public static void actionCompose(Context context, Account account) {
|
||||
String accountUuid = (account == null) ?
|
||||
Preferences.getPreferences(context).getDefaultAccount().getUuid() :
|
||||
account.getUuid();
|
||||
|
||||
Intent i = new Intent(context, MessageCompose.class);
|
||||
i.putExtra(MessageCompose.EXTRA_ACCOUNT, accountUuid);
|
||||
i.setAction(MessageCompose.ACTION_COMPOSE);
|
||||
context.startActivity(i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get intent for composing a new message as a reply to the given message. If replyAll is true
|
||||
* the function is reply all instead of simply reply.
|
||||
* @param messageBody optional, for decrypted messages, null if it should be grabbed from the given message
|
||||
*/
|
||||
public static Intent getActionReplyIntent(
|
||||
Context context,
|
||||
LocalMessage message,
|
||||
boolean replyAll,
|
||||
String messageBody) {
|
||||
Intent i = new Intent(context, MessageCompose.class);
|
||||
i.putExtra(MessageCompose.EXTRA_MESSAGE_BODY, messageBody);
|
||||
i.putExtra(MessageCompose.EXTRA_MESSAGE_REFERENCE, message.makeMessageReference());
|
||||
if (replyAll) {
|
||||
i.setAction(MessageCompose.ACTION_REPLY_ALL);
|
||||
} else {
|
||||
i.setAction(MessageCompose.ACTION_REPLY);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
public static Intent getActionReplyIntent(Context context, MessageReference messageReference) {
|
||||
Intent intent = new Intent(context, MessageCompose.class);
|
||||
intent.setAction(MessageCompose.ACTION_REPLY);
|
||||
intent.putExtra(MessageCompose.EXTRA_MESSAGE_REFERENCE, messageReference);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
|
||||
return intent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compose a new message as a reply to the given message. If replyAll is true the function
|
||||
* is reply all instead of simply reply.
|
||||
* @param messageBody optional, for decrypted messages, null if it should be grabbed from the given message
|
||||
*/
|
||||
public static void actionReply(
|
||||
Context context,
|
||||
LocalMessage message,
|
||||
boolean replyAll,
|
||||
String messageBody) {
|
||||
context.startActivity(getActionReplyIntent(context, message, replyAll, messageBody));
|
||||
}
|
||||
|
||||
/**
|
||||
* Compose a new message as a forward of the given message.
|
||||
* @param messageBody optional, for decrypted messages, null if it should be grabbed from the given message
|
||||
*/
|
||||
public static void actionForward(
|
||||
Context context,
|
||||
LocalMessage message,
|
||||
String messageBody) {
|
||||
Intent i = new Intent(context, MessageCompose.class);
|
||||
i.putExtra(MessageCompose.EXTRA_MESSAGE_BODY, messageBody);
|
||||
i.putExtra(MessageCompose.EXTRA_MESSAGE_REFERENCE, message.makeMessageReference());
|
||||
i.setAction(MessageCompose.ACTION_FORWARD);
|
||||
context.startActivity(i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Continue composition of the given message. This action modifies the way this Activity
|
||||
* handles certain actions.
|
||||
* Save will attempt to replace the message in the given folder with the updated version.
|
||||
* Discard will delete the message from the given folder.
|
||||
*/
|
||||
public static void actionEditDraft(Context context, MessageReference messageReference) {
|
||||
Intent i = new Intent(context, MessageCompose.class);
|
||||
i.putExtra(MessageCompose.EXTRA_MESSAGE_REFERENCE, messageReference);
|
||||
i.setAction(MessageCompose.ACTION_EDIT_DRAFT);
|
||||
context.startActivity(i);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package com.fsck.k9.activity.compose;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Handler;
|
||||
|
||||
import com.fsck.k9.Account;
|
||||
import com.fsck.k9.activity.MessageCompose;
|
||||
import com.fsck.k9.controller.MessagingController;
|
||||
import com.fsck.k9.helper.Contacts;
|
||||
import com.fsck.k9.mail.Message;
|
||||
|
||||
public class SaveMessageTask extends AsyncTask<Void, Void, Void> {
|
||||
Context context;
|
||||
Account account;
|
||||
Contacts contacts;
|
||||
Handler handler;
|
||||
Message message;
|
||||
long draftId;
|
||||
boolean saveRemotely;
|
||||
|
||||
public SaveMessageTask(Context context, Account account, Contacts contacts,
|
||||
Handler handler, Message message, long draftId, boolean saveRemotely) {
|
||||
this.context = context;
|
||||
this.account = account;
|
||||
this.contacts = contacts;
|
||||
this.handler = handler;
|
||||
this.message = message;
|
||||
this.draftId = draftId;
|
||||
this.saveRemotely = saveRemotely;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
final MessagingController messagingController = MessagingController.getInstance(context);
|
||||
Message draftMessage = messagingController.saveDraft(account, message, draftId, saveRemotely);
|
||||
draftId = messagingController.getId(draftMessage);
|
||||
|
||||
android.os.Message msg = android.os.Message.obtain(handler, MessageCompose.MSG_SAVED_DRAFT, draftId);
|
||||
handler.sendMessage(msg);
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -19,6 +19,7 @@ import com.fsck.k9.activity.MessageCompose;
|
|||
import com.fsck.k9.activity.MessageList;
|
||||
import com.fsck.k9.activity.MessageReference;
|
||||
import com.fsck.k9.activity.NotificationDeleteConfirmation;
|
||||
import com.fsck.k9.activity.compose.MessageActions;
|
||||
import com.fsck.k9.search.LocalSearch;
|
||||
|
||||
|
||||
|
@ -91,7 +92,7 @@ class NotificationActionCreator {
|
|||
}
|
||||
|
||||
public PendingIntent createReplyPendingIntent(MessageReference messageReference, int notificationId) {
|
||||
Intent intent = MessageCompose.getActionReplyIntent(context, messageReference);
|
||||
Intent intent = MessageActions.getActionReplyIntent(context, messageReference);
|
||||
|
||||
return PendingIntent.getActivity(context, notificationId, intent,
|
||||
PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
|
||||
|
|
Loading…
Reference in a new issue