From aa8bf4437fe6d35f69bd1a78c5f413f18cda1d2e Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 20 May 2020 18:55:46 +0200 Subject: [PATCH] Added add event --- .../eu/faircode/email/AdapterMessage.java | 70 +++++++++++++------ app/src/main/res/menu/popup_message_more.xml | 4 ++ app/src/main/res/values/strings.xml | 1 + 3 files changed, 54 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java index 4d79f90ba9..fb6ff8ced6 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMessage.java +++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java @@ -3645,6 +3645,7 @@ public class AdapterMessage extends RecyclerView.Adapter() { + new SimpleTask>() { @Override - protected String[] onExecute(Context context, Bundle args) throws Throwable { + protected Map onExecute(Context context, Bundle args) throws Throwable { long id = args.getLong("id"); + Map result = new HashMap<>(); + DB db = DB.getInstance(context); EntityMessage message = db.message().getMessage(id); if (message == null || !message.content) @@ -4203,39 +4209,61 @@ public class AdapterMessage extends RecyclerView.Adapter 0) - from = ((InternetAddress) message.from[0]).getAddress(); + result.put("from", ((InternetAddress) message.from[0]).getAddress()); + + if (!TextUtils.isEmpty(message.subject)) + result.put("subject", message.subject); String html = Helper.readText(file); String text = HtmlHelper.getText(context, html); - return new String[]{from, message.subject, text}; + if (!TextUtils.isEmpty(text)) + result.put("text", text); + + return result; } @Override - protected void onExecuted(Bundle args, String[] text) { - if (text == null) + protected void onExecuted(Bundle args, Map data) { + if (data == null) return; - Intent share = new Intent(); - share.setAction(Intent.ACTION_SEND); - share.setType("text/plain"); - if (!TextUtils.isEmpty(text[0])) - share.putExtra(Intent.EXTRA_EMAIL, new String[]{text[0]}); - if (!TextUtils.isEmpty(text[1])) - share.putExtra(Intent.EXTRA_SUBJECT, text[1]); - if (!TextUtils.isEmpty(text[2])) - share.putExtra(Intent.EXTRA_TEXT, text[2]); + Intent intent = new Intent(); + if (event) { + intent.setAction(Intent.ACTION_INSERT); + intent.setData(CalendarContract.Events.CONTENT_URI); + if (data.containsKey("me")) + intent.putExtra(Intent.EXTRA_EMAIL, new String[]{data.get("me")}); + if (data.containsKey("subject")) + intent.putExtra(CalendarContract.Events.TITLE, data.get("subject")); + if (data.containsKey("text")) + intent.putExtra(CalendarContract.Events.DESCRIPTION, data.get("text")); + } else { + intent.setAction(Intent.ACTION_SEND); + intent.setType("text/plain"); + if (data.containsKey("from")) + intent.putExtra(Intent.EXTRA_EMAIL, new String[]{data.get("from")}); + if (data.containsKey("subject")) + intent.putExtra(Intent.EXTRA_SUBJECT, data.get("subject")); + if (data.containsKey("text")) + intent.putExtra(Intent.EXTRA_TEXT, data.get("text")); + } PackageManager pm = context.getPackageManager(); - if (share.resolveActivity(pm) == null) + if (intent.resolveActivity(pm) == null) Snackbar.make(parentFragment.getView(), - context.getString(R.string.title_no_viewer, share.getAction()), + context.getString(R.string.title_no_viewer, intent.getAction()), Snackbar.LENGTH_LONG). show(); else - context.startActivity(Helper.getChooser(context, share)); + context.startActivity(Helper.getChooser(context, intent)); } @Override diff --git a/app/src/main/res/menu/popup_message_more.xml b/app/src/main/res/menu/popup_message_more.xml index 977b711140..4571d0323e 100644 --- a/app/src/main/res/menu/popup_message_more.xml +++ b/app/src/main/res/menu/popup_message_more.xml @@ -64,6 +64,10 @@ android:id="@+id/menu_share" android:title="@string/title_share" /> + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3482875484..0ff48ae688 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -719,6 +719,7 @@ Edit as new Create rule … Share + Add to calendar Add shortcut Print Show headers