mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-27 03:32:16 -05:00
show attachments inline
This commit is contained in:
parent
445c978f31
commit
581d32acd6
@ -2,7 +2,6 @@ package com.fsck.k9.mailstore;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.fsck.k9.mail.Message;
|
||||
@ -16,8 +15,6 @@ public class MessageViewInfo {
|
||||
|
||||
@Deprecated
|
||||
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));
|
||||
this.message = message;
|
||||
}
|
||||
|
@ -97,7 +97,6 @@ public class MessageContainerView extends LinearLayout implements OnClickListene
|
||||
private View mShowAttachmentsAction;
|
||||
private boolean mShowPictures;
|
||||
private boolean mHasAttachments;
|
||||
private Button mDownloadRemainder;
|
||||
private LayoutInflater mInflater;
|
||||
private Contacts mContacts;
|
||||
private AttachmentViewCallback attachmentCallback;
|
||||
@ -108,7 +107,9 @@ public class MessageContainerView extends LinearLayout implements OnClickListene
|
||||
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();
|
||||
mMessageContentView = (MessageWebView) findViewById(R.id.message_content);
|
||||
mMessageContentView.configure();
|
||||
@ -131,9 +132,6 @@ public class MessageContainerView extends LinearLayout implements OnClickListene
|
||||
mContacts = Contacts.getInstance(activity);
|
||||
|
||||
mInflater = ((MessageViewFragment) fragment).getFragmentLayoutInflater();
|
||||
// mDownloadRemainder = (Button) findViewById(R.id.download_remainder);
|
||||
// mDownloadRemainder.setVisibility(View.GONE);
|
||||
mAttachmentsContainer.setVisibility(View.GONE);
|
||||
mMessageContentView.setVisibility(View.VISIBLE);
|
||||
|
||||
// the HTC version of WebView tries to force the background of the
|
||||
@ -373,14 +371,6 @@ public class MessageContainerView extends LinearLayout implements OnClickListene
|
||||
onShowHiddenAttachments();
|
||||
break;
|
||||
}
|
||||
case R.id.show_message: {
|
||||
onShowMessage();
|
||||
break;
|
||||
}
|
||||
case R.id.show_attachments: {
|
||||
onShowAttachments();
|
||||
break;
|
||||
}
|
||||
case R.id.show_pictures: {
|
||||
// Allow network access first...
|
||||
setLoadPictures(true);
|
||||
@ -396,20 +386,6 @@ public class MessageContainerView extends LinearLayout implements OnClickListene
|
||||
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) {
|
||||
super(context, attrs);
|
||||
}
|
||||
@ -439,33 +415,6 @@ public class MessageContainerView extends LinearLayout implements OnClickListene
|
||||
public void showShowPicturesAction(boolean show) {
|
||||
// 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() {
|
||||
for (AttachmentView attachmentView : attachments.values()) {
|
||||
@ -500,19 +449,11 @@ public class MessageContainerView extends LinearLayout implements OnClickListene
|
||||
lookForImages = false;
|
||||
}
|
||||
|
||||
if (mSavedState.attachmentViewVisible) {
|
||||
onShowAttachments();
|
||||
} else {
|
||||
onShowMessage();
|
||||
}
|
||||
|
||||
if (mSavedState.hiddenAttachmentsVisible) {
|
||||
onShowHiddenAttachments();
|
||||
}
|
||||
|
||||
mSavedState = null;
|
||||
} else {
|
||||
onShowMessage();
|
||||
}
|
||||
|
||||
/*
|
||||
@ -551,17 +492,6 @@ public class MessageContainerView extends LinearLayout implements OnClickListene
|
||||
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 {
|
||||
for (AttachmentViewInfo attachment : messageContainer.attachments) {
|
||||
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() {
|
||||
// mDownloadRemainder.setVisibility(View.GONE);
|
||||
setLoadPictures(false);
|
||||
showShowAttachmentsAction(false);
|
||||
showShowMessageAction(false);
|
||||
showShowPicturesAction(false);
|
||||
mAttachments.removeAllViews();
|
||||
mHiddenAttachments.removeAllViews();
|
||||
@ -617,10 +544,6 @@ public class MessageContainerView extends LinearLayout implements OnClickListene
|
||||
loadBodyFromText("");
|
||||
}
|
||||
|
||||
public void setAttachmentCallback(AttachmentViewCallback attachmentCallback) {
|
||||
this.attachmentCallback = attachmentCallback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Parcelable onSaveInstanceState() {
|
||||
Parcelable superState = super.onSaveInstanceState();
|
||||
|
@ -8,12 +8,14 @@ import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.fsck.k9.Account;
|
||||
import com.fsck.k9.K9;
|
||||
import com.fsck.k9.R;
|
||||
import com.fsck.k9.crypto.PgpData;
|
||||
import com.fsck.k9.mail.Flag;
|
||||
import com.fsck.k9.mail.Message;
|
||||
import com.fsck.k9.mail.MessagingException;
|
||||
import com.fsck.k9.mailstore.MessageViewInfo;
|
||||
@ -27,14 +29,16 @@ public class MessageTopView extends LinearLayout {
|
||||
private LayoutInflater mInflater;
|
||||
private LinearLayout containerViews;
|
||||
private Fragment fragment;
|
||||
private Button mDownloadRemainder;
|
||||
private AttachmentViewCallback attachmentCallback;
|
||||
|
||||
public MessageTopView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public void initialize (Fragment fragment) {
|
||||
public void initialize (Fragment fragment, AttachmentViewCallback attachmentCallback) {
|
||||
this.fragment = fragment;
|
||||
Activity activity = fragment.getActivity();
|
||||
this.attachmentCallback = attachmentCallback;
|
||||
|
||||
mHeaderContainer = (MessageHeader) findViewById(R.id.header_container);
|
||||
// mHeaderContainer.setOnLayoutChangedListener(this);
|
||||
@ -44,12 +48,15 @@ public class MessageTopView extends LinearLayout {
|
||||
getContext().getTheme().resolveAttribute(R.attr.messageViewHeaderBackgroundColor, outValue, true);
|
||||
mHeaderContainer.setBackgroundColor(outValue.data);
|
||||
|
||||
mDownloadRemainder = (Button) findViewById(R.id.download_remainder);
|
||||
mDownloadRemainder.setVisibility(View.GONE);
|
||||
|
||||
containerViews = (LinearLayout) findViewById(R.id.message_containers);
|
||||
|
||||
}
|
||||
|
||||
public void resetView() {
|
||||
// mDownloadRemainder.setVisibility(View.GONE);
|
||||
mDownloadRemainder.setVisibility(View.GONE);
|
||||
containerViews.removeAllViews();
|
||||
}
|
||||
|
||||
@ -59,7 +66,7 @@ public class MessageTopView extends LinearLayout {
|
||||
|
||||
for (MessageViewContainer container : messageViewInfo.containers) {
|
||||
MessageContainerView view = (MessageContainerView) mInflater.inflate(R.layout.message_container, null);
|
||||
view.initialize(fragment);
|
||||
view.initialize(fragment, attachmentCallback);
|
||||
view.setMessage(container);
|
||||
containerViews.addView(view);
|
||||
}
|
||||
@ -102,4 +109,25 @@ public class MessageTopView extends LinearLayout {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -147,9 +147,7 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF
|
||||
|
||||
mMessageView = (MessageTopView) view.findViewById(R.id.message_view);
|
||||
|
||||
// mMessageView.setAttachmentCallback(this);
|
||||
|
||||
mMessageView.initialize(this);
|
||||
mMessageView.initialize(this, this);
|
||||
mMessageView.setOnToggleFlagClickListener(new OnClickListener() {
|
||||
@Override
|
||||
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
|
||||
public void onClick(View v) {
|
||||
onDownloadRemainder();
|
||||
}
|
||||
});*/
|
||||
});
|
||||
|
||||
mFragmentListener.messageHeaderViewAvailable(mMessageView.getMessageHeaderView());
|
||||
|
||||
@ -248,7 +246,7 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF
|
||||
}
|
||||
|
||||
private void onDownloadMessageFailed(Throwable t) {
|
||||
// mMessageView.enableDownloadButton();
|
||||
mMessageView.enableDownloadButton();
|
||||
String errorMessage;
|
||||
if (t instanceof IllegalArgumentException) {
|
||||
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) {
|
||||
try {
|
||||
mMessageView.setMessage(mAccount, messageContainer);
|
||||
// mMessageView.setShowDownloadButton(mMessage);
|
||||
mMessageView.setShowDownloadButton(mMessage);
|
||||
} catch (MessagingException 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)) {
|
||||
return;
|
||||
}
|
||||
// mMessageView.disableDownloadButton();
|
||||
mMessageView.disableDownloadButton();
|
||||
|
||||
mController.loadMessageForViewRemote(mAccount, mMessageReference.folderName, mMessageReference.uid,
|
||||
downloadMessageListener);
|
||||
|
Loading…
Reference in New Issue
Block a user