From 11a9eff109495ea20977898a1c7669c57185098f Mon Sep 17 00:00:00 2001 From: cketti Date: Sun, 9 Nov 2014 20:46:46 +0100 Subject: [PATCH] Extract intent creation code to method --- src/com/fsck/k9/view/AttachmentView.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/com/fsck/k9/view/AttachmentView.java b/src/com/fsck/k9/view/AttachmentView.java index dc20de7ec..35740beeb 100644 --- a/src/com/fsck/k9/view/AttachmentView.java +++ b/src/com/fsck/k9/view/AttachmentView.java @@ -240,11 +240,7 @@ public class AttachmentView extends FrameLayout implements OnClickListener, OnLo public void showFile() { Uri uri = AttachmentProvider.getAttachmentUriForViewing(account, part.getAttachmentId()); - Intent intent = new Intent(Intent.ACTION_VIEW); - // We explicitly set the content type in addition to the URI because some attachment viewers - // (such as Polaris office 3.0.x) choke on documents without a MIME type. - intent.setDataAndType(uri, contentType); - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); + Intent intent = createViewIntentForContentUri(contentType, uri); try { context.startActivity(intent); @@ -256,6 +252,14 @@ public class AttachmentView extends FrameLayout implements OnClickListener, OnLo } } + private Intent createViewIntentForContentUri(String mimeType, Uri uri) { + Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setDataAndType(uri, mimeType); + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); + + return intent; + } + private void displayAttachmentSavedMessage(final String filename) { String message = context.getString(R.string.message_view_status_attachment_saved, filename); displayMessageToUser(message);