mirror of
https://github.com/moparisthebest/k-9
synced 2024-12-17 21:32:26 -05:00
lift "displayMessage" out of a callback
This commit is contained in:
parent
39ef6584a8
commit
b2c44579d2
@ -1685,86 +1685,8 @@ public class MessageView extends K9Activity implements OnClickListener
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void renderAttachments(Part part, int depth) throws MessagingException
|
||||
public void displayMessage(Account account, String folder, String uid, Message message)
|
||||
{
|
||||
if (part.getBody() instanceof Multipart)
|
||||
{
|
||||
Multipart mp = (Multipart) part.getBody();
|
||||
for (int i = 0; i < mp.getCount(); i++)
|
||||
{
|
||||
renderAttachments(mp.getBodyPart(i), depth + 1);
|
||||
}
|
||||
}
|
||||
else if (part instanceof LocalAttachmentBodyPart)
|
||||
{
|
||||
String contentDisposition = MimeUtility.unfoldAndDecode(part.getDisposition());
|
||||
// Inline parts with a content-id are almost certainly components of an HTML message
|
||||
// not attachments. Don't show attachment download buttons for them.
|
||||
if (contentDisposition != null &&
|
||||
MimeUtility.getHeaderParameter(contentDisposition, null).matches("^(?i:inline)")
|
||||
&& part.getHeader("Content-ID") != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
renderPartAsAttachment(part);
|
||||
}
|
||||
}
|
||||
|
||||
private void renderPartAsAttachment(Part part) throws MessagingException
|
||||
{
|
||||
LayoutInflater inflater = getLayoutInflater();
|
||||
AttachmentView view = (AttachmentView)inflater.inflate(R.layout.message_view_attachment, null);
|
||||
if (view.populateFromPart(part, mMessage, mAccount, mController, mListener))
|
||||
{
|
||||
mHandler.addAttachment((View)view);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
class Listener extends MessagingListener
|
||||
{
|
||||
@Override
|
||||
public void loadMessageForViewHeadersAvailable(Account account, String folder, String uid,
|
||||
final Message message)
|
||||
{
|
||||
if (!mMessageReference.uid.equals(uid) || !mMessageReference.folderName.equals(folder)
|
||||
|| !mMessageReference.accountUuid.equals(account.getUuid()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
MessageView.this.mMessage = message;
|
||||
if (!message.isSet(Flag.X_DOWNLOADED_FULL)
|
||||
&& !message.isSet(Flag.X_DOWNLOADED_PARTIAL))
|
||||
{
|
||||
mHandler.post(new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
mMessageContentView.loadUrl("file:///android_asset/downloading.html");
|
||||
updateDecryptLayout();
|
||||
}
|
||||
});
|
||||
}
|
||||
try
|
||||
{
|
||||
mHandler.setHeaders(message);
|
||||
}
|
||||
catch (MessagingException me)
|
||||
{
|
||||
Log.e(K9.LOG_TAG, "loadMessageForViewHeadersAvailable", me);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadMessageForViewBodyAvailable(Account account, String folder, String uid,
|
||||
Message message)
|
||||
{
|
||||
if (!mMessageReference.uid.equals(uid) || !mMessageReference.folderName.equals(folder)
|
||||
|| !mMessageReference.accountUuid.equals(account.getUuid()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
if (MessageView.this.mMessage != null
|
||||
@ -1847,6 +1769,89 @@ public class MessageView extends K9Activity implements OnClickListener
|
||||
Log.v(K9.LOG_TAG, "loadMessageForViewBodyAvailable", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void renderAttachments(Part part, int depth) throws MessagingException
|
||||
{
|
||||
if (part.getBody() instanceof Multipart)
|
||||
{
|
||||
Multipart mp = (Multipart) part.getBody();
|
||||
for (int i = 0; i < mp.getCount(); i++)
|
||||
{
|
||||
renderAttachments(mp.getBodyPart(i), depth + 1);
|
||||
}
|
||||
}
|
||||
else if (part instanceof LocalAttachmentBodyPart)
|
||||
{
|
||||
String contentDisposition = MimeUtility.unfoldAndDecode(part.getDisposition());
|
||||
// Inline parts with a content-id are almost certainly components of an HTML message
|
||||
// not attachments. Don't show attachment download buttons for them.
|
||||
if (contentDisposition != null &&
|
||||
MimeUtility.getHeaderParameter(contentDisposition, null).matches("^(?i:inline)")
|
||||
&& part.getHeader("Content-ID") != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
renderPartAsAttachment(part);
|
||||
}
|
||||
}
|
||||
|
||||
private void renderPartAsAttachment(Part part) throws MessagingException
|
||||
{
|
||||
LayoutInflater inflater = getLayoutInflater();
|
||||
AttachmentView view = (AttachmentView)inflater.inflate(R.layout.message_view_attachment, null);
|
||||
if (view.populateFromPart(part, mMessage, mAccount, mController, mListener))
|
||||
{
|
||||
mHandler.addAttachment((View)view);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
class Listener extends MessagingListener
|
||||
{
|
||||
@Override
|
||||
public void loadMessageForViewHeadersAvailable(Account account, String folder, String uid,
|
||||
final Message message)
|
||||
{
|
||||
if (!mMessageReference.uid.equals(uid) || !mMessageReference.folderName.equals(folder)
|
||||
|| !mMessageReference.accountUuid.equals(account.getUuid()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
MessageView.this.mMessage = message;
|
||||
if (!message.isSet(Flag.X_DOWNLOADED_FULL)
|
||||
&& !message.isSet(Flag.X_DOWNLOADED_PARTIAL))
|
||||
{
|
||||
mHandler.post(new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
mMessageContentView.loadUrl("file:///android_asset/downloading.html");
|
||||
updateDecryptLayout();
|
||||
}
|
||||
});
|
||||
}
|
||||
try
|
||||
{
|
||||
mHandler.setHeaders(message);
|
||||
}
|
||||
catch (MessagingException me)
|
||||
{
|
||||
Log.e(K9.LOG_TAG, "loadMessageForViewHeadersAvailable", me);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadMessageForViewBodyAvailable(Account account, String folder, String uid,
|
||||
Message message)
|
||||
{
|
||||
if (!mMessageReference.uid.equals(uid) || !mMessageReference.folderName.equals(folder)
|
||||
|| !mMessageReference.accountUuid.equals(account.getUuid()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
displayMessage(account, folder, uid, message);
|
||||
}//loadMessageForViewBodyAvailable
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user