1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-27 11:42:16 -05:00

extract header view for multiple MessageContainerViews (intermediate state)

This commit is contained in:
Vincent Breitmoser 2015-01-27 16:43:49 +01:00
parent 29ad0f0f99
commit 445c978f31
6 changed files with 200 additions and 146 deletions

View File

@ -16,20 +16,12 @@ 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;
}
@Deprecated
public String getText() {
return containers.get(0).text;
}
@Deprecated
public List<AttachmentViewInfo> getAttachments() {
return containers.get(0).attachments;
}
public static class MessageViewContainer {
final public String text;

View File

@ -20,7 +20,6 @@ import android.os.AsyncTask;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
@ -55,9 +54,9 @@ import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mail.internet.MimeUtility;
import com.fsck.k9.mailstore.AttachmentViewInfo;
import com.fsck.k9.mailstore.MessageViewInfo;
import com.fsck.k9.mailstore.MessageViewInfo.MessageViewContainer;
import com.fsck.k9.provider.AttachmentProvider.AttachmentProviderColumns;
import com.fsck.k9.view.MessageHeader;
import com.fsck.k9.view.MessageHeader.OnLayoutChangedListener;
import com.fsck.k9.view.MessageWebView;
import org.apache.commons.io.IOUtils;
@ -90,7 +89,6 @@ public class MessageContainerView extends LinearLayout implements OnClickListene
private MessageOpenPgpView mOpenPgpView;
private MessageWebView mMessageContentView;
private MessageHeader mHeaderContainer;
private LinearLayout mAttachments;
private Button mShowHiddenAttachments;
private LinearLayout mHiddenAttachments;
@ -117,18 +115,12 @@ public class MessageContainerView extends LinearLayout implements OnClickListene
activity.registerForContextMenu(mMessageContentView);
mMessageContentView.setOnCreateContextMenuListener(this);
mHeaderContainer = (MessageHeader) findViewById(R.id.header_container);
mHeaderContainer.setOnLayoutChangedListener(this);
mAttachmentsContainer = findViewById(R.id.attachments_container);
mAttachments = (LinearLayout) findViewById(R.id.attachments);
mHiddenAttachments = (LinearLayout) findViewById(R.id.hidden_attachments);
mHiddenAttachments.setVisibility(View.GONE);
mShowHiddenAttachments = (Button) findViewById(R.id.show_hidden_attachments);
mShowHiddenAttachments.setVisibility(View.GONE);
mOpenPgpView = (MessageOpenPgpView) findViewById(R.id.layout_decrypt_openpgp);
mOpenPgpView.setFragment(fragment);
mOpenPgpView.setupChildViews();
mShowPicturesAction = findViewById(R.id.show_pictures);
mShowMessageAction = findViewById(R.id.show_message);
@ -139,8 +131,8 @@ 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);
// mDownloadRemainder = (Button) findViewById(R.id.download_remainder);
// mDownloadRemainder.setVisibility(View.GONE);
mAttachmentsContainer.setVisibility(View.GONE);
mMessageContentView.setVisibility(View.VISIBLE);
@ -148,14 +140,13 @@ public class MessageContainerView extends LinearLayout implements OnClickListene
// titlebar, which is really unfair.
TypedValue outValue = new TypedValue();
getContext().getTheme().resolveAttribute(R.attr.messageViewHeaderBackgroundColor, outValue, true);
mHeaderContainer.setBackgroundColor(outValue.data);
// also set background of the whole view (including the attachments view)
setBackgroundColor(outValue.data);
mShowHiddenAttachments.setOnClickListener(this);
mShowMessageAction.setOnClickListener(this);
mShowAttachmentsAction.setOnClickListener(this);
mShowPicturesAction.setOnClickListener(this);
// mShowMessageAction.setOnClickListener(this);
// mShowAttachmentsAction.setOnClickListener(this);
// mShowPicturesAction.setOnClickListener(this);
mClipboardManager = ClipboardManager.getInstance(activity);
}
@ -446,37 +437,13 @@ public class MessageContainerView extends LinearLayout implements OnClickListene
}
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);
// mShowMessageAction.setVisibility(show ? View.VISIBLE : View.GONE);
}
public void showShowAttachmentsAction(boolean show) {
mShowAttachmentsAction.setVisibility(show ? View.VISIBLE : View.GONE);
}
/**
* Fetch the message header view. This is not the same as the message headers; this is the View shown at the top
* of messages.
* @return MessageHeader View.
*/
public MessageHeader getMessageHeaderView() {
return mHeaderContainer;
}
public void setHeaders(final Message message, Account account) {
try {
mHeaderContainer.populate(message, account);
mHeaderContainer.setVisibility(View.VISIBLE);
} catch (Exception me) {
Log.e(K9.LOG_TAG, "setHeaders - error", me);
}
}
public void setOnToggleFlagClickListener(OnClickListener listener) {
mHeaderContainer.setOnFlagListener(listener);
// mShowAttachmentsAction.setVisibility(show ? View.VISIBLE : View.GONE);
}
public void setOnDownloadButtonClickListener(OnClickListener listener) {
@ -512,36 +479,16 @@ public class MessageContainerView extends LinearLayout implements OnClickListene
}
}
public void showAllHeaders() {
mHeaderContainer.onShowAdditionalHeaders();
}
public boolean additionalHeadersVisible() {
return mHeaderContainer.additionalHeadersVisible();
}
public void setMessage(Account account, MessageViewInfo messageViewInfo, PgpData pgpData)
public void setMessage(MessageViewContainer messageViewContainer)
throws MessagingException {
resetView();
String text = null;
if (pgpData != null) {
text = pgpData.getDecryptedData();
if (text != null) {
text = HtmlConverter.textToHtml(text);
}
}
if (text == null) {
text = messageViewInfo.getText();
}
// Save the text so we can reset the WebView when the user clicks the "Show pictures" button
mText = text;
mText = messageViewContainer.text;
mHasAttachments = !messageViewInfo.getAttachments().isEmpty();
mHasAttachments = !messageViewContainer.attachments.isEmpty();
if (mHasAttachments) {
renderAttachments(messageViewInfo);
renderAttachments(messageViewContainer);
}
mHiddenAttachments.setVisibility(View.GONE);
@ -568,12 +515,13 @@ public class MessageContainerView extends LinearLayout implements OnClickListene
onShowMessage();
}
/*
if (text != null && lookForImages) {
// If the message contains external pictures and the "Show pictures"
// button wasn't already pressed, see if the user's preferences has us
// showing them anyway.
if (Utility.hasExternalImages(text) && !showPictures()) {
Address[] from = messageViewInfo.message.getFrom();
Address[] from = messageViewContainer.message.getFrom();
if ((account.getShowPictures() == Account.ShowPictures.ALWAYS) ||
((account.getShowPictures() == Account.ShowPictures.ONLY_FROM_CONTACTS) &&
// Make sure we have at least one from address
@ -585,11 +533,10 @@ public class MessageContainerView extends LinearLayout implements OnClickListene
}
}
}
*/
if (text != null) {
loadBodyFromText(text);
mOpenPgpView.updateLayout(account, pgpData.getDecryptedData(),
pgpData.getSignatureResult(), messageViewInfo.message);
if (mText != null) {
loadBodyFromText(mText);
} else {
showStatusMessage(getContext().getString(R.string.webview_empty_message));
}
@ -615,8 +562,8 @@ public class MessageContainerView extends LinearLayout implements OnClickListene
mMessageContentView.setVisibility(show ? View.VISIBLE : View.GONE);
}
public void renderAttachments(MessageViewInfo messageContainer) throws MessagingException {
for (AttachmentViewInfo attachment : messageContainer.getAttachments()) {
public void renderAttachments(MessageViewContainer messageContainer) throws MessagingException {
for (AttachmentViewInfo attachment : messageContainer.attachments) {
AttachmentView view = (AttachmentView) mInflater.inflate(R.layout.message_view_attachment, null);
view.setCallback(attachmentCallback);
view.setAttachment(attachment);
@ -652,7 +599,7 @@ public class MessageContainerView extends LinearLayout implements OnClickListene
}
public void resetView() {
mDownloadRemainder.setVisibility(View.GONE);
// mDownloadRemainder.setVisibility(View.GONE);
setLoadPictures(false);
showShowAttachmentsAction(false);
showShowMessageAction(false);
@ -670,10 +617,6 @@ public class MessageContainerView extends LinearLayout implements OnClickListene
loadBodyFromText("");
}
public void resetHeaderView() {
mHeaderContainer.setVisibility(View.GONE);
}
public void setAttachmentCallback(AttachmentViewCallback attachmentCallback) {
this.attachmentCallback = attachmentCallback;
}

View File

@ -0,0 +1,105 @@
package com.fsck.k9.ui.messageview;
import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
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.Message;
import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mailstore.MessageViewInfo;
import com.fsck.k9.mailstore.MessageViewInfo.MessageViewContainer;
import com.fsck.k9.view.MessageHeader;
public class MessageTopView extends LinearLayout {
private MessageHeader mHeaderContainer;
private LayoutInflater mInflater;
private LinearLayout containerViews;
private Fragment fragment;
public MessageTopView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public void initialize (Fragment fragment) {
this.fragment = fragment;
Activity activity = fragment.getActivity();
mHeaderContainer = (MessageHeader) findViewById(R.id.header_container);
// mHeaderContainer.setOnLayoutChangedListener(this);
mInflater = ((MessageViewFragment) fragment).getFragmentLayoutInflater();
TypedValue outValue = new TypedValue();
getContext().getTheme().resolveAttribute(R.attr.messageViewHeaderBackgroundColor, outValue, true);
mHeaderContainer.setBackgroundColor(outValue.data);
containerViews = (LinearLayout) findViewById(R.id.message_containers);
}
public void resetView() {
// mDownloadRemainder.setVisibility(View.GONE);
containerViews.removeAllViews();
}
public void setMessage(Account account, MessageViewInfo messageViewInfo)
throws MessagingException {
resetView();
for (MessageViewContainer container : messageViewInfo.containers) {
MessageContainerView view = (MessageContainerView) mInflater.inflate(R.layout.message_container, null);
view.initialize(fragment);
view.setMessage(container);
containerViews.addView(view);
}
}
/**
* Fetch the message header view. This is not the same as the message headers; this is the View shown at the top
* of messages.
* @return MessageHeader View.
*/
public MessageHeader getMessageHeaderView() {
return mHeaderContainer;
}
public void setHeaders(final Message message, Account account) {
try {
mHeaderContainer.populate(message, account);
mHeaderContainer.setVisibility(View.VISIBLE);
} catch (Exception me) {
Log.e(K9.LOG_TAG, "setHeaders - error", me);
}
}
public void setOnToggleFlagClickListener(OnClickListener listener) {
mHeaderContainer.setOnFlagListener(listener);
}
public void showAllHeaders() {
mHeaderContainer.onShowAdditionalHeaders();
}
public boolean additionalHeadersVisible() {
return mHeaderContainer.additionalHeadersVisible();
}
public void resetHeaderView() {
mHeaderContainer.setVisibility(View.GONE);
}
}

View File

@ -78,7 +78,7 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF
}
private SingleMessageView mMessageView;
private MessageTopView mMessageView;
private PgpData mPgpData;
private Account mAccount;
private MessageReference mMessageReference;
@ -145,9 +145,9 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF
View view = mLayoutInflater.inflate(R.layout.message, container, false);
mMessageView = (SingleMessageView) view.findViewById(R.id.message_view);
mMessageView = (MessageTopView) view.findViewById(R.id.message_view);
mMessageView.setAttachmentCallback(this);
// mMessageView.setAttachmentCallback(this);
mMessageView.initialize(this);
mMessageView.setOnToggleFlagClickListener(new OnClickListener() {
@ -156,12 +156,13 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF
onToggleFlagged();
}
});
mMessageView.setOnDownloadButtonClickListener(new OnClickListener() {
/*mMessageView.setOnDownloadButtonClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
onDownloadRemainder();
}
});
});*/
mFragmentListener.messageHeaderViewAvailable(mMessageView.getMessageHeaderView());
@ -229,7 +230,7 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF
}
private void onLoadMessageFromDatabaseFailed() {
mMessageView.showStatusMessage(mContext.getString(R.string.status_invalid_id_error));
// mMessageView.showStatusMessage(mContext.getString(R.string.status_invalid_id_error));
}
private void startDownloadingMessageBody(LocalMessage message) {
@ -247,7 +248,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);
@ -269,8 +270,8 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF
private void showMessage(MessageViewInfo messageContainer) {
try {
mMessageView.setMessage(mAccount, messageContainer, mPgpData);
mMessageView.setShowDownloadButton(mMessage);
mMessageView.setMessage(mAccount, messageContainer);
// mMessageView.setShowDownloadButton(mMessage);
} catch (MessagingException e) {
Log.e(K9.LOG_TAG, "Error while trying to display message", e);
}
@ -406,7 +407,8 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF
}
public void onSelectText() {
mMessageView.beginSelectingText();
// FIXME
// mMessageView.beginSelectingText();
}
private void startRefileActivity(int activity) {
@ -418,7 +420,6 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF
startActivityForResult(intent, activity);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != Activity.RESULT_OK) {
@ -487,7 +488,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);
@ -533,7 +534,7 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF
PgpData data = new PgpData();
data.setDecryptedData(decryptedData);
data.setSignatureResult(signatureResult);
mMessageView.setMessage(mAccount, messageViewInfo, data);
mMessageView.setMessage(mAccount, messageViewInfo);
} catch (MessagingException e) {
Log.e(K9.LOG_TAG, "displayMessageBody failed", e);
}
@ -600,7 +601,7 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF
}
public void zoom(KeyEvent event) {
mMessageView.zoom(event);
// mMessageView.zoom(event);
}
@Override
@ -668,11 +669,11 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF
}
public void disableAttachmentButtons(AttachmentViewInfo attachment) {
mMessageView.disableAttachmentButtons(attachment);
// mMessageView.disableAttachmentButtons(attachment);
}
public void enableAttachmentButtons(AttachmentViewInfo attachment) {
mMessageView.enableAttachmentButtons(attachment);
// mMessageView.enableAttachmentButtons(attachment);
}
public void runOnMainThread(Runnable runnable) {
@ -680,7 +681,7 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF
}
public void showAttachmentLoadingDialog() {
mMessageView.disableAttachmentButtons();
// mMessageView.disableAttachmentButtons();
showDialog(R.id.dialog_attachment_progress);
}
@ -689,13 +690,13 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF
@Override
public void run() {
removeDialog(R.id.dialog_attachment_progress);
mMessageView.enableAttachmentButtons();
// mMessageView.enableAttachmentButtons();
}
});
}
public void refreshAttachmentThumbnail(AttachmentViewInfo attachment) {
mMessageView.refreshAttachmentThumbnail(attachment);
// mMessageView.refreshAttachmentThumbnail(attachment);
}
public interface MessageViewFragmentListener {

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<com.fsck.k9.ui.messageview.SingleMessageView
<com.fsck.k9.ui.messageview.MessageTopView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/message_view"
android:orientation="vertical"
@ -20,41 +20,11 @@
<!-- Header area -->
<include layout="@layout/message_view_header"/>
<!-- Content area -->
<com.fsck.k9.view.MessageWebView
android:id="@+id/message_content"
android:layout_height="wrap_content"
android:layout_width="fill_parent"/>
<!-- Attachments area -->
<LinearLayout
android:id="@+id/attachments_container"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/attachments"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="4dip" />
<Button
android:id="@+id/show_hidden_attachments"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/message_view_show_more_attachments_action"/>
<LinearLayout
android:id="@+id/hidden_attachments"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="4dip"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:id="@+id/message_containers"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
@ -66,4 +36,4 @@
android:visibility="gone"
android:layout_width="fill_parent"/>
</com.fsck.k9.ui.messageview.SingleMessageView>
</com.fsck.k9.ui.messageview.MessageTopView>

View File

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<com.fsck.k9.ui.messageview.MessageContainerView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Content area -->
<com.fsck.k9.view.MessageWebView
android:id="@+id/message_content"
android:layout_height="wrap_content"
android:layout_width="fill_parent"/>
<!-- Attachments area -->
<LinearLayout
android:id="@+id/attachments_container"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/attachments"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="4dip" />
<Button
android:id="@+id/show_hidden_attachments"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/message_view_show_more_attachments_action"/>
<LinearLayout
android:id="@+id/hidden_attachments"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="4dip"/>
</LinearLayout>
</com.fsck.k9.ui.messageview.MessageContainerView>