Added add event

pull/178/head
M66B 5 years ago
parent 86d7bece76
commit aa8bf4437f

@ -3645,6 +3645,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
popupMenu.getMenu().findItem(R.id.menu_manage_keywords).setVisible(message.accountProtocol == EntityAccount.TYPE_IMAP); popupMenu.getMenu().findItem(R.id.menu_manage_keywords).setVisible(message.accountProtocol == EntityAccount.TYPE_IMAP);
popupMenu.getMenu().findItem(R.id.menu_share).setEnabled(message.content); popupMenu.getMenu().findItem(R.id.menu_share).setEnabled(message.content);
popupMenu.getMenu().findItem(R.id.menu_event).setEnabled(message.content);
popupMenu.getMenu().findItem(R.id.menu_print).setEnabled(hasWebView && message.content); popupMenu.getMenu().findItem(R.id.menu_print).setEnabled(hasWebView && message.content);
popupMenu.getMenu().findItem(R.id.menu_print).setVisible(Helper.canPrint(context)); popupMenu.getMenu().findItem(R.id.menu_print).setVisible(Helper.canPrint(context));
@ -3705,7 +3706,10 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
onMenuManageKeywords(message); onMenuManageKeywords(message);
return true; return true;
case R.id.menu_share: case R.id.menu_share:
onMenuShare(message); onMenuShare(message, false);
return true;
case R.id.menu_event:
onMenuShare(message, true);
return true; return true;
case R.id.menu_print: case R.id.menu_print:
onMenuPrint(message); onMenuPrint(message);
@ -4185,15 +4189,17 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
fragment.show(parentFragment.getParentFragmentManager(), "keyword:manage"); fragment.show(parentFragment.getParentFragmentManager(), "keyword:manage");
} }
private void onMenuShare(TupleMessageEx message) { private void onMenuShare(TupleMessageEx message, final boolean event) {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("id", message.id); args.putLong("id", message.id);
new SimpleTask<String[]>() { new SimpleTask<Map<String, String>>() {
@Override @Override
protected String[] onExecute(Context context, Bundle args) throws Throwable { protected Map<String, String> onExecute(Context context, Bundle args) throws Throwable {
long id = args.getLong("id"); long id = args.getLong("id");
Map<String, String> result = new HashMap<>();
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
EntityMessage message = db.message().getMessage(id); EntityMessage message = db.message().getMessage(id);
if (message == null || !message.content) if (message == null || !message.content)
@ -4203,39 +4209,61 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
if (!file.exists()) if (!file.exists())
return null; return null;
String from = null; if (message.identity != null) {
EntityIdentity identity = db.identity().getIdentity(message.identity);
if (identity != null)
result.put("me", identity.email);
}
if (message.from != null && message.from.length > 0) if (message.from != null && message.from.length > 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 html = Helper.readText(file);
String text = HtmlHelper.getText(context, html); String text = HtmlHelper.getText(context, html);
return new String[]{from, message.subject, text}; if (!TextUtils.isEmpty(text))
result.put("text", text);
return result;
} }
@Override @Override
protected void onExecuted(Bundle args, String[] text) { protected void onExecuted(Bundle args, Map<String, String> data) {
if (text == null) if (data == null)
return; return;
Intent share = new Intent(); Intent intent = new Intent();
share.setAction(Intent.ACTION_SEND); if (event) {
share.setType("text/plain"); intent.setAction(Intent.ACTION_INSERT);
if (!TextUtils.isEmpty(text[0])) intent.setData(CalendarContract.Events.CONTENT_URI);
share.putExtra(Intent.EXTRA_EMAIL, new String[]{text[0]}); if (data.containsKey("me"))
if (!TextUtils.isEmpty(text[1])) intent.putExtra(Intent.EXTRA_EMAIL, new String[]{data.get("me")});
share.putExtra(Intent.EXTRA_SUBJECT, text[1]); if (data.containsKey("subject"))
if (!TextUtils.isEmpty(text[2])) intent.putExtra(CalendarContract.Events.TITLE, data.get("subject"));
share.putExtra(Intent.EXTRA_TEXT, text[2]); 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(); PackageManager pm = context.getPackageManager();
if (share.resolveActivity(pm) == null) if (intent.resolveActivity(pm) == null)
Snackbar.make(parentFragment.getView(), 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). Snackbar.LENGTH_LONG).
show(); show();
else else
context.startActivity(Helper.getChooser(context, share)); context.startActivity(Helper.getChooser(context, intent));
} }
@Override @Override

@ -64,6 +64,10 @@
android:id="@+id/menu_share" android:id="@+id/menu_share"
android:title="@string/title_share" /> android:title="@string/title_share" />
<item
android:id="@+id/menu_event"
android:title="@string/title_event" />
<item <item
android:id="@+id/menu_print" android:id="@+id/menu_print"
android:title="@string/title_print" /> android:title="@string/title_print" />

@ -719,6 +719,7 @@
<string name="title_editasnew">Edit as new</string> <string name="title_editasnew">Edit as new</string>
<string name="title_create_rule">Create rule &#8230;</string> <string name="title_create_rule">Create rule &#8230;</string>
<string name="title_share">Share</string> <string name="title_share">Share</string>
<string name="title_event">Add to calendar</string>
<string name="title_pin">Add shortcut</string> <string name="title_pin">Add shortcut</string>
<string name="title_print">Print</string> <string name="title_print">Print</string>
<string name="title_show_headers">Show headers</string> <string name="title_show_headers">Show headers</string>

Loading…
Cancel
Save