2015-01-12 16:46:56 -05:00
|
|
|
package com.fsck.k9.ui.messageview;
|
2008-11-01 17:32:06 -04:00
|
|
|
|
2012-07-12 12:29:41 -04:00
|
|
|
import java.io.File;
|
2012-11-03 00:56:12 -04:00
|
|
|
import java.util.Collections;
|
2014-03-03 10:40:23 -05:00
|
|
|
import java.util.Locale;
|
2012-07-12 12:29:41 -04:00
|
|
|
|
2012-09-26 12:03:14 -04:00
|
|
|
import android.app.Activity;
|
2014-06-21 10:54:09 -04:00
|
|
|
import android.app.Fragment;
|
2015-01-12 22:17:25 -05:00
|
|
|
import android.app.LoaderManager.LoaderCallbacks;
|
2008-11-01 17:32:06 -04:00
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
2015-01-12 22:17:25 -05:00
|
|
|
import android.content.Loader;
|
2008-11-01 17:32:06 -04:00
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Handler;
|
2014-06-21 10:54:09 -04:00
|
|
|
import android.app.DialogFragment;
|
|
|
|
import android.app.FragmentManager;
|
2015-01-12 22:17:25 -05:00
|
|
|
import android.text.TextUtils;
|
2008-11-01 17:32:06 -04:00
|
|
|
import android.util.Log;
|
2013-02-04 12:04:34 -05:00
|
|
|
import android.view.ContextThemeWrapper;
|
2012-07-12 12:29:41 -04:00
|
|
|
import android.view.KeyEvent;
|
2012-09-26 12:03:14 -04:00
|
|
|
import android.view.LayoutInflater;
|
2012-07-12 12:29:41 -04:00
|
|
|
import android.view.View;
|
2008-11-01 17:32:06 -04:00
|
|
|
import android.view.View.OnClickListener;
|
2012-09-26 12:03:14 -04:00
|
|
|
import android.view.ViewGroup;
|
2012-07-12 12:29:41 -04:00
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
import com.fsck.k9.Account;
|
|
|
|
import com.fsck.k9.K9;
|
|
|
|
import com.fsck.k9.Preferences;
|
|
|
|
import com.fsck.k9.R;
|
2012-09-26 12:03:14 -04:00
|
|
|
import com.fsck.k9.activity.ChooseFolder;
|
|
|
|
import com.fsck.k9.activity.MessageReference;
|
2010-05-19 14:17:06 -04:00
|
|
|
import com.fsck.k9.controller.MessagingController;
|
|
|
|
import com.fsck.k9.controller.MessagingListener;
|
2010-08-22 05:51:17 -04:00
|
|
|
import com.fsck.k9.crypto.PgpData;
|
2015-01-12 16:46:56 -05:00
|
|
|
import com.fsck.k9.fragment.ConfirmationDialogFragment;
|
2012-09-26 12:03:14 -04:00
|
|
|
import com.fsck.k9.fragment.ConfirmationDialogFragment.ConfirmationDialogFragmentListener;
|
2015-01-12 16:46:56 -05:00
|
|
|
import com.fsck.k9.fragment.ProgressDialogFragment;
|
2011-04-24 00:00:10 -04:00
|
|
|
import com.fsck.k9.helper.FileBrowserHelper;
|
|
|
|
import com.fsck.k9.helper.FileBrowserHelper.FileBrowserFailOverCallback;
|
2012-07-12 12:29:41 -04:00
|
|
|
import com.fsck.k9.mail.Flag;
|
|
|
|
import com.fsck.k9.mail.Message;
|
|
|
|
import com.fsck.k9.mail.MessagingException;
|
|
|
|
import com.fsck.k9.mail.Part;
|
2014-12-14 10:28:42 -05:00
|
|
|
import com.fsck.k9.mailstore.LocalMessage;
|
2015-01-14 03:56:57 -05:00
|
|
|
import com.fsck.k9.mailstore.MessageViewInfo;
|
|
|
|
import com.fsck.k9.ui.message.DecodeMessageLoader;
|
2015-01-12 22:17:25 -05:00
|
|
|
import com.fsck.k9.ui.message.LocalMessageLoader;
|
2015-01-15 02:25:43 -05:00
|
|
|
import com.fsck.k9.ui.messageview.AttachmentView.AttachmentFileDownloadCallback;
|
2012-09-26 12:03:14 -04:00
|
|
|
import com.fsck.k9.view.MessageHeader;
|
2010-12-28 04:07:59 -05:00
|
|
|
|
2014-06-21 10:54:09 -04:00
|
|
|
import org.openintents.openpgp.OpenPgpSignatureResult;
|
|
|
|
|
2012-09-26 12:03:14 -04:00
|
|
|
|
2014-06-21 10:54:09 -04:00
|
|
|
public class MessageViewFragment extends Fragment implements OnClickListener,
|
2014-09-18 13:45:25 -04:00
|
|
|
ConfirmationDialogFragmentListener {
|
2012-09-26 12:03:14 -04:00
|
|
|
|
|
|
|
private static final String ARG_REFERENCE = "reference";
|
|
|
|
|
|
|
|
private static final String STATE_MESSAGE_REFERENCE = "reference";
|
2010-08-22 05:51:17 -04:00
|
|
|
private static final String STATE_PGP_DATA = "pgpData";
|
2012-09-26 12:03:14 -04:00
|
|
|
|
2009-03-05 02:32:45 -05:00
|
|
|
private static final int ACTIVITY_CHOOSE_FOLDER_MOVE = 1;
|
|
|
|
private static final int ACTIVITY_CHOOSE_FOLDER_COPY = 2;
|
2011-04-24 00:00:10 -04:00
|
|
|
private static final int ACTIVITY_CHOOSE_DIRECTORY = 3;
|
2011-02-11 10:09:15 -05:00
|
|
|
|
2015-01-12 22:17:25 -05:00
|
|
|
private static final int LOCAL_MESSAGE_LOADER_ID = 1;
|
2015-01-14 03:56:57 -05:00
|
|
|
private static final int DECODE_MESSAGE_LOADER_ID = 2;
|
2015-01-12 22:17:25 -05:00
|
|
|
|
2011-02-11 10:09:15 -05:00
|
|
|
|
2012-09-26 12:03:14 -04:00
|
|
|
public static MessageViewFragment newInstance(MessageReference reference) {
|
|
|
|
MessageViewFragment fragment = new MessageViewFragment();
|
|
|
|
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putParcelable(ARG_REFERENCE, reference);
|
|
|
|
fragment.setArguments(args);
|
|
|
|
|
|
|
|
return fragment;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private SingleMessageView mMessageView;
|
2011-02-11 10:09:15 -05:00
|
|
|
private PgpData mPgpData;
|
2008-11-01 17:32:06 -04:00
|
|
|
private Account mAccount;
|
2010-04-24 10:59:27 -04:00
|
|
|
private MessageReference mMessageReference;
|
2014-12-11 22:23:32 -05:00
|
|
|
private LocalMessage mMessage;
|
2012-09-26 12:03:14 -04:00
|
|
|
private MessagingController mController;
|
2008-11-01 17:32:06 -04:00
|
|
|
private Listener mListener = new Listener();
|
|
|
|
private MessageViewHandler mHandler = new MessageViewHandler();
|
2013-02-05 12:35:43 -05:00
|
|
|
private LayoutInflater mLayoutInflater;
|
2010-11-13 16:40:56 -05:00
|
|
|
|
2011-04-24 00:00:10 -04:00
|
|
|
/** this variable is used to save the calling AttachmentView
|
|
|
|
* until the onActivityResult is called.
|
|
|
|
* => with this reference we can identity the caller
|
|
|
|
*/
|
|
|
|
private AttachmentView attachmentTmpStore;
|
|
|
|
|
2011-03-31 22:21:27 -04:00
|
|
|
/**
|
|
|
|
* Used to temporarily store the destination folder for refile operations if a confirmation
|
|
|
|
* dialog is shown.
|
|
|
|
*/
|
|
|
|
private String mDstFolder;
|
|
|
|
|
2012-09-26 12:03:14 -04:00
|
|
|
private MessageViewFragmentListener mFragmentListener;
|
2008-12-21 12:44:18 -05:00
|
|
|
|
2013-02-01 20:35:48 -05:00
|
|
|
/**
|
|
|
|
* {@code true} after {@link #onCreate(Bundle)} has been executed. This is used by
|
|
|
|
* {@code MessageList.configureMenu()} to make sure the fragment has been initialized before
|
|
|
|
* it is used.
|
|
|
|
*/
|
|
|
|
private boolean mInitialized = false;
|
|
|
|
|
2013-04-01 20:17:28 -04:00
|
|
|
private Context mContext;
|
|
|
|
|
2015-01-12 22:17:25 -05:00
|
|
|
private LoaderCallbacks<LocalMessage> localMessageLoaderCallback = new LocalMessageLoaderCallback();
|
2015-01-14 03:56:57 -05:00
|
|
|
private LoaderCallbacks<MessageViewInfo> decodeMessageLoaderCallback = new DecodeMessageLoaderCallback();
|
|
|
|
private MessageViewInfo messageViewInfo;
|
2015-01-12 22:17:25 -05:00
|
|
|
|
2010-08-29 22:16:20 -04:00
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
class MessageViewHandler extends Handler {
|
2011-01-10 12:47:28 -05:00
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public void progress(final boolean progress) {
|
2012-09-26 12:03:14 -04:00
|
|
|
post(new Runnable() {
|
2013-02-03 11:23:39 -05:00
|
|
|
@Override
|
2011-02-06 17:09:48 -05:00
|
|
|
public void run() {
|
2012-09-26 12:03:14 -04:00
|
|
|
setProgress(progress);
|
2010-01-03 21:06:40 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-02-14 20:26:00 -05:00
|
|
|
/* A helper for a set of "show a toast" methods */
|
|
|
|
private void showToast(final String message, final int toastLength) {
|
2012-09-26 12:03:14 -04:00
|
|
|
post(new Runnable() {
|
2013-02-03 11:23:39 -05:00
|
|
|
@Override
|
2011-02-06 17:09:48 -05:00
|
|
|
public void run() {
|
2012-09-26 12:03:14 -04:00
|
|
|
Toast.makeText(getActivity(), message, toastLength).show();
|
2010-01-03 21:06:40 -05:00
|
|
|
}
|
|
|
|
});
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
|
2011-02-14 20:26:00 -05:00
|
|
|
public void networkError() {
|
2013-03-04 22:18:54 -05:00
|
|
|
// FIXME: This is a hack. Fix the Handler madness!
|
|
|
|
Context context = getActivity();
|
|
|
|
if (context == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
showToast(context.getString(R.string.status_network_error), Toast.LENGTH_LONG);
|
2011-02-14 20:26:00 -05:00
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public void fetchingAttachment() {
|
2013-03-04 22:18:54 -05:00
|
|
|
Context context = getActivity();
|
|
|
|
if (context == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
showToast(context.getString(R.string.message_view_fetching_attachment_toast), Toast.LENGTH_SHORT);
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-26 12:03:14 -04:00
|
|
|
@Override
|
|
|
|
public void onAttach(Activity activity) {
|
|
|
|
super.onAttach(activity);
|
|
|
|
|
2013-04-01 20:17:28 -04:00
|
|
|
mContext = activity.getApplicationContext();
|
|
|
|
|
2012-09-26 12:03:14 -04:00
|
|
|
try {
|
|
|
|
mFragmentListener = (MessageViewFragmentListener) activity;
|
|
|
|
} catch (ClassCastException e) {
|
|
|
|
throw new ClassCastException(activity.getClass() +
|
|
|
|
" must implement MessageViewFragmentListener");
|
|
|
|
}
|
2009-11-21 17:45:14 -05:00
|
|
|
}
|
2008-11-01 17:32:06 -04:00
|
|
|
|
2010-04-16 08:20:10 -04:00
|
|
|
@Override
|
2012-09-26 12:03:14 -04:00
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
2009-11-19 01:03:59 -05:00
|
|
|
|
2012-09-26 12:03:14 -04:00
|
|
|
// This fragments adds options to the action bar
|
|
|
|
setHasOptionsMenu(true);
|
|
|
|
|
|
|
|
mController = MessagingController.getInstance(getActivity().getApplication());
|
2013-02-01 20:35:48 -05:00
|
|
|
mInitialized = true;
|
2012-09-26 12:03:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
|
|
|
Bundle savedInstanceState) {
|
2013-02-05 14:46:56 -05:00
|
|
|
Context context = new ContextThemeWrapper(inflater.getContext(),
|
2013-02-04 12:04:34 -05:00
|
|
|
K9.getK9ThemeResourceId(K9.getK9MessageViewTheme()));
|
2013-02-05 12:35:43 -05:00
|
|
|
mLayoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
|
View view = mLayoutInflater.inflate(R.layout.message, container, false);
|
2012-09-26 12:03:14 -04:00
|
|
|
|
|
|
|
|
|
|
|
mMessageView = (SingleMessageView) view.findViewById(R.id.message_view);
|
2011-02-11 10:09:15 -05:00
|
|
|
|
2011-04-24 00:00:10 -04:00
|
|
|
//set a callback for the attachment view. With this callback the attachmentview
|
|
|
|
//request the start of a filebrowser activity.
|
|
|
|
mMessageView.setAttachmentCallback(new AttachmentFileDownloadCallback() {
|
|
|
|
|
|
|
|
@Override
|
2014-10-20 20:28:38 -04:00
|
|
|
public void pickDirectoryToSaveAttachmentTo(final AttachmentView caller) {
|
2011-04-24 00:00:10 -04:00
|
|
|
FileBrowserHelper.getInstance()
|
2012-09-26 12:03:14 -04:00
|
|
|
.showFileBrowserActivity(MessageViewFragment.this,
|
2011-04-24 00:00:10 -04:00
|
|
|
null,
|
2012-09-26 12:03:14 -04:00
|
|
|
ACTIVITY_CHOOSE_DIRECTORY,
|
2011-04-24 00:00:10 -04:00
|
|
|
callback);
|
|
|
|
attachmentTmpStore = caller;
|
|
|
|
}
|
2012-09-26 12:03:14 -04:00
|
|
|
|
2011-04-24 00:00:10 -04:00
|
|
|
FileBrowserFailOverCallback callback = new FileBrowserFailOverCallback() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPathEntered(String path) {
|
|
|
|
attachmentTmpStore.writeFile(new File(path));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCancel() {
|
|
|
|
// canceled, do nothing
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
2011-11-02 19:39:23 -04:00
|
|
|
|
2015-01-12 22:17:25 -05:00
|
|
|
mMessageView.initialize(this, new OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
onToggleFlagged();
|
|
|
|
}
|
|
|
|
});
|
2012-09-09 19:04:47 -04:00
|
|
|
mMessageView.downloadRemainderButton().setOnClickListener(this);
|
2011-06-08 16:53:23 -04:00
|
|
|
|
2012-09-26 12:03:14 -04:00
|
|
|
mFragmentListener.messageHeaderViewAvailable(mMessageView.getMessageHeaderView());
|
2011-12-05 12:16:43 -05:00
|
|
|
|
2012-09-26 12:03:14 -04:00
|
|
|
return view;
|
|
|
|
}
|
2010-12-25 22:51:33 -05:00
|
|
|
|
2012-09-26 12:03:14 -04:00
|
|
|
@Override
|
|
|
|
public void onActivityCreated(Bundle savedInstanceState) {
|
|
|
|
super.onActivityCreated(savedInstanceState);
|
2010-12-25 22:51:33 -05:00
|
|
|
|
2012-09-26 12:03:14 -04:00
|
|
|
MessageReference messageReference;
|
|
|
|
if (savedInstanceState != null) {
|
|
|
|
mPgpData = (PgpData) savedInstanceState.get(STATE_PGP_DATA);
|
|
|
|
messageReference = (MessageReference) savedInstanceState.get(STATE_MESSAGE_REFERENCE);
|
|
|
|
} else {
|
|
|
|
Bundle args = getArguments();
|
|
|
|
messageReference = (MessageReference) args.getParcelable(ARG_REFERENCE);
|
2010-12-25 22:51:33 -05:00
|
|
|
}
|
2010-07-27 08:10:09 -04:00
|
|
|
|
2012-09-26 12:03:14 -04:00
|
|
|
displayMessage(messageReference, (mPgpData == null));
|
2010-12-25 22:51:33 -05:00
|
|
|
}
|
|
|
|
|
2009-10-22 11:54:49 -04:00
|
|
|
@Override
|
2012-09-26 12:03:14 -04:00
|
|
|
public void onSaveInstanceState(Bundle outState) {
|
2012-02-23 21:43:42 -05:00
|
|
|
super.onSaveInstanceState(outState);
|
2012-09-26 12:03:14 -04:00
|
|
|
outState.putParcelable(STATE_MESSAGE_REFERENCE, mMessageReference);
|
2011-02-11 10:09:15 -05:00
|
|
|
outState.putSerializable(STATE_PGP_DATA, mPgpData);
|
2010-07-27 08:10:09 -04:00
|
|
|
}
|
|
|
|
|
2012-09-26 12:03:14 -04:00
|
|
|
private void displayMessage(MessageReference ref, boolean resetPgpData) {
|
2010-04-24 10:59:27 -04:00
|
|
|
mMessageReference = ref;
|
2012-09-26 12:03:14 -04:00
|
|
|
if (K9.DEBUG) {
|
2010-04-24 10:59:27 -04:00
|
|
|
Log.d(K9.LOG_TAG, "MessageView displaying message " + mMessageReference);
|
2012-09-26 12:03:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Context appContext = getActivity().getApplicationContext();
|
|
|
|
mAccount = Preferences.getPreferences(appContext).getAccount(mMessageReference.accountUuid);
|
|
|
|
|
|
|
|
if (resetPgpData) {
|
|
|
|
// start with fresh, empty PGP data
|
|
|
|
mPgpData = new PgpData();
|
|
|
|
}
|
2012-02-23 21:43:42 -05:00
|
|
|
|
|
|
|
// Clear previous message
|
|
|
|
mMessageView.resetView();
|
|
|
|
mMessageView.resetHeaderView();
|
|
|
|
|
2015-01-12 22:17:25 -05:00
|
|
|
startLoadingMessageFromDatabase();
|
2013-01-28 19:19:53 -05:00
|
|
|
|
|
|
|
mFragmentListener.updateMenu();
|
Complete merge of DAmail functionality into K9mail. Following
features are added to K9mail:
1) Show unread message count on each folder
2) Sum unread count of all shown folders in an account to the account display
3) Periodically check selected folders for new mail, not just Inbox
4) Don't refresh folder when opened (unless folder is empty)
5) Show date and time of last sync for each folder
6) Fix timer for automatic periodic sync (use wakelock to assure completion)
7) Optimize local folder queries (speeds up account and folder lists)
8) Show Loading... message in status bar indicating which folder is being synced
9) Eliminate redundant sync of new messages (performance enhancement)
10) Improve notification text for multiple accounts
11) Do not automatically sync folders more often than the account-specific period
12) Use user-configured date and time formats
13) Select which folders are shown, using configurable Classes
14) Select which folders are synced, using configurable Classes
15) Added context (long press) menu to folders, to provide for Refresh
and Folder Settings
16) Status light flashes purple when there are unread messages
17) Folder list more quickly eliminates display of deleted and out-of-Class folders.
18) Delete works
19) Mark all messages as read (in the folder context menu)
20) Notifications only for new unread messages
21) One minute synchronization frequency
22) Deleting an unread message decrements unread counter
23) Notifications work for POP3 accounts
24) Message deletes work for POP3 accounts
25) Explicit errors show in folder list
26) Stack traces saved to folder K9mail-errors
27) Clear pending actions (danger, for emergencies only!)
28) Delete policy in Account settings
29) DNS cache in InetAddress disabled
30) Trapped some crash-causing error conditions
31) Eliminate duplicate copies to Sent folder
32) Prevent crashes due to message listener concurrency
33) Empty Trash
34) Nuclear "Mark all messages as read" (marks all messages as read in
server-side folder, irrespective of which messages have been downloaded)
35) Forward (alternate) to allow forwarding email through other programs
36) Accept text/plain Intents to allow other programs to send email through K9mail
37) Displays Outbox sending status
38) Manual retry of outbox sending when "Refresh"ing Outbox
39) Folder error status is persisted
40) Ability to log to arbitrary file
Fixes K9 issues 11, 23, 24, 65, 69, 71, 79, 81, 82, 83, 87, 101, 104,
107, 120, 148, 154
2008-12-30 22:49:09 -05:00
|
|
|
}
|
2008-11-01 17:32:06 -04:00
|
|
|
|
2015-01-12 22:17:25 -05:00
|
|
|
private void startLoadingMessageFromDatabase() {
|
|
|
|
getLoaderManager().initLoader(LOCAL_MESSAGE_LOADER_ID, null, localMessageLoaderCallback);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onLoadMessageFromDatabaseFinished(LocalMessage message) {
|
|
|
|
displayMessageHeader(message);
|
|
|
|
|
|
|
|
if (message.isBodyMissing()) {
|
|
|
|
startDownloadingMessageBody(message);
|
|
|
|
} else {
|
|
|
|
startExtractingTextAndAttachments(message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onLoadMessageFromDatabaseFailed() {
|
|
|
|
mMessageView.showStatusMessage(mContext.getString(R.string.status_invalid_id_error));
|
|
|
|
}
|
|
|
|
|
|
|
|
private void startDownloadingMessageBody(LocalMessage message) {
|
|
|
|
throw new RuntimeException("Not implemented yet");
|
|
|
|
}
|
|
|
|
|
|
|
|
private void startExtractingTextAndAttachments(LocalMessage message) {
|
2015-01-14 03:56:57 -05:00
|
|
|
getLoaderManager().initLoader(DECODE_MESSAGE_LOADER_ID, null, decodeMessageLoaderCallback);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onDecodeMessageFinished(MessageViewInfo messageContainer) {
|
2015-01-12 22:17:25 -05:00
|
|
|
//TODO: handle decryption and signature verification
|
2015-01-14 03:56:57 -05:00
|
|
|
this.messageViewInfo = messageContainer;
|
|
|
|
showMessage(messageContainer);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showMessage(MessageViewInfo messageContainer) {
|
2015-01-12 22:17:25 -05:00
|
|
|
try {
|
2015-01-14 03:56:57 -05:00
|
|
|
mMessageView.setMessage(mAccount, messageContainer, mPgpData, mController, mListener);
|
|
|
|
mMessageView.setShowDownloadButton(mMessage);
|
2015-01-12 22:17:25 -05:00
|
|
|
} catch (MessagingException e) {
|
|
|
|
Log.e(K9.LOG_TAG, "Error while trying to display message", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void displayMessageHeader(LocalMessage message) {
|
|
|
|
mMessageView.setHeaders(message, mAccount);
|
|
|
|
displayMessageSubject(getSubjectForMessage(message));
|
|
|
|
mFragmentListener.updateMenu();
|
|
|
|
}
|
|
|
|
|
2010-09-01 16:59:09 -04:00
|
|
|
/**
|
|
|
|
* Called from UI thread when user select Delete
|
|
|
|
*/
|
2012-09-26 12:03:14 -04:00
|
|
|
public void onDelete() {
|
2011-11-15 01:28:41 -05:00
|
|
|
if (K9.confirmDelete() || (K9.confirmDeleteStarred() && mMessage.isSet(Flag.FLAGGED))) {
|
2010-09-01 16:59:09 -04:00
|
|
|
showDialog(R.id.dialog_confirm_delete);
|
2011-02-06 17:09:48 -05:00
|
|
|
} else {
|
2010-09-01 16:59:09 -04:00
|
|
|
delete();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-07 15:27:22 -05:00
|
|
|
public void onToggleAllHeadersView() {
|
|
|
|
mMessageView.getMessageHeaderView().onShowAdditionalHeaders();
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean allHeadersVisible() {
|
|
|
|
return mMessageView.getMessageHeaderView().additionalHeadersVisible();
|
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
private void delete() {
|
|
|
|
if (mMessage != null) {
|
2010-07-11 15:40:48 -04:00
|
|
|
// Disable the delete button after it's tapped (to try to prevent
|
|
|
|
// accidental clicks)
|
2013-01-28 19:19:53 -05:00
|
|
|
mFragmentListener.disableDeleteAction();
|
2014-12-11 22:23:32 -05:00
|
|
|
LocalMessage messageToDelete = mMessage;
|
2012-09-26 12:03:14 -04:00
|
|
|
mFragmentListener.showNextMessageOrReturn();
|
2012-11-03 00:56:12 -04:00
|
|
|
mController.deleteMessages(Collections.singletonList(messageToDelete), null);
|
2010-06-14 09:46:08 -04:00
|
|
|
}
|
|
|
|
}
|
2009-11-29 23:03:00 -05:00
|
|
|
|
2012-09-26 12:03:14 -04:00
|
|
|
public void onRefile(String dstFolder) {
|
2011-02-06 17:09:48 -05:00
|
|
|
if (!mController.isMoveCapable(mAccount)) {
|
2010-07-05 09:41:52 -04:00
|
|
|
return;
|
|
|
|
}
|
2011-02-06 17:09:48 -05:00
|
|
|
if (!mController.isMoveCapable(mMessage)) {
|
2012-09-26 12:03:14 -04:00
|
|
|
Toast toast = Toast.makeText(getActivity(), R.string.move_copy_cannot_copy_unsynced_message, Toast.LENGTH_LONG);
|
2010-07-05 09:41:52 -04:00
|
|
|
toast.show();
|
|
|
|
return;
|
|
|
|
}
|
2011-03-31 22:21:27 -04:00
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
if (K9.FOLDER_NONE.equalsIgnoreCase(dstFolder)) {
|
2010-07-05 09:41:52 -04:00
|
|
|
return;
|
|
|
|
}
|
2011-03-31 22:21:27 -04:00
|
|
|
|
|
|
|
if (mAccount.getSpamFolderName().equals(dstFolder) && K9.confirmSpam()) {
|
|
|
|
mDstFolder = dstFolder;
|
|
|
|
showDialog(R.id.dialog_confirm_spam);
|
|
|
|
} else {
|
|
|
|
refileMessage(dstFolder);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void refileMessage(String dstFolder) {
|
|
|
|
String srcFolder = mMessageReference.folderName;
|
2014-12-11 22:23:32 -05:00
|
|
|
LocalMessage messageToMove = mMessage;
|
2012-09-26 12:03:14 -04:00
|
|
|
mFragmentListener.showNextMessageOrReturn();
|
2011-02-14 20:45:08 -05:00
|
|
|
mController.moveMessage(mAccount, srcFolder, messageToMove, dstFolder, null);
|
2010-07-05 09:41:52 -04:00
|
|
|
}
|
|
|
|
|
2012-09-26 12:03:14 -04:00
|
|
|
public void onReply() {
|
2011-02-06 17:09:48 -05:00
|
|
|
if (mMessage != null) {
|
2012-09-26 12:03:14 -04:00
|
|
|
mFragmentListener.onReply(mMessage, mPgpData);
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-26 12:03:14 -04:00
|
|
|
public void onReplyAll() {
|
2011-02-06 17:09:48 -05:00
|
|
|
if (mMessage != null) {
|
2012-09-26 12:03:14 -04:00
|
|
|
mFragmentListener.onReplyAll(mMessage, mPgpData);
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-26 12:03:14 -04:00
|
|
|
public void onForward() {
|
2011-02-06 17:09:48 -05:00
|
|
|
if (mMessage != null) {
|
2012-09-26 12:03:14 -04:00
|
|
|
mFragmentListener.onForward(mMessage, mPgpData);
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
}
|
2009-11-21 17:45:14 -05:00
|
|
|
|
2013-01-28 10:15:03 -05:00
|
|
|
public void onToggleFlagged() {
|
2011-02-06 17:09:48 -05:00
|
|
|
if (mMessage != null) {
|
2012-01-27 02:39:10 -05:00
|
|
|
boolean newState = !mMessage.isSet(Flag.FLAGGED);
|
|
|
|
mController.setFlag(mAccount, mMessage.getFolder().getName(),
|
2014-10-04 05:37:30 -04:00
|
|
|
Collections.singletonList(mMessage), Flag.FLAGGED, newState);
|
2012-02-04 08:52:45 -05:00
|
|
|
mMessageView.setHeaders(mMessage, mAccount);
|
2009-11-21 17:45:14 -05:00
|
|
|
}
|
2009-03-05 02:32:45 -05:00
|
|
|
}
|
2009-11-21 17:45:14 -05:00
|
|
|
|
2012-09-26 12:03:14 -04:00
|
|
|
public void onMove() {
|
2011-01-06 11:56:02 -05:00
|
|
|
if ((!mController.isMoveCapable(mAccount))
|
2011-02-06 17:09:48 -05:00
|
|
|
|| (mMessage == null)) {
|
2009-11-21 17:45:14 -05:00
|
|
|
return;
|
|
|
|
}
|
2011-02-06 17:09:48 -05:00
|
|
|
if (!mController.isMoveCapable(mMessage)) {
|
2012-09-26 12:03:14 -04:00
|
|
|
Toast toast = Toast.makeText(getActivity(), R.string.move_copy_cannot_copy_unsynced_message, Toast.LENGTH_LONG);
|
2009-11-21 17:45:14 -05:00
|
|
|
toast.show();
|
|
|
|
return;
|
|
|
|
}
|
2010-12-25 22:49:13 -05:00
|
|
|
|
|
|
|
startRefileActivity(ACTIVITY_CHOOSE_FOLDER_MOVE);
|
2012-09-26 12:03:14 -04:00
|
|
|
|
2009-11-21 17:45:14 -05:00
|
|
|
}
|
|
|
|
|
2012-09-26 12:03:14 -04:00
|
|
|
public void onCopy() {
|
2011-01-06 11:56:02 -05:00
|
|
|
if ((!mController.isCopyCapable(mAccount))
|
2011-02-06 17:09:48 -05:00
|
|
|
|| (mMessage == null)) {
|
2009-11-21 17:45:14 -05:00
|
|
|
return;
|
|
|
|
}
|
2011-02-06 17:09:48 -05:00
|
|
|
if (!mController.isCopyCapable(mMessage)) {
|
2012-09-26 12:03:14 -04:00
|
|
|
Toast toast = Toast.makeText(getActivity(), R.string.move_copy_cannot_copy_unsynced_message, Toast.LENGTH_LONG);
|
2009-11-21 17:45:14 -05:00
|
|
|
toast.show();
|
|
|
|
return;
|
|
|
|
}
|
2010-12-25 22:49:13 -05:00
|
|
|
|
|
|
|
startRefileActivity(ACTIVITY_CHOOSE_FOLDER_COPY);
|
|
|
|
}
|
|
|
|
|
2013-01-28 10:15:03 -05:00
|
|
|
public void onArchive() {
|
|
|
|
onRefile(mAccount.getArchiveFolderName());
|
|
|
|
}
|
|
|
|
|
2013-01-28 19:19:53 -05:00
|
|
|
public void onSpam() {
|
|
|
|
onRefile(mAccount.getSpamFolderName());
|
|
|
|
}
|
2012-09-15 01:13:46 -04:00
|
|
|
|
2013-01-28 19:19:53 -05:00
|
|
|
public void onSelectText() {
|
|
|
|
mMessageView.beginSelectingText();
|
2012-09-13 20:25:39 -04:00
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
private void startRefileActivity(int activity) {
|
2012-09-26 12:03:14 -04:00
|
|
|
Intent intent = new Intent(getActivity(), ChooseFolder.class);
|
2010-03-03 23:00:30 -05:00
|
|
|
intent.putExtra(ChooseFolder.EXTRA_ACCOUNT, mAccount.getUuid());
|
2010-04-24 10:59:27 -04:00
|
|
|
intent.putExtra(ChooseFolder.EXTRA_CUR_FOLDER, mMessageReference.folderName);
|
2010-07-04 19:29:57 -04:00
|
|
|
intent.putExtra(ChooseFolder.EXTRA_SEL_FOLDER, mAccount.getLastSelectedFolderName());
|
2010-05-01 16:06:52 -04:00
|
|
|
intent.putExtra(ChooseFolder.EXTRA_MESSAGE, mMessageReference);
|
2010-12-25 22:49:13 -05:00
|
|
|
startActivityForResult(intent, activity);
|
2009-11-21 17:45:14 -05:00
|
|
|
}
|
|
|
|
|
2010-05-21 11:34:29 -04:00
|
|
|
|
2009-11-21 17:45:14 -05:00
|
|
|
@Override
|
2012-09-26 12:03:14 -04:00
|
|
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
if (resultCode != Activity.RESULT_OK) {
|
2009-11-21 17:45:14 -05:00
|
|
|
return;
|
2012-09-26 12:03:14 -04:00
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
switch (requestCode) {
|
2012-09-26 12:03:14 -04:00
|
|
|
case ACTIVITY_CHOOSE_DIRECTORY: {
|
|
|
|
if (resultCode == Activity.RESULT_OK && data != null) {
|
|
|
|
// obtain the filename
|
|
|
|
Uri fileUri = data.getData();
|
|
|
|
if (fileUri != null) {
|
|
|
|
String filePath = fileUri.getPath();
|
|
|
|
if (filePath != null) {
|
|
|
|
attachmentTmpStore.writeFile(new File(filePath));
|
|
|
|
}
|
2011-04-24 00:00:10 -04:00
|
|
|
}
|
|
|
|
}
|
2012-09-26 12:03:14 -04:00
|
|
|
break;
|
2011-04-24 00:00:10 -04:00
|
|
|
}
|
2012-09-26 12:03:14 -04:00
|
|
|
case ACTIVITY_CHOOSE_FOLDER_MOVE:
|
|
|
|
case ACTIVITY_CHOOSE_FOLDER_COPY: {
|
|
|
|
if (data == null) {
|
|
|
|
return;
|
|
|
|
}
|
2011-04-24 00:00:10 -04:00
|
|
|
|
2012-09-26 12:03:14 -04:00
|
|
|
String destFolderName = data.getStringExtra(ChooseFolder.EXTRA_NEW_FOLDER);
|
|
|
|
MessageReference ref = data.getParcelableExtra(ChooseFolder.EXTRA_MESSAGE);
|
|
|
|
if (mMessageReference.equals(ref)) {
|
|
|
|
mAccount.setLastSelectedFolderName(destFolderName);
|
|
|
|
switch (requestCode) {
|
|
|
|
case ACTIVITY_CHOOSE_FOLDER_MOVE: {
|
|
|
|
mFragmentListener.showNextMessageOrReturn();
|
|
|
|
moveMessage(ref, destFolderName);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ACTIVITY_CHOOSE_FOLDER_COPY: {
|
|
|
|
copyMessage(ref, destFolderName);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-11-21 17:45:14 -05:00
|
|
|
}
|
2012-09-26 12:03:14 -04:00
|
|
|
break;
|
2011-02-06 17:09:48 -05:00
|
|
|
}
|
2009-11-21 17:45:14 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-28 19:19:53 -05:00
|
|
|
public void onSendAlternate() {
|
2011-02-06 17:09:48 -05:00
|
|
|
if (mMessage != null) {
|
2012-09-26 12:03:14 -04:00
|
|
|
mController.sendAlternate(getActivity(), mAccount, mMessage);
|
2009-12-26 13:31:55 -05:00
|
|
|
}
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
|
2013-01-28 10:15:03 -05:00
|
|
|
public void onToggleRead() {
|
2011-02-06 17:09:48 -05:00
|
|
|
if (mMessage != null) {
|
2012-01-27 02:39:10 -05:00
|
|
|
mController.setFlag(mAccount, mMessage.getFolder().getName(),
|
2014-10-04 05:37:30 -04:00
|
|
|
Collections.singletonList(mMessage), Flag.SEEN, !mMessage.isSet(Flag.SEEN));
|
2012-02-04 08:52:45 -05:00
|
|
|
mMessageView.setHeaders(mMessage, mAccount);
|
|
|
|
String subject = mMessage.getSubject();
|
2012-09-26 12:03:14 -04:00
|
|
|
displayMessageSubject(subject);
|
2013-01-28 19:19:53 -05:00
|
|
|
mFragmentListener.updateMenu();
|
2009-11-21 17:45:14 -05:00
|
|
|
}
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
private void onDownloadRemainder() {
|
|
|
|
if (mMessage.isSet(Flag.X_DOWNLOADED_FULL)) {
|
2010-07-18 21:57:49 -04:00
|
|
|
return;
|
|
|
|
}
|
2011-02-11 10:09:15 -05:00
|
|
|
mMessageView.downloadRemainderButton().setEnabled(false);
|
|
|
|
mController.loadMessageForViewRemote(mAccount, mMessageReference.folderName, mMessageReference.uid, mListener);
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
|
2012-09-26 12:03:14 -04:00
|
|
|
@Override
|
2011-02-06 17:09:48 -05:00
|
|
|
public void onClick(View view) {
|
2014-10-20 20:04:55 -04:00
|
|
|
if (view.getId() == R.id.download_remainder) {
|
|
|
|
onDownloadRemainder();
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-26 12:03:14 -04:00
|
|
|
private void setProgress(boolean enable) {
|
|
|
|
if (mFragmentListener != null) {
|
|
|
|
mFragmentListener.setProgress(enable);
|
|
|
|
}
|
|
|
|
}
|
2010-12-25 22:49:23 -05:00
|
|
|
|
2012-09-26 12:03:14 -04:00
|
|
|
private void displayMessageSubject(String subject) {
|
|
|
|
if (mFragmentListener != null) {
|
|
|
|
mFragmentListener.displayMessageSubject(subject);
|
2010-09-01 16:59:09 -04:00
|
|
|
}
|
2012-09-26 12:03:14 -04:00
|
|
|
}
|
|
|
|
|
2015-01-12 22:17:25 -05:00
|
|
|
private String getSubjectForMessage(LocalMessage message) {
|
|
|
|
String subject = message.getSubject();
|
|
|
|
if (TextUtils.isEmpty(subject)) {
|
|
|
|
return mContext.getString(R.string.general_no_subject);
|
|
|
|
}
|
|
|
|
|
|
|
|
return subject;
|
|
|
|
}
|
|
|
|
|
2012-09-26 12:03:14 -04:00
|
|
|
public void moveMessage(MessageReference reference, String destFolderName) {
|
|
|
|
mController.moveMessage(mAccount, mMessageReference.folderName, mMessage,
|
|
|
|
destFolderName, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void copyMessage(MessageReference reference, String destFolderName) {
|
|
|
|
mController.copyMessage(mAccount, mMessageReference.folderName, mMessage,
|
|
|
|
destFolderName, null);
|
2010-09-01 16:59:09 -04:00
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
class Listener extends MessagingListener {
|
2008-11-01 17:32:06 -04:00
|
|
|
@Override
|
2011-02-11 10:09:15 -05:00
|
|
|
public void loadMessageForViewHeadersAvailable(final Account account, String folder, String uid,
|
2011-02-06 17:09:48 -05:00
|
|
|
final Message message) {
|
2015-01-12 22:17:25 -05:00
|
|
|
throw new IllegalStateException();
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-02-23 21:43:42 -05:00
|
|
|
public void loadMessageForViewBodyAvailable(final Account account, String folder,
|
|
|
|
String uid, final Message message) {
|
2015-01-12 22:17:25 -05:00
|
|
|
throw new IllegalStateException();
|
2012-02-23 21:43:42 -05:00
|
|
|
}
|
2009-05-03 16:52:32 -04:00
|
|
|
|
2008-11-01 17:32:06 -04:00
|
|
|
@Override
|
2011-02-14 20:45:08 -05:00
|
|
|
public void loadMessageForViewFailed(Account account, String folder, String uid, final Throwable t) {
|
2015-01-12 22:17:25 -05:00
|
|
|
throw new IllegalStateException();
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-02-14 20:45:08 -05:00
|
|
|
public void loadMessageForViewFinished(Account account, String folder, String uid, final Message message) {
|
2015-01-12 22:17:25 -05:00
|
|
|
throw new IllegalStateException();
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-02-06 17:09:48 -05:00
|
|
|
public void loadMessageForViewStarted(Account account, String folder, String uid) {
|
2015-01-12 22:17:25 -05:00
|
|
|
throw new IllegalStateException();
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-02-20 12:49:55 -05:00
|
|
|
public void loadAttachmentStarted(Account account, Message message, Part part, Object tag, final boolean requiresDownload) {
|
2011-02-06 17:09:48 -05:00
|
|
|
if (mMessage != message) {
|
2009-07-01 17:31:51 -04:00
|
|
|
return;
|
|
|
|
}
|
2011-02-20 12:49:55 -05:00
|
|
|
mHandler.post(new Runnable() {
|
2013-02-03 11:23:39 -05:00
|
|
|
@Override
|
2011-02-20 12:49:55 -05:00
|
|
|
public void run() {
|
|
|
|
mMessageView.setAttachmentsEnabled(false);
|
|
|
|
showDialog(R.id.dialog_attachment_progress);
|
|
|
|
if (requiresDownload) {
|
|
|
|
mHandler.fetchingAttachment();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-02-20 12:49:55 -05:00
|
|
|
public void loadAttachmentFinished(Account account, Message message, Part part, final Object tag) {
|
2011-02-06 17:09:48 -05:00
|
|
|
if (mMessage != message) {
|
2009-07-01 17:31:51 -04:00
|
|
|
return;
|
|
|
|
}
|
2011-02-20 12:49:55 -05:00
|
|
|
mHandler.post(new Runnable() {
|
2013-02-03 11:23:39 -05:00
|
|
|
@Override
|
2011-02-20 12:49:55 -05:00
|
|
|
public void run() {
|
|
|
|
mMessageView.setAttachmentsEnabled(true);
|
|
|
|
removeDialog(R.id.dialog_attachment_progress);
|
|
|
|
Object[] params = (Object[]) tag;
|
|
|
|
boolean download = (Boolean) params[0];
|
|
|
|
AttachmentView attachment = (AttachmentView) params[1];
|
|
|
|
if (download) {
|
|
|
|
attachment.writeFile();
|
|
|
|
} else {
|
|
|
|
attachment.showFile();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-02-14 20:45:08 -05:00
|
|
|
public void loadAttachmentFailed(Account account, Message message, Part part, Object tag, String reason) {
|
2011-02-06 17:09:48 -05:00
|
|
|
if (mMessage != message) {
|
2009-07-01 17:31:51 -04:00
|
|
|
return;
|
|
|
|
}
|
2011-02-20 12:49:55 -05:00
|
|
|
mHandler.post(new Runnable() {
|
2013-02-03 11:23:39 -05:00
|
|
|
@Override
|
2011-02-20 12:49:55 -05:00
|
|
|
public void run() {
|
|
|
|
mMessageView.setAttachmentsEnabled(true);
|
|
|
|
removeDialog(R.id.dialog_attachment_progress);
|
|
|
|
mHandler.networkError();
|
|
|
|
}
|
|
|
|
});
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
}
|
2014-02-21 11:38:20 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Used by MessageOpenPgpView
|
|
|
|
*/
|
|
|
|
public void setMessageWithOpenPgp(String decryptedData, OpenPgpSignatureResult signatureResult) {
|
|
|
|
try {
|
|
|
|
// TODO: get rid of PgpData?
|
|
|
|
PgpData data = new PgpData();
|
|
|
|
data.setDecryptedData(decryptedData);
|
|
|
|
data.setSignatureResult(signatureResult);
|
2015-01-14 03:56:57 -05:00
|
|
|
mMessageView.setMessage(mAccount, messageViewInfo, data, mController, mListener);
|
2014-02-21 11:38:20 -05:00
|
|
|
} catch (MessagingException e) {
|
|
|
|
Log.e(K9.LOG_TAG, "displayMessageBody failed", e);
|
|
|
|
}
|
|
|
|
}
|
2008-11-01 17:32:06 -04:00
|
|
|
|
2012-09-26 12:03:14 -04:00
|
|
|
private void showDialog(int dialogId) {
|
|
|
|
DialogFragment fragment;
|
|
|
|
switch (dialogId) {
|
|
|
|
case R.id.dialog_confirm_delete: {
|
|
|
|
String title = getString(R.string.dialog_confirm_delete_title);
|
|
|
|
String message = getString(R.string.dialog_confirm_delete_message);
|
|
|
|
String confirmText = getString(R.string.dialog_confirm_delete_confirm_button);
|
|
|
|
String cancelText = getString(R.string.dialog_confirm_delete_cancel_button);
|
|
|
|
|
|
|
|
fragment = ConfirmationDialogFragment.newInstance(dialogId, title, message,
|
|
|
|
confirmText, cancelText);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case R.id.dialog_confirm_spam: {
|
|
|
|
String title = getString(R.string.dialog_confirm_spam_title);
|
|
|
|
String message = getResources().getQuantityString(R.plurals.dialog_confirm_spam_message, 1);
|
|
|
|
String confirmText = getString(R.string.dialog_confirm_spam_confirm_button);
|
|
|
|
String cancelText = getString(R.string.dialog_confirm_spam_cancel_button);
|
|
|
|
|
|
|
|
fragment = ConfirmationDialogFragment.newInstance(dialogId, title, message,
|
|
|
|
confirmText, cancelText);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case R.id.dialog_attachment_progress: {
|
2013-09-24 21:46:11 -04:00
|
|
|
String message = getString(R.string.dialog_attachment_progress_title);
|
|
|
|
fragment = ProgressDialogFragment.newInstance(null, message);
|
2012-09-26 12:03:14 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
throw new RuntimeException("Called showDialog(int) with unknown dialog id.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fragment.setTargetFragment(this, dialogId);
|
|
|
|
fragment.show(getFragmentManager(), getDialogTag(dialogId));
|
|
|
|
}
|
|
|
|
|
|
|
|
private void removeDialog(int dialogId) {
|
|
|
|
FragmentManager fm = getFragmentManager();
|
|
|
|
|
2013-04-17 23:43:11 -04:00
|
|
|
if (fm == null || isRemoving() || isDetached()) {
|
2013-04-01 20:30:07 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-26 12:03:14 -04:00
|
|
|
// Make sure the "show dialog" transaction has been processed when we call
|
|
|
|
// findFragmentByTag() below. Otherwise the fragment won't be found and the dialog will
|
|
|
|
// never be dismissed.
|
|
|
|
fm.executePendingTransactions();
|
|
|
|
|
|
|
|
DialogFragment fragment = (DialogFragment) fm.findFragmentByTag(getDialogTag(dialogId));
|
|
|
|
|
|
|
|
if (fragment != null) {
|
|
|
|
fragment.dismiss();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private String getDialogTag(int dialogId) {
|
2014-03-03 10:40:23 -05:00
|
|
|
return String.format(Locale.US, "dialog-%d", dialogId);
|
2012-09-26 12:03:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public void zoom(KeyEvent event) {
|
|
|
|
mMessageView.zoom(event);
|
|
|
|
}
|
|
|
|
|
2012-09-07 23:33:53 -04:00
|
|
|
@Override
|
2012-09-26 12:03:14 -04:00
|
|
|
public void doPositiveClick(int dialogId) {
|
|
|
|
switch (dialogId) {
|
|
|
|
case R.id.dialog_confirm_delete: {
|
|
|
|
delete();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case R.id.dialog_confirm_spam: {
|
|
|
|
refileMessage(mDstFolder);
|
|
|
|
mDstFolder = null;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void doNegativeClick(int dialogId) {
|
|
|
|
/* do nothing */
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void dialogCancelled(int dialogId) {
|
|
|
|
/* do nothing */
|
|
|
|
}
|
|
|
|
|
2013-01-28 10:15:03 -05:00
|
|
|
/**
|
|
|
|
* Get the {@link MessageReference} of the currently displayed message.
|
|
|
|
*/
|
|
|
|
public MessageReference getMessageReference() {
|
|
|
|
return mMessageReference;
|
|
|
|
}
|
|
|
|
|
2013-01-28 19:19:53 -05:00
|
|
|
public boolean isMessageRead() {
|
|
|
|
return (mMessage != null) ? mMessage.isSet(Flag.SEEN) : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isCopyCapable() {
|
|
|
|
return mController.isCopyCapable(mAccount);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isMoveCapable() {
|
|
|
|
return mController.isMoveCapable(mAccount);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canMessageBeArchived() {
|
|
|
|
return (!mMessageReference.folderName.equals(mAccount.getArchiveFolderName())
|
|
|
|
&& mAccount.hasArchiveFolder());
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canMessageBeMovedToSpam() {
|
|
|
|
return (!mMessageReference.folderName.equals(mAccount.getSpamFolderName())
|
|
|
|
&& mAccount.hasSpamFolder());
|
|
|
|
}
|
2012-09-26 12:03:14 -04:00
|
|
|
|
2013-01-31 20:50:00 -05:00
|
|
|
public void updateTitle() {
|
|
|
|
if (mMessage != null) {
|
|
|
|
displayMessageSubject(mMessage.getSubject());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-26 12:03:14 -04:00
|
|
|
public interface MessageViewFragmentListener {
|
2014-12-12 08:04:59 -05:00
|
|
|
public void onForward(LocalMessage mMessage, PgpData mPgpData);
|
2013-01-28 19:19:53 -05:00
|
|
|
public void disableDeleteAction();
|
2014-12-12 08:04:59 -05:00
|
|
|
public void onReplyAll(LocalMessage mMessage, PgpData mPgpData);
|
|
|
|
public void onReply(LocalMessage mMessage, PgpData mPgpData);
|
2012-09-26 12:03:14 -04:00
|
|
|
public void displayMessageSubject(String title);
|
|
|
|
public void setProgress(boolean b);
|
|
|
|
public void showNextMessageOrReturn();
|
|
|
|
public void messageHeaderViewAvailable(MessageHeader messageHeaderView);
|
2013-01-28 19:19:53 -05:00
|
|
|
public void updateMenu();
|
2012-09-07 23:33:53 -04:00
|
|
|
}
|
2013-02-01 20:35:48 -05:00
|
|
|
|
|
|
|
public boolean isInitialized() {
|
|
|
|
return mInitialized ;
|
|
|
|
}
|
2013-02-05 12:35:43 -05:00
|
|
|
|
|
|
|
public LayoutInflater getFragmentLayoutInflater() {
|
|
|
|
return mLayoutInflater;
|
|
|
|
}
|
2015-01-12 22:17:25 -05:00
|
|
|
|
|
|
|
class LocalMessageLoaderCallback implements LoaderCallbacks<LocalMessage> {
|
|
|
|
@Override
|
|
|
|
public Loader<LocalMessage> onCreateLoader(int id, Bundle args) {
|
2015-01-14 03:56:57 -05:00
|
|
|
setProgress(true);
|
2015-01-12 22:17:25 -05:00
|
|
|
return new LocalMessageLoader(mContext, mController, mAccount, mMessageReference);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLoadFinished(Loader<LocalMessage> loader, LocalMessage message) {
|
2015-01-14 03:56:57 -05:00
|
|
|
setProgress(false);
|
2015-01-12 22:17:25 -05:00
|
|
|
mMessage = message;
|
|
|
|
if (message == null) {
|
|
|
|
onLoadMessageFromDatabaseFailed();
|
|
|
|
} else {
|
|
|
|
onLoadMessageFromDatabaseFinished(message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLoaderReset(Loader<LocalMessage> loader) {
|
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
}
|
2015-01-14 03:56:57 -05:00
|
|
|
|
|
|
|
class DecodeMessageLoaderCallback implements LoaderCallbacks<MessageViewInfo> {
|
|
|
|
@Override
|
|
|
|
public Loader<MessageViewInfo> onCreateLoader(int id, Bundle args) {
|
|
|
|
setProgress(true);
|
|
|
|
return new DecodeMessageLoader(mContext, mMessage);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLoadFinished(Loader<MessageViewInfo> loader, MessageViewInfo messageContainer) {
|
|
|
|
setProgress(false);
|
|
|
|
onDecodeMessageFinished(messageContainer);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLoaderReset(Loader<MessageViewInfo> loader) {
|
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
}
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|