1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-30 13:12:25 -05:00

show attachments inline

This commit is contained in:
Vincent Breitmoser 2015-01-27 17:33:50 +01:00
parent 445c978f31
commit 581d32acd6
4 changed files with 41 additions and 95 deletions

View File

@ -2,7 +2,6 @@ package com.fsck.k9.mailstore;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import com.fsck.k9.mail.Message; import com.fsck.k9.mail.Message;
@ -16,8 +15,6 @@ public class MessageViewInfo {
@Deprecated @Deprecated
public MessageViewInfo(String text, List<AttachmentViewInfo> attachments, Message message) { public MessageViewInfo(String text, List<AttachmentViewInfo> attachments, Message message) {
containers.add(new MessageViewContainer(text, attachments));
// FIXME just display it twice, for testing only
containers.add(new MessageViewContainer(text, attachments)); containers.add(new MessageViewContainer(text, attachments));
this.message = message; this.message = message;
} }

View File

@ -97,7 +97,6 @@ public class MessageContainerView extends LinearLayout implements OnClickListene
private View mShowAttachmentsAction; private View mShowAttachmentsAction;
private boolean mShowPictures; private boolean mShowPictures;
private boolean mHasAttachments; private boolean mHasAttachments;
private Button mDownloadRemainder;
private LayoutInflater mInflater; private LayoutInflater mInflater;
private Contacts mContacts; private Contacts mContacts;
private AttachmentViewCallback attachmentCallback; private AttachmentViewCallback attachmentCallback;
@ -108,7 +107,9 @@ public class MessageContainerView extends LinearLayout implements OnClickListene
private Map<AttachmentViewInfo, AttachmentView> attachments = new HashMap<AttachmentViewInfo, AttachmentView>(); private Map<AttachmentViewInfo, AttachmentView> attachments = new HashMap<AttachmentViewInfo, AttachmentView>();
public void initialize(Fragment fragment) { public void initialize(Fragment fragment, AttachmentViewCallback attachmentCallback) {
this.attachmentCallback = attachmentCallback;
Activity activity = fragment.getActivity(); Activity activity = fragment.getActivity();
mMessageContentView = (MessageWebView) findViewById(R.id.message_content); mMessageContentView = (MessageWebView) findViewById(R.id.message_content);
mMessageContentView.configure(); mMessageContentView.configure();
@ -131,9 +132,6 @@ public class MessageContainerView extends LinearLayout implements OnClickListene
mContacts = Contacts.getInstance(activity); mContacts = Contacts.getInstance(activity);
mInflater = ((MessageViewFragment) fragment).getFragmentLayoutInflater(); mInflater = ((MessageViewFragment) fragment).getFragmentLayoutInflater();
// mDownloadRemainder = (Button) findViewById(R.id.download_remainder);
// mDownloadRemainder.setVisibility(View.GONE);
mAttachmentsContainer.setVisibility(View.GONE);
mMessageContentView.setVisibility(View.VISIBLE); mMessageContentView.setVisibility(View.VISIBLE);
// the HTC version of WebView tries to force the background of the // the HTC version of WebView tries to force the background of the
@ -373,14 +371,6 @@ public class MessageContainerView extends LinearLayout implements OnClickListene
onShowHiddenAttachments(); onShowHiddenAttachments();
break; break;
} }
case R.id.show_message: {
onShowMessage();
break;
}
case R.id.show_attachments: {
onShowAttachments();
break;
}
case R.id.show_pictures: { case R.id.show_pictures: {
// Allow network access first... // Allow network access first...
setLoadPictures(true); setLoadPictures(true);
@ -396,20 +386,6 @@ public class MessageContainerView extends LinearLayout implements OnClickListene
mHiddenAttachments.setVisibility(View.VISIBLE); mHiddenAttachments.setVisibility(View.VISIBLE);
} }
public void onShowMessage() {
showShowMessageAction(false);
showAttachments(false);
showShowAttachmentsAction(mHasAttachments);
showMessageWebView(true);
}
public void onShowAttachments() {
showMessageWebView(false);
showShowAttachmentsAction(false);
showShowMessageAction(true);
showAttachments(true);
}
public MessageContainerView(Context context, AttributeSet attrs) { public MessageContainerView(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
} }
@ -439,33 +415,6 @@ public class MessageContainerView extends LinearLayout implements OnClickListene
public void showShowPicturesAction(boolean show) { public void showShowPicturesAction(boolean show) {
// mShowPicturesAction.setVisibility(show ? View.VISIBLE : View.GONE); // mShowPicturesAction.setVisibility(show ? View.VISIBLE : View.GONE);
} }
public void showShowMessageAction(boolean show) {
// mShowMessageAction.setVisibility(show ? View.VISIBLE : View.GONE);
}
public void showShowAttachmentsAction(boolean show) {
// mShowAttachmentsAction.setVisibility(show ? View.VISIBLE : View.GONE);
}
public void setOnDownloadButtonClickListener(OnClickListener listener) {
mDownloadRemainder.setOnClickListener(listener);
}
public void enableDownloadButton() {
mDownloadRemainder.setEnabled(true);
}
public void disableDownloadButton() {
mDownloadRemainder.setEnabled(false);
}
public void setShowDownloadButton(Message message) {
if (message.isSet(Flag.X_DOWNLOADED_FULL)) {
mDownloadRemainder.setVisibility(View.GONE);
} else {
mDownloadRemainder.setEnabled(true);
mDownloadRemainder.setVisibility(View.VISIBLE);
}
}
public void enableAttachmentButtons() { public void enableAttachmentButtons() {
for (AttachmentView attachmentView : attachments.values()) { for (AttachmentView attachmentView : attachments.values()) {
@ -500,19 +449,11 @@ public class MessageContainerView extends LinearLayout implements OnClickListene
lookForImages = false; lookForImages = false;
} }
if (mSavedState.attachmentViewVisible) {
onShowAttachments();
} else {
onShowMessage();
}
if (mSavedState.hiddenAttachmentsVisible) { if (mSavedState.hiddenAttachmentsVisible) {
onShowHiddenAttachments(); onShowHiddenAttachments();
} }
mSavedState = null; mSavedState = null;
} else {
onShowMessage();
} }
/* /*
@ -551,17 +492,6 @@ public class MessageContainerView extends LinearLayout implements OnClickListene
mMessageContentView.setText(emailText); mMessageContentView.setText(emailText);
} }
public void showAttachments(boolean show) {
mAttachmentsContainer.setVisibility(show ? View.VISIBLE : View.GONE);
boolean showHidden = (show && mHiddenAttachments.getVisibility() == View.GONE &&
mHiddenAttachments.getChildCount() > 0);
mShowHiddenAttachments.setVisibility(showHidden ? View.VISIBLE : View.GONE);
}
public void showMessageWebView(boolean show) {
mMessageContentView.setVisibility(show ? View.VISIBLE : View.GONE);
}
public void renderAttachments(MessageViewContainer messageContainer) throws MessagingException { public void renderAttachments(MessageViewContainer messageContainer) throws MessagingException {
for (AttachmentViewInfo attachment : messageContainer.attachments) { for (AttachmentViewInfo attachment : messageContainer.attachments) {
AttachmentView view = (AttachmentView) mInflater.inflate(R.layout.message_view_attachment, null); AttachmentView view = (AttachmentView) mInflater.inflate(R.layout.message_view_attachment, null);
@ -599,10 +529,7 @@ public class MessageContainerView extends LinearLayout implements OnClickListene
} }
public void resetView() { public void resetView() {
// mDownloadRemainder.setVisibility(View.GONE);
setLoadPictures(false); setLoadPictures(false);
showShowAttachmentsAction(false);
showShowMessageAction(false);
showShowPicturesAction(false); showShowPicturesAction(false);
mAttachments.removeAllViews(); mAttachments.removeAllViews();
mHiddenAttachments.removeAllViews(); mHiddenAttachments.removeAllViews();
@ -617,10 +544,6 @@ public class MessageContainerView extends LinearLayout implements OnClickListene
loadBodyFromText(""); loadBodyFromText("");
} }
public void setAttachmentCallback(AttachmentViewCallback attachmentCallback) {
this.attachmentCallback = attachmentCallback;
}
@Override @Override
public Parcelable onSaveInstanceState() { public Parcelable onSaveInstanceState() {
Parcelable superState = super.onSaveInstanceState(); Parcelable superState = super.onSaveInstanceState();

View File

@ -8,12 +8,14 @@ import android.util.Log;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import com.fsck.k9.Account; import com.fsck.k9.Account;
import com.fsck.k9.K9; import com.fsck.k9.K9;
import com.fsck.k9.R; import com.fsck.k9.R;
import com.fsck.k9.crypto.PgpData; import com.fsck.k9.crypto.PgpData;
import com.fsck.k9.mail.Flag;
import com.fsck.k9.mail.Message; import com.fsck.k9.mail.Message;
import com.fsck.k9.mail.MessagingException; import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mailstore.MessageViewInfo; import com.fsck.k9.mailstore.MessageViewInfo;
@ -27,14 +29,16 @@ public class MessageTopView extends LinearLayout {
private LayoutInflater mInflater; private LayoutInflater mInflater;
private LinearLayout containerViews; private LinearLayout containerViews;
private Fragment fragment; private Fragment fragment;
private Button mDownloadRemainder;
private AttachmentViewCallback attachmentCallback;
public MessageTopView(Context context, AttributeSet attrs) { public MessageTopView(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
} }
public void initialize (Fragment fragment) { public void initialize (Fragment fragment, AttachmentViewCallback attachmentCallback) {
this.fragment = fragment; this.fragment = fragment;
Activity activity = fragment.getActivity(); this.attachmentCallback = attachmentCallback;
mHeaderContainer = (MessageHeader) findViewById(R.id.header_container); mHeaderContainer = (MessageHeader) findViewById(R.id.header_container);
// mHeaderContainer.setOnLayoutChangedListener(this); // mHeaderContainer.setOnLayoutChangedListener(this);
@ -44,12 +48,15 @@ public class MessageTopView extends LinearLayout {
getContext().getTheme().resolveAttribute(R.attr.messageViewHeaderBackgroundColor, outValue, true); getContext().getTheme().resolveAttribute(R.attr.messageViewHeaderBackgroundColor, outValue, true);
mHeaderContainer.setBackgroundColor(outValue.data); mHeaderContainer.setBackgroundColor(outValue.data);
mDownloadRemainder = (Button) findViewById(R.id.download_remainder);
mDownloadRemainder.setVisibility(View.GONE);
containerViews = (LinearLayout) findViewById(R.id.message_containers); containerViews = (LinearLayout) findViewById(R.id.message_containers);
} }
public void resetView() { public void resetView() {
// mDownloadRemainder.setVisibility(View.GONE); mDownloadRemainder.setVisibility(View.GONE);
containerViews.removeAllViews(); containerViews.removeAllViews();
} }
@ -59,7 +66,7 @@ public class MessageTopView extends LinearLayout {
for (MessageViewContainer container : messageViewInfo.containers) { for (MessageViewContainer container : messageViewInfo.containers) {
MessageContainerView view = (MessageContainerView) mInflater.inflate(R.layout.message_container, null); MessageContainerView view = (MessageContainerView) mInflater.inflate(R.layout.message_container, null);
view.initialize(fragment); view.initialize(fragment, attachmentCallback);
view.setMessage(container); view.setMessage(container);
containerViews.addView(view); containerViews.addView(view);
} }
@ -102,4 +109,25 @@ public class MessageTopView extends LinearLayout {
mHeaderContainer.setVisibility(View.GONE); mHeaderContainer.setVisibility(View.GONE);
} }
public void setOnDownloadButtonClickListener(OnClickListener listener) {
mDownloadRemainder.setOnClickListener(listener);
}
public void enableDownloadButton() {
mDownloadRemainder.setEnabled(true);
}
public void disableDownloadButton() {
mDownloadRemainder.setEnabled(false);
}
public void setShowDownloadButton(Message message) {
if (message.isSet(Flag.X_DOWNLOADED_FULL)) {
mDownloadRemainder.setVisibility(View.GONE);
} else {
mDownloadRemainder.setEnabled(true);
mDownloadRemainder.setVisibility(View.VISIBLE);
}
}
} }

View File

@ -147,9 +147,7 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF
mMessageView = (MessageTopView) view.findViewById(R.id.message_view); mMessageView = (MessageTopView) view.findViewById(R.id.message_view);
// mMessageView.setAttachmentCallback(this); mMessageView.initialize(this, this);
mMessageView.initialize(this);
mMessageView.setOnToggleFlagClickListener(new OnClickListener() { mMessageView.setOnToggleFlagClickListener(new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -157,12 +155,12 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF
} }
}); });
/*mMessageView.setOnDownloadButtonClickListener(new OnClickListener() { mMessageView.setOnDownloadButtonClickListener(new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
onDownloadRemainder(); onDownloadRemainder();
} }
});*/ });
mFragmentListener.messageHeaderViewAvailable(mMessageView.getMessageHeaderView()); mFragmentListener.messageHeaderViewAvailable(mMessageView.getMessageHeaderView());
@ -248,7 +246,7 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF
} }
private void onDownloadMessageFailed(Throwable t) { private void onDownloadMessageFailed(Throwable t) {
// mMessageView.enableDownloadButton(); mMessageView.enableDownloadButton();
String errorMessage; String errorMessage;
if (t instanceof IllegalArgumentException) { if (t instanceof IllegalArgumentException) {
errorMessage = mContext.getString(R.string.status_invalid_id_error); errorMessage = mContext.getString(R.string.status_invalid_id_error);
@ -271,7 +269,7 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF
private void showMessage(MessageViewInfo messageContainer) { private void showMessage(MessageViewInfo messageContainer) {
try { try {
mMessageView.setMessage(mAccount, messageContainer); mMessageView.setMessage(mAccount, messageContainer);
// mMessageView.setShowDownloadButton(mMessage); mMessageView.setShowDownloadButton(mMessage);
} catch (MessagingException e) { } catch (MessagingException e) {
Log.e(K9.LOG_TAG, "Error while trying to display message", e); Log.e(K9.LOG_TAG, "Error while trying to display message", e);
} }
@ -488,7 +486,7 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF
if (mMessage.isSet(Flag.X_DOWNLOADED_FULL)) { if (mMessage.isSet(Flag.X_DOWNLOADED_FULL)) {
return; return;
} }
// mMessageView.disableDownloadButton(); mMessageView.disableDownloadButton();
mController.loadMessageForViewRemote(mAccount, mMessageReference.folderName, mMessageReference.uid, mController.loadMessageForViewRemote(mAccount, mMessageReference.folderName, mMessageReference.uid,
downloadMessageListener); downloadMessageListener);