mirror of https://github.com/M66B/FairEmail.git
Added share into
This commit is contained in:
parent
dd960c39a4
commit
8be1b3394c
|
@ -44,117 +44,14 @@ public class ActivityCompose extends ActivityBase implements FragmentManager.OnB
|
|||
|
||||
getSupportFragmentManager().addOnBackStackChangedListener(this);
|
||||
|
||||
if (getSupportFragmentManager().getFragments().size() == 0) {
|
||||
Bundle args;
|
||||
Intent intent = getIntent();
|
||||
String action = intent.getAction();
|
||||
if (Intent.ACTION_VIEW.equals(action) ||
|
||||
Intent.ACTION_SENDTO.equals(action) ||
|
||||
Intent.ACTION_SEND.equals(action) ||
|
||||
Intent.ACTION_SEND_MULTIPLE.equals(action)) {
|
||||
handle(getIntent());
|
||||
}
|
||||
|
||||
args = new Bundle();
|
||||
args.putString("action", "new");
|
||||
args.putLong("account", -1);
|
||||
|
||||
Uri uri = intent.getData();
|
||||
if (uri != null && "mailto".equals(uri.getScheme())) {
|
||||
// https://www.ietf.org/rfc/rfc2368.txt
|
||||
String url = uri.toString();
|
||||
int query = url.indexOf('?', MailTo.MAILTO_SCHEME.length());
|
||||
if (query > 0)
|
||||
url = url.substring(0, query) + url.substring(query).replace(":", "%3A");
|
||||
|
||||
MailTo mailto = MailTo.parse(url);
|
||||
|
||||
String to = mailto.getTo();
|
||||
if (to != null)
|
||||
args.putString("to", to);
|
||||
|
||||
String cc = mailto.getCc();
|
||||
if (cc != null)
|
||||
args.putString("cc", cc);
|
||||
|
||||
String subject = mailto.getSubject();
|
||||
if (subject != null)
|
||||
args.putString("subject", subject);
|
||||
|
||||
String body = mailto.getBody();
|
||||
if (body != null)
|
||||
args.putString("body", body);
|
||||
}
|
||||
|
||||
if (intent.hasExtra(Intent.EXTRA_SHORTCUT_ID)) {
|
||||
String to = intent.getStringExtra(Intent.EXTRA_SHORTCUT_ID);
|
||||
if (to != null)
|
||||
args.putString("to", to);
|
||||
}
|
||||
|
||||
if (intent.hasExtra(Intent.EXTRA_EMAIL)) {
|
||||
String[] to = intent.getStringArrayExtra(Intent.EXTRA_EMAIL);
|
||||
if (to != null)
|
||||
args.putString("to", TextUtils.join(", ", to));
|
||||
}
|
||||
|
||||
if (intent.hasExtra(Intent.EXTRA_CC)) {
|
||||
String[] cc = intent.getStringArrayExtra(Intent.EXTRA_CC);
|
||||
if (cc != null)
|
||||
args.putString("cc", TextUtils.join(", ", cc));
|
||||
}
|
||||
|
||||
if (intent.hasExtra(Intent.EXTRA_BCC)) {
|
||||
String[] bcc = intent.getStringArrayExtra(Intent.EXTRA_BCC);
|
||||
if (bcc != null)
|
||||
args.putString("bcc", TextUtils.join(", ", bcc));
|
||||
}
|
||||
|
||||
if (intent.hasExtra(Intent.EXTRA_SUBJECT)) {
|
||||
String subject = intent.getStringExtra(Intent.EXTRA_SUBJECT);
|
||||
if (subject != null)
|
||||
args.putString("subject", subject);
|
||||
}
|
||||
|
||||
if (intent.hasExtra(Intent.EXTRA_HTML_TEXT)) {
|
||||
String html = intent.getStringExtra(Intent.EXTRA_HTML_TEXT);
|
||||
if (!TextUtils.isEmpty(html))
|
||||
args.putString("body", html);
|
||||
} else if (intent.hasExtra(Intent.EXTRA_TEXT)) {
|
||||
CharSequence body = intent.getCharSequenceExtra(Intent.EXTRA_TEXT);
|
||||
if (body != null)
|
||||
if (body instanceof Spanned)
|
||||
args.putString("body", HtmlHelper.toHtml((Spanned) body, this));
|
||||
else {
|
||||
String text = body.toString();
|
||||
if (!TextUtils.isEmpty(text)) {
|
||||
String html = "<span>" + text.replaceAll("\\r?\\n", "<br>") + "</span>";
|
||||
args.putString("body", html);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (intent.hasExtra(Intent.EXTRA_STREAM))
|
||||
if (Intent.ACTION_SEND_MULTIPLE.equals(action)) {
|
||||
ArrayList<Uri> uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
|
||||
if (uris != null)
|
||||
args.putParcelableArrayList("attachments", uris);
|
||||
} else {
|
||||
Uri stream = intent.getParcelableExtra(Intent.EXTRA_STREAM);
|
||||
if (stream != null) {
|
||||
ArrayList<Uri> uris = new ArrayList<>();
|
||||
uris.add(stream);
|
||||
args.putParcelableArrayList("attachments", uris);
|
||||
}
|
||||
}
|
||||
} else
|
||||
args = intent.getExtras();
|
||||
|
||||
FragmentCompose fragment = new FragmentCompose();
|
||||
fragment.setArguments(args);
|
||||
|
||||
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
|
||||
fragmentTransaction.replace(R.id.content_frame, fragment).addToBackStack("compose");
|
||||
fragmentTransaction.commit();
|
||||
}
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
setIntent(intent);
|
||||
handle(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -174,4 +71,115 @@ public class ActivityCompose extends ActivityBase implements FragmentManager.OnB
|
|||
finishAndRemoveTask();
|
||||
}
|
||||
}
|
||||
|
||||
private void handle(Intent intent) {
|
||||
Bundle args;
|
||||
String action = intent.getAction();
|
||||
if (Intent.ACTION_VIEW.equals(action) ||
|
||||
Intent.ACTION_SENDTO.equals(action) ||
|
||||
Intent.ACTION_SEND.equals(action) ||
|
||||
Intent.ACTION_SEND_MULTIPLE.equals(action)) {
|
||||
|
||||
args = new Bundle();
|
||||
args.putString("action", "new");
|
||||
args.putLong("account", -1);
|
||||
|
||||
Uri uri = intent.getData();
|
||||
if (uri != null && "mailto".equals(uri.getScheme())) {
|
||||
// https://www.ietf.org/rfc/rfc2368.txt
|
||||
String url = uri.toString();
|
||||
int query = url.indexOf('?', MailTo.MAILTO_SCHEME.length());
|
||||
if (query > 0)
|
||||
url = url.substring(0, query) + url.substring(query).replace(":", "%3A");
|
||||
|
||||
MailTo mailto = MailTo.parse(url);
|
||||
|
||||
String to = mailto.getTo();
|
||||
if (to != null)
|
||||
args.putString("to", to);
|
||||
|
||||
String cc = mailto.getCc();
|
||||
if (cc != null)
|
||||
args.putString("cc", cc);
|
||||
|
||||
String subject = mailto.getSubject();
|
||||
if (subject != null)
|
||||
args.putString("subject", subject);
|
||||
|
||||
String body = mailto.getBody();
|
||||
if (body != null)
|
||||
args.putString("body", body);
|
||||
}
|
||||
|
||||
if (intent.hasExtra(Intent.EXTRA_SHORTCUT_ID)) {
|
||||
String to = intent.getStringExtra(Intent.EXTRA_SHORTCUT_ID);
|
||||
if (to != null)
|
||||
args.putString("to", to);
|
||||
}
|
||||
|
||||
if (intent.hasExtra(Intent.EXTRA_EMAIL)) {
|
||||
String[] to = intent.getStringArrayExtra(Intent.EXTRA_EMAIL);
|
||||
if (to != null)
|
||||
args.putString("to", TextUtils.join(", ", to));
|
||||
}
|
||||
|
||||
if (intent.hasExtra(Intent.EXTRA_CC)) {
|
||||
String[] cc = intent.getStringArrayExtra(Intent.EXTRA_CC);
|
||||
if (cc != null)
|
||||
args.putString("cc", TextUtils.join(", ", cc));
|
||||
}
|
||||
|
||||
if (intent.hasExtra(Intent.EXTRA_BCC)) {
|
||||
String[] bcc = intent.getStringArrayExtra(Intent.EXTRA_BCC);
|
||||
if (bcc != null)
|
||||
args.putString("bcc", TextUtils.join(", ", bcc));
|
||||
}
|
||||
|
||||
if (intent.hasExtra(Intent.EXTRA_SUBJECT)) {
|
||||
String subject = intent.getStringExtra(Intent.EXTRA_SUBJECT);
|
||||
if (subject != null)
|
||||
args.putString("subject", subject);
|
||||
}
|
||||
|
||||
if (intent.hasExtra(Intent.EXTRA_HTML_TEXT)) {
|
||||
String html = intent.getStringExtra(Intent.EXTRA_HTML_TEXT);
|
||||
if (!TextUtils.isEmpty(html))
|
||||
args.putString("body", html);
|
||||
} else if (intent.hasExtra(Intent.EXTRA_TEXT)) {
|
||||
CharSequence body = intent.getCharSequenceExtra(Intent.EXTRA_TEXT);
|
||||
if (body != null)
|
||||
if (body instanceof Spanned)
|
||||
args.putString("body", HtmlHelper.toHtml((Spanned) body, this));
|
||||
else {
|
||||
String text = body.toString();
|
||||
if (!TextUtils.isEmpty(text)) {
|
||||
String html = "<span>" + text.replaceAll("\\r?\\n", "<br>") + "</span>";
|
||||
args.putString("body", html);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (intent.hasExtra(Intent.EXTRA_STREAM))
|
||||
if (Intent.ACTION_SEND_MULTIPLE.equals(action)) {
|
||||
ArrayList<Uri> uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
|
||||
if (uris != null)
|
||||
args.putParcelableArrayList("attachments", uris);
|
||||
} else {
|
||||
Uri stream = intent.getParcelableExtra(Intent.EXTRA_STREAM);
|
||||
if (stream != null) {
|
||||
ArrayList<Uri> uris = new ArrayList<>();
|
||||
uris.add(stream);
|
||||
args.putParcelableArrayList("attachments", uris);
|
||||
}
|
||||
}
|
||||
} else
|
||||
args = intent.getExtras();
|
||||
|
||||
FragmentCompose fragment = new FragmentCompose();
|
||||
fragment.setArguments(args);
|
||||
|
||||
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
|
||||
fragmentTransaction.replace(R.id.content_frame, fragment).addToBackStack("compose");
|
||||
fragmentTransaction.commit();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue