mirror of
https://github.com/moparisthebest/k-9
synced 2025-02-22 05:31:55 -05:00
split apart attachment view creation a bit
This commit is contained in:
parent
3c9eb2c004
commit
b166cf03e8
@ -1839,9 +1839,17 @@ public class MessageView extends K9Activity implements OnClickListener
|
|||||||
|
|
||||||
private void renderAttachments(Part part, int depth) throws MessagingException
|
private void renderAttachments(Part part, int depth) throws MessagingException
|
||||||
{
|
{
|
||||||
String contentType = MimeUtility.unfoldAndDecode(part.getContentType());
|
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
|
||||||
|
{
|
||||||
String contentDisposition = MimeUtility.unfoldAndDecode(part.getDisposition());
|
String contentDisposition = MimeUtility.unfoldAndDecode(part.getDisposition());
|
||||||
String name = MimeUtility.getHeaderParameter(contentType, "name");
|
|
||||||
// Inline parts with a content-id are almost certainly components of an HTML message
|
// Inline parts with a content-id are almost certainly components of an HTML message
|
||||||
// not attachments. Don't show attachment download buttons for them.
|
// not attachments. Don't show attachment download buttons for them.
|
||||||
if (contentDisposition != null &&
|
if (contentDisposition != null &&
|
||||||
@ -1850,24 +1858,30 @@ public class MessageView extends K9Activity implements OnClickListener
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
renderPartAsAttachment(part);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void renderPartAsAttachment(Part part) throws MessagingException
|
||||||
|
{
|
||||||
|
String contentType = MimeUtility.unfoldAndDecode(part.getContentType());
|
||||||
|
String contentDisposition = MimeUtility.unfoldAndDecode(part.getDisposition());
|
||||||
|
String name = MimeUtility.getHeaderParameter(contentType, "name");
|
||||||
if (name == null)
|
if (name == null)
|
||||||
{
|
{
|
||||||
name = MimeUtility.getHeaderParameter(contentDisposition, "filename");
|
name = MimeUtility.getHeaderParameter(contentDisposition, "filename");
|
||||||
}
|
}
|
||||||
if (name != null)
|
if (name == null)
|
||||||
{
|
{
|
||||||
/*
|
return;
|
||||||
* We're guaranteed size because LocalStore.fetch puts it there.
|
}
|
||||||
*/
|
AttachmentViewHolder attachment = new AttachmentViewHolder();
|
||||||
int size = Integer.parseInt(MimeUtility.getHeaderParameter(contentDisposition, "size"));
|
attachment.size = Integer.parseInt(MimeUtility.getHeaderParameter(contentDisposition, "size"));
|
||||||
AttachmentViewHolder attachment = new AttachmentViewHolder();
|
attachment.contentType = part.getMimeType();
|
||||||
attachment.size = size;
|
if (MimeUtility.DEFAULT_ATTACHMENT_MIME_TYPE.equals(attachment.contentType))
|
||||||
String mimeType = part.getMimeType();
|
{
|
||||||
if (MimeUtility.DEFAULT_ATTACHMENT_MIME_TYPE.equals(mimeType))
|
attachment.contentType = MimeUtility.getMimeTypeByExtension(name);
|
||||||
{
|
|
||||||
mimeType = MimeUtility.getMimeTypeByExtension(name);
|
|
||||||
}
|
}
|
||||||
attachment.contentType = mimeType;
|
|
||||||
attachment.name = name;
|
attachment.name = name;
|
||||||
attachment.part = (LocalAttachmentBodyPart) part;
|
attachment.part = (LocalAttachmentBodyPart) part;
|
||||||
LayoutInflater inflater = getLayoutInflater();
|
LayoutInflater inflater = getLayoutInflater();
|
||||||
@ -1877,17 +1891,13 @@ public class MessageView extends K9Activity implements OnClickListener
|
|||||||
ImageView attachmentIcon = (ImageView) view.findViewById(R.id.attachment_icon);
|
ImageView attachmentIcon = (ImageView) view.findViewById(R.id.attachment_icon);
|
||||||
Button attachmentView = (Button) view.findViewById(R.id.view);
|
Button attachmentView = (Button) view.findViewById(R.id.view);
|
||||||
Button attachmentDownload = (Button) view.findViewById(R.id.download);
|
Button attachmentDownload = (Button) view.findViewById(R.id.download);
|
||||||
if ((!MimeUtility.mimeTypeMatches(attachment.contentType,
|
if ((!MimeUtility.mimeTypeMatches(attachment.contentType, K9.ACCEPTABLE_ATTACHMENT_VIEW_TYPES))
|
||||||
K9.ACCEPTABLE_ATTACHMENT_VIEW_TYPES))
|
|| (MimeUtility.mimeTypeMatches(attachment.contentType, K9.UNACCEPTABLE_ATTACHMENT_VIEW_TYPES)))
|
||||||
|| (MimeUtility.mimeTypeMatches(attachment.contentType,
|
|
||||||
K9.UNACCEPTABLE_ATTACHMENT_VIEW_TYPES)))
|
|
||||||
{
|
{
|
||||||
attachmentView.setVisibility(View.GONE);
|
attachmentView.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
if ((!MimeUtility.mimeTypeMatches(attachment.contentType,
|
if ((!MimeUtility.mimeTypeMatches(attachment.contentType, K9.ACCEPTABLE_ATTACHMENT_DOWNLOAD_TYPES))
|
||||||
K9.ACCEPTABLE_ATTACHMENT_DOWNLOAD_TYPES))
|
|| (MimeUtility.mimeTypeMatches(attachment.contentType, K9.UNACCEPTABLE_ATTACHMENT_DOWNLOAD_TYPES)))
|
||||||
|| (MimeUtility.mimeTypeMatches(attachment.contentType,
|
|
||||||
K9.UNACCEPTABLE_ATTACHMENT_DOWNLOAD_TYPES)))
|
|
||||||
{
|
{
|
||||||
attachmentDownload.setVisibility(View.GONE);
|
attachmentDownload.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
@ -1905,7 +1915,7 @@ public class MessageView extends K9Activity implements OnClickListener
|
|||||||
attachmentDownload.setOnClickListener(this);
|
attachmentDownload.setOnClickListener(this);
|
||||||
attachmentDownload.setTag(attachment);
|
attachmentDownload.setTag(attachment);
|
||||||
attachmentName.setText(name);
|
attachmentName.setText(name);
|
||||||
attachmentInfo.setText(SizeFormatter.formatSize(getApplication(), size));
|
attachmentInfo.setText(SizeFormatter.formatSize(getApplication(), attachment.size));
|
||||||
Bitmap previewIcon = getPreviewIcon(attachment);
|
Bitmap previewIcon = getPreviewIcon(attachment);
|
||||||
if (previewIcon != null)
|
if (previewIcon != null)
|
||||||
{
|
{
|
||||||
@ -1916,15 +1926,7 @@ public class MessageView extends K9Activity implements OnClickListener
|
|||||||
attachmentIcon.setImageResource(R.drawable.attached_image_placeholder);
|
attachmentIcon.setImageResource(R.drawable.attached_image_placeholder);
|
||||||
}
|
}
|
||||||
mHandler.addAttachment(view);
|
mHandler.addAttachment(view);
|
||||||
}
|
return;
|
||||||
if (part.getBody() instanceof Multipart)
|
|
||||||
{
|
|
||||||
Multipart mp = (Multipart) part.getBody();
|
|
||||||
for (int i = 0; i < mp.getCount(); i++)
|
|
||||||
{
|
|
||||||
renderAttachments(mp.getBodyPart(i), depth + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Listener extends MessagingListener
|
class Listener extends MessagingListener
|
||||||
|
Loading…
x
Reference in New Issue
Block a user