From 0b08c39845be006781e28a70c3787f555bd3072e Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 24 Jan 2020 11:13:56 +0100 Subject: [PATCH] Allow opening EML in EML --- .../java/eu/faircode/email/ActivityEML.java | 62 +++++++++++++------ 1 file changed, 44 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ActivityEML.java b/app/src/main/java/eu/faircode/email/ActivityEML.java index 4830aa888e..eb1544d6c9 100644 --- a/app/src/main/java/eu/faircode/email/ActivityEML.java +++ b/app/src/main/java/eu/faircode/email/ActivityEML.java @@ -67,6 +67,19 @@ import javax.mail.Session; import javax.mail.internet.MimeMessage; public class ActivityEML extends ActivityBase { + private TextView tvFrom; + private TextView tvTo; + private TextView tvReplyTo; + private TextView tvCc; + private TextView tvSent; + private TextView tvReceived; + private TextView tvSubject; + private View vSeparatorAttachments; + private RecyclerView rvAttachment; + private TextView tvBody; + private ContentLoadingProgressBar pbWait; + private Group grpReady; + private Uri uri; private MessageHelper.AttachmentPart apart; private static final int REQUEST_ATTACHMENT = 1; @@ -78,18 +91,18 @@ public class ActivityEML extends ActivityBase { getSupportActionBar().setSubtitle("EML"); setContentView(R.layout.activity_eml); - final TextView tvFrom = findViewById(R.id.tvFrom); - final TextView tvTo = findViewById(R.id.tvTo); - final TextView tvReplyTo = findViewById(R.id.tvReplyTo); - final TextView tvCc = findViewById(R.id.tvCc); - final TextView tvSent = findViewById(R.id.tvSent); - final TextView tvReceived = findViewById(R.id.tvReceived); - final TextView tvSubject = findViewById(R.id.tvSubject); - final View vSeparatorAttachments = findViewById(R.id.vSeparatorAttachments); - final RecyclerView rvAttachment = findViewById(R.id.rvAttachment); - final TextView tvBody = findViewById(R.id.tvBody); - final ContentLoadingProgressBar pbWait = findViewById(R.id.pbWait); - final Group grpReady = findViewById(R.id.grpReady); + tvFrom = findViewById(R.id.tvFrom); + tvTo = findViewById(R.id.tvTo); + tvReplyTo = findViewById(R.id.tvReplyTo); + tvCc = findViewById(R.id.tvCc); + tvSent = findViewById(R.id.tvSent); + tvReceived = findViewById(R.id.tvReceived); + tvSubject = findViewById(R.id.tvSubject); + vSeparatorAttachments = findViewById(R.id.vSeparatorAttachments); + rvAttachment = findViewById(R.id.rvAttachment); + tvBody = findViewById(R.id.tvBody); + pbWait = findViewById(R.id.pbWait); + grpReady = findViewById(R.id.grpReady); rvAttachment.setHasFixedSize(false); LinearLayoutManager llm = new LinearLayoutManager(this); @@ -100,19 +113,29 @@ public class ActivityEML extends ActivityBase { vSeparatorAttachments.setVisibility(View.GONE); grpReady.setVisibility(View.GONE); - uri = getIntent().getData(); - if (uri == null) { - pbWait.setVisibility(View.GONE); - return; - } else - pbWait.setVisibility(View.VISIBLE); + load(); + } + + @Override + protected void onNewIntent(Intent intent) { + super.onNewIntent(intent); + setIntent(intent); + load(); + } + private void load() { + uri = getIntent().getData(); Log.i("EML uri=" + uri); Bundle args = new Bundle(); args.putParcelable("uri", uri); new SimpleTask() { + @Override + protected void onPreExecute(Bundle args) { + pbWait.setVisibility(View.VISIBLE); + } + @Override protected void onPostExecute(Bundle args) { pbWait.setVisibility(View.GONE); @@ -122,6 +145,9 @@ public class ActivityEML extends ActivityBase { protected Result onExecute(Context context, Bundle args) throws Throwable { Uri uri = args.getParcelable("uri"); + if (uri == null) + throw new FileNotFoundException(); + if (!"content".equals(uri.getScheme()) && !Helper.hasPermission(context, Manifest.permission.READ_EXTERNAL_STORAGE)) { Log.w("EML uri=" + uri);