diff --git a/k9mail/src/main/java/com/fsck/k9/activity/MessageCompose.java b/k9mail/src/main/java/com/fsck/k9/activity/MessageCompose.java index 8fff3fbb0..e6f2f856d 100644 --- a/k9mail/src/main/java/com/fsck/k9/activity/MessageCompose.java +++ b/k9mail/src/main/java/com/fsck/k9/activity/MessageCompose.java @@ -3402,7 +3402,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, } @Override - public void loadMessageForViewFinished(Account account, String folder, String uid, Message message) { + public void loadMessageForViewFinished(Account account, String folder, String uid, LocalMessage message) { if ((mMessageReference == null) || !mMessageReference.uid.equals(uid)) { return; } diff --git a/k9mail/src/main/java/com/fsck/k9/controller/MessagingListener.java b/k9mail/src/main/java/com/fsck/k9/controller/MessagingListener.java index 72bd93d18..9190fe422 100644 --- a/k9mail/src/main/java/com/fsck/k9/controller/MessagingListener.java +++ b/k9mail/src/main/java/com/fsck/k9/controller/MessagingListener.java @@ -91,7 +91,7 @@ public class MessagingListener { Message message) {} public void loadMessageForViewFinished(Account account, String folder, String uid, - Message message) {} + LocalMessage message) {} public void loadMessageForViewFailed(Account account, String folder, String uid, Throwable t) {} diff --git a/k9mail/src/main/java/com/fsck/k9/ui/messageview/MessageViewFragment.java b/k9mail/src/main/java/com/fsck/k9/ui/messageview/MessageViewFragment.java index 40a1175c8..c91033128 100644 --- a/k9mail/src/main/java/com/fsck/k9/ui/messageview/MessageViewFragment.java +++ b/k9mail/src/main/java/com/fsck/k9/ui/messageview/MessageViewFragment.java @@ -8,12 +8,14 @@ import android.app.Activity; import android.app.DialogFragment; import android.app.Fragment; import android.app.FragmentManager; +import android.app.LoaderManager; import android.app.LoaderManager.LoaderCallbacks; import android.content.Context; import android.content.Intent; import android.content.Loader; import android.net.Uri; import android.os.Bundle; +import android.os.Handler; import android.text.TextUtils; import android.util.Log; import android.view.ContextThemeWrapper; @@ -31,6 +33,7 @@ import com.fsck.k9.R; import com.fsck.k9.activity.ChooseFolder; import com.fsck.k9.activity.MessageReference; import com.fsck.k9.controller.MessagingController; +import com.fsck.k9.controller.MessagingListener; import com.fsck.k9.crypto.PgpData; import com.fsck.k9.fragment.ConfirmationDialogFragment; import com.fsck.k9.fragment.ConfirmationDialogFragment.ConfirmationDialogFragmentListener; @@ -82,6 +85,8 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF private LocalMessage mMessage; private MessagingController mController; private LayoutInflater mLayoutInflater; + private Handler handler = new Handler(); + private DownloadMessageListener downloadMessageListener = new DownloadMessageListener(); /** * Used to temporarily store the destination folder for refile operations if a confirmation @@ -231,6 +236,27 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF throw new RuntimeException("Not implemented yet"); } + private void onMessageDownloadFinished(LocalMessage message) { + mMessage = message; + + LoaderManager loaderManager = getLoaderManager(); + loaderManager.destroyLoader(LOCAL_MESSAGE_LOADER_ID); + loaderManager.destroyLoader(DECODE_MESSAGE_LOADER_ID); + + onLoadMessageFromDatabaseFinished(mMessage); + } + + private void onDownloadMessageFailed(Throwable t) { + mMessageView.enableDownloadButton(); + String errorMessage; + if (t instanceof IllegalArgumentException) { + errorMessage = mContext.getString(R.string.status_invalid_id_error); + } else { + errorMessage = mContext.getString(R.string.status_network_error); + } + Toast.makeText(mContext, errorMessage, Toast.LENGTH_LONG).show(); + } + private void startExtractingTextAndAttachments(LocalMessage message) { getLoaderManager().initLoader(DECODE_MESSAGE_LOADER_ID, null, decodeMessageLoaderCallback); } @@ -462,8 +488,9 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF return; } mMessageView.disableDownloadButton(); - //FIXME -// mController.loadMessageForViewRemote(mAccount, mMessageReference.folderName, mMessageReference.uid, mListener); + + mController.loadMessageForViewRemote(mAccount, mMessageReference.folderName, mMessageReference.uid, + downloadMessageListener); } private void setProgress(boolean enable) { @@ -735,4 +762,26 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF private AttachmentController getAttachmentController(AttachmentViewInfo attachment) { return new AttachmentController(mMessageView, attachment); } + + private class DownloadMessageListener extends MessagingListener { + @Override + public void loadMessageForViewFinished(Account account, String folder, String uid, final LocalMessage message) { + handler.post(new Runnable() { + @Override + public void run() { + onMessageDownloadFinished(message); + } + }); + } + + @Override + public void loadMessageForViewFailed(Account account, String folder, String uid, final Throwable t) { + handler.post(new Runnable() { + @Override + public void run() { + onDownloadMessageFailed(t); + } + }); + } + } } diff --git a/k9mail/src/main/java/com/fsck/k9/ui/messageview/SingleMessageView.java b/k9mail/src/main/java/com/fsck/k9/ui/messageview/SingleMessageView.java index 1997c36fa..a7f2abebf 100644 --- a/k9mail/src/main/java/com/fsck/k9/ui/messageview/SingleMessageView.java +++ b/k9mail/src/main/java/com/fsck/k9/ui/messageview/SingleMessageView.java @@ -483,6 +483,10 @@ public class SingleMessageView extends LinearLayout implements OnClickListener, mDownloadRemainder.setOnClickListener(listener); } + public void enableDownloadButton() { + mDownloadRemainder.setEnabled(true); + } + public void disableDownloadButton() { mDownloadRemainder.setEnabled(false); }