messageview: simplify handling of external pictures, ditch ShowPicturesController
This commit is contained in:
parent
b5b603001b
commit
fccb4a4b24
5 changed files with 27 additions and 53 deletions
|
@ -35,7 +35,6 @@ import com.fsck.k9.helper.ClipboardManager;
|
|||
import com.fsck.k9.helper.Contacts;
|
||||
import com.fsck.k9.helper.Utility;
|
||||
import com.fsck.k9.mail.Address;
|
||||
import com.fsck.k9.mail.MessagingException;
|
||||
import com.fsck.k9.mailstore.AttachmentResolver;
|
||||
import com.fsck.k9.mailstore.AttachmentViewInfo;
|
||||
import com.fsck.k9.mailstore.MessageViewInfo;
|
||||
|
@ -76,6 +75,7 @@ public class MessageContainerView extends LinearLayout implements OnClickListene
|
|||
private SavedState mSavedState;
|
||||
private ClipboardManager mClipboardManager;
|
||||
private Map<AttachmentViewInfo, AttachmentView> attachments = new HashMap<>();
|
||||
private boolean hasHiddenExternalImages;
|
||||
|
||||
private String currentHtmlText;
|
||||
private AttachmentResolver currentAttachmentResolver;
|
||||
|
@ -403,8 +403,7 @@ public class MessageContainerView extends LinearLayout implements OnClickListene
|
|||
|
||||
public void displayMessageViewContainer(MessageViewInfo messageViewInfo,
|
||||
final OnRenderingFinishedListener onRenderingFinishedListener, boolean automaticallyLoadPictures,
|
||||
ShowPicturesController showPicturesController,
|
||||
AttachmentViewCallback attachmentCallback) throws MessagingException {
|
||||
AttachmentViewCallback attachmentCallback) {
|
||||
|
||||
this.attachmentCallback = attachmentCallback;
|
||||
|
||||
|
@ -414,11 +413,9 @@ public class MessageContainerView extends LinearLayout implements OnClickListene
|
|||
|
||||
mHiddenAttachments.setVisibility(View.GONE);
|
||||
|
||||
boolean lookForImages = true;
|
||||
if (mSavedState != null) {
|
||||
if (mSavedState.showingPictures) {
|
||||
setLoadPictures(true);
|
||||
lookForImages = false;
|
||||
}
|
||||
|
||||
if (mSavedState.hiddenAttachmentsVisible) {
|
||||
|
@ -429,12 +426,12 @@ public class MessageContainerView extends LinearLayout implements OnClickListene
|
|||
}
|
||||
|
||||
String textToDisplay = messageViewInfo.text;
|
||||
if (textToDisplay != null && lookForImages) {
|
||||
if (Utility.hasExternalImages(textToDisplay) && !isShowingPictures()) {
|
||||
if (textToDisplay != null && !isShowingPictures()) {
|
||||
if (Utility.hasExternalImages(textToDisplay)) {
|
||||
if (automaticallyLoadPictures) {
|
||||
setLoadPictures(true);
|
||||
} else {
|
||||
showPicturesController.notifyMessageContainerContainsPictures(this);
|
||||
hasHiddenExternalImages = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -459,6 +456,10 @@ public class MessageContainerView extends LinearLayout implements OnClickListene
|
|||
}
|
||||
}
|
||||
|
||||
public boolean hasHiddenExternalImages() {
|
||||
return hasHiddenExternalImages;
|
||||
}
|
||||
|
||||
public String wrapStatusMessage(String status) {
|
||||
return "<div style=\"text-align:center; color: grey;\">" + status + "</div>";
|
||||
}
|
||||
|
@ -478,7 +479,7 @@ public class MessageContainerView extends LinearLayout implements OnClickListene
|
|||
mMessageContentView.displayHtmlContentWithInlineAttachments("", null, null);
|
||||
}
|
||||
|
||||
public void renderAttachments(MessageViewInfo messageViewInfo) throws MessagingException {
|
||||
public void renderAttachments(MessageViewInfo messageViewInfo) {
|
||||
if (messageViewInfo.attachments != null) {
|
||||
for (AttachmentViewInfo attachment : messageViewInfo.attachments) {
|
||||
ViewGroup parent = attachment.firstClassAttachment ? mAttachments : mHiddenAttachments;
|
||||
|
|
|
@ -1,16 +1,12 @@
|
|||
package com.fsck.k9.ui.messageview;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -22,13 +18,11 @@ import android.widget.TextView;
|
|||
|
||||
import com.fsck.k9.Account;
|
||||
import com.fsck.k9.Account.ShowPictures;
|
||||
import com.fsck.k9.K9;
|
||||
import com.fsck.k9.R;
|
||||
import com.fsck.k9.helper.Contacts;
|
||||
import com.fsck.k9.mail.Address;
|
||||
import com.fsck.k9.mail.Flag;
|
||||
import com.fsck.k9.mail.Message;
|
||||
import com.fsck.k9.mail.MessagingException;
|
||||
import com.fsck.k9.mailstore.MessageViewInfo;
|
||||
import com.fsck.k9.ui.messageview.MessageContainerView.OnRenderingFinishedListener;
|
||||
import com.fsck.k9.view.MessageCryptoDisplayStatus;
|
||||
|
@ -37,7 +31,7 @@ import com.fsck.k9.view.ToolableViewAnimator;
|
|||
import org.openintents.openpgp.OpenPgpError;
|
||||
|
||||
|
||||
public class MessageTopView extends LinearLayout implements ShowPicturesController {
|
||||
public class MessageTopView extends LinearLayout {
|
||||
|
||||
public static final int PROGRESS_MAX = 1000;
|
||||
public static final int PROGRESS_MAX_WITH_MARGIN = 950;
|
||||
|
@ -54,7 +48,6 @@ public class MessageTopView extends LinearLayout implements ShowPicturesControll
|
|||
private Button mDownloadRemainder;
|
||||
private AttachmentViewCallback attachmentCallback;
|
||||
private Button showPicturesButton;
|
||||
private List<MessageContainerView> messageContainerViewsWithPictures = new ArrayList<>();
|
||||
private boolean isShowingProgress;
|
||||
|
||||
private MessageCryptoPresenter messageCryptoPresenter;
|
||||
|
@ -97,10 +90,10 @@ public class MessageTopView extends LinearLayout implements ShowPicturesControll
|
|||
}
|
||||
|
||||
private void showPicturesInAllContainerViews() {
|
||||
for (MessageContainerView containerView : messageContainerViewsWithPictures) {
|
||||
containerView.showPictures();
|
||||
View messageContainerViewCandidate = containerView.getChildAt(0);
|
||||
if (messageContainerViewCandidate instanceof MessageContainerView) {
|
||||
((MessageContainerView) messageContainerViewCandidate).showPictures();
|
||||
}
|
||||
|
||||
hideShowPicturesButton();
|
||||
}
|
||||
|
||||
|
@ -109,7 +102,7 @@ public class MessageTopView extends LinearLayout implements ShowPicturesControll
|
|||
containerView.removeAllViews();
|
||||
}
|
||||
|
||||
public void setMessage(Account account, MessageViewInfo messageViewInfo) throws MessagingException {
|
||||
public void setMessage(Account account, MessageViewInfo messageViewInfo) {
|
||||
resetView();
|
||||
|
||||
setShowDownloadButton(messageViewInfo.message);
|
||||
|
@ -160,8 +153,7 @@ public class MessageTopView extends LinearLayout implements ShowPicturesControll
|
|||
displayViewOnLoadFinished(false);
|
||||
}
|
||||
|
||||
private void showMessageContentView(Account account, MessageViewInfo messageViewInfo)
|
||||
throws MessagingException {
|
||||
private void showMessageContentView(Account account, MessageViewInfo messageViewInfo) {
|
||||
ShowPictures showPicturesSetting = account.getShowPictures();
|
||||
boolean automaticallyLoadPictures =
|
||||
shouldAutomaticallyLoadPictures(showPicturesSetting, messageViewInfo.message);
|
||||
|
@ -175,7 +167,11 @@ public class MessageTopView extends LinearLayout implements ShowPicturesControll
|
|||
public void onLoadFinished() {
|
||||
displayViewOnLoadFinished(true);
|
||||
}
|
||||
}, automaticallyLoadPictures, this, attachmentCallback);
|
||||
}, automaticallyLoadPictures, attachmentCallback);
|
||||
|
||||
if (view.hasHiddenExternalImages()) {
|
||||
showShowPicturesButton();
|
||||
}
|
||||
}
|
||||
|
||||
private void showMessageCryptoErrorView(Account account, MessageViewInfo messageViewInfo) {
|
||||
|
@ -231,16 +227,11 @@ public class MessageTopView extends LinearLayout implements ShowPicturesControll
|
|||
}
|
||||
|
||||
public void setHeaders(final Message message, Account account) {
|
||||
try {
|
||||
mHeaderContainer.populate(message, account);
|
||||
if (account.isOpenPgpProviderConfigured()) {
|
||||
mHeaderContainer.setCryptoStatus(MessageCryptoDisplayStatus.LOADING);
|
||||
}
|
||||
mHeaderContainer.setVisibility(View.VISIBLE);
|
||||
|
||||
} catch (Exception me) {
|
||||
Log.e(K9.LOG_TAG, "setHeaders - error", me);
|
||||
mHeaderContainer.populate(message, account);
|
||||
if (account.isOpenPgpProviderConfigured()) {
|
||||
mHeaderContainer.setCryptoStatus(MessageCryptoDisplayStatus.LOADING);
|
||||
}
|
||||
mHeaderContainer.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
public void setOnToggleFlagClickListener(OnClickListener listener) {
|
||||
|
@ -297,13 +288,6 @@ public class MessageTopView extends LinearLayout implements ShowPicturesControll
|
|||
showPicturesButton.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyMessageContainerContainsPictures(MessageContainerView messageContainerView) {
|
||||
messageContainerViewsWithPictures.add(messageContainerView);
|
||||
|
||||
showShowPicturesButton();
|
||||
}
|
||||
|
||||
private boolean shouldAutomaticallyLoadPictures(ShowPictures showPicturesSetting, Message message) {
|
||||
return showPicturesSetting == ShowPictures.ALWAYS || shouldShowPicturesFromSender(showPicturesSetting, message);
|
||||
}
|
||||
|
|
|
@ -42,7 +42,6 @@ import com.fsck.k9.fragment.ProgressDialogFragment;
|
|||
import com.fsck.k9.helper.FileBrowserHelper;
|
||||
import com.fsck.k9.helper.FileBrowserHelper.FileBrowserFailOverCallback;
|
||||
import com.fsck.k9.mail.Flag;
|
||||
import com.fsck.k9.mail.MessagingException;
|
||||
import com.fsck.k9.mailstore.AttachmentViewInfo;
|
||||
import com.fsck.k9.mailstore.LocalMessage;
|
||||
import com.fsck.k9.mailstore.MessageViewInfo;
|
||||
|
@ -236,11 +235,7 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF
|
|||
|
||||
private void showMessage(MessageViewInfo messageViewInfo) {
|
||||
messageCryptoPresenter.setMessageViewInfo(messageViewInfo);
|
||||
try {
|
||||
mMessageView.setMessage(mAccount, messageViewInfo);
|
||||
} catch (MessagingException e) {
|
||||
Log.e(K9.LOG_TAG, "Error while trying to display message", e);
|
||||
}
|
||||
mMessageView.setMessage(mAccount, messageViewInfo);
|
||||
}
|
||||
|
||||
private void displayMessageHeader(LocalMessage message) {
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
package com.fsck.k9.ui.messageview;
|
||||
|
||||
|
||||
interface ShowPicturesController {
|
||||
void notifyMessageContainerContainsPictures(MessageContainerView messageContainerView);
|
||||
}
|
|
@ -256,7 +256,7 @@ public class MessageHeader extends LinearLayout implements OnClickListener, OnLo
|
|||
|
||||
}
|
||||
|
||||
public void populate(final Message message, final Account account) throws MessagingException {
|
||||
public void populate(final Message message, final Account account) {
|
||||
final Contacts contacts = K9.showContactName() ? mContacts : null;
|
||||
final CharSequence from = MessageHelper.toFriendly(message.getFrom(), contacts);
|
||||
final CharSequence to = MessageHelper.toFriendly(message.getRecipients(Message.RecipientType.TO), contacts);
|
||||
|
|
Loading…
Reference in a new issue