FairEmail/app/src/main/java/eu/faircode/email/ActivityCompose.java

105 lines
4.2 KiB
Java
Raw Normal View History

2018-08-02 13:33:06 +00:00
package eu.faircode.email;
/*
2018-08-14 05:53:24 +00:00
This file is part of FairEmail.
2018-08-02 13:33:06 +00:00
2018-08-14 05:53:24 +00:00
FairEmail is free software: you can redistribute it and/or modify
2018-08-02 13:33:06 +00:00
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
NetGuard is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with NetGuard. If not, see <http://www.gnu.org/licenses/>.
Copyright 2018 by Marcel Bokhorst (M66B)
*/
2018-08-23 11:18:07 +00:00
import android.content.Intent;
import android.net.Uri;
2018-08-02 13:33:06 +00:00
import android.os.Bundle;
2018-08-23 11:18:07 +00:00
import android.text.TextUtils;
2018-08-02 13:33:06 +00:00
2018-08-23 11:18:07 +00:00
import java.util.ArrayList;
2018-08-08 06:55:47 +00:00
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
2018-09-04 18:51:09 +00:00
public class ActivityCompose extends ActivityBilling implements FragmentManager.OnBackStackChangedListener {
2018-08-03 07:39:43 +00:00
static final int REQUEST_CONTACT_TO = 1;
static final int REQUEST_CONTACT_CC = 2;
static final int REQUEST_CONTACT_BCC = 3;
2018-09-13 18:24:48 +00:00
static final int REQUEST_IMAGE = 4;
static final int REQUEST_ATTACHMENT = 5;
2018-08-02 13:33:06 +00:00
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_compose);
2018-08-04 16:54:57 +00:00
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
2018-08-02 13:33:06 +00:00
getSupportFragmentManager().addOnBackStackChangedListener(this);
if (getSupportFragmentManager().getFragments().size() == 0) {
2018-08-23 11:18:07 +00:00
Bundle args;
2018-09-04 10:33:27 +00:00
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)) {
2018-08-23 11:18:07 +00:00
args = new Bundle();
args.putString("action", "new");
args.putLong("account", -1);
2018-09-04 10:33:27 +00:00
Uri uri = intent.getData();
if (uri != null && "mailto".equals(uri.getScheme()))
args.putString("to", uri.getSchemeSpecificPart());
if (intent.hasExtra(Intent.EXTRA_EMAIL))
args.putString("to", TextUtils.join(", ", intent.getStringArrayExtra(Intent.EXTRA_EMAIL)));
2018-08-23 11:18:07 +00:00
2018-09-04 10:33:27 +00:00
if (intent.hasExtra(Intent.EXTRA_CC))
args.putString("cc", TextUtils.join(", ", intent.getStringArrayExtra(Intent.EXTRA_CC)));
2018-08-23 11:18:07 +00:00
2018-09-04 10:33:27 +00:00
if (intent.hasExtra(Intent.EXTRA_BCC))
args.putString("bcc", TextUtils.join(", ", intent.getStringArrayExtra(Intent.EXTRA_BCC)));
2018-08-23 11:18:07 +00:00
2018-09-04 10:33:27 +00:00
if (intent.hasExtra(Intent.EXTRA_SUBJECT))
args.putString("subject", intent.getStringExtra(Intent.EXTRA_SUBJECT));
2018-08-23 11:18:07 +00:00
2018-09-04 10:33:27 +00:00
if (intent.hasExtra(Intent.EXTRA_TEXT))
args.putString("body", intent.getStringExtra(Intent.EXTRA_TEXT)); // Intent.EXTRA_HTML_TEXT
2018-08-23 11:18:07 +00:00
2018-09-04 10:33:27 +00:00
if (intent.hasExtra(Intent.EXTRA_STREAM))
if (Intent.ACTION_SEND_MULTIPLE.equals(action))
args.putParcelableArrayList("attachments", intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM));
2018-08-23 11:18:07 +00:00
else {
ArrayList<Uri> uris = new ArrayList<>();
2018-09-04 10:33:27 +00:00
uris.add((Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM));
2018-08-23 11:18:07 +00:00
args.putParcelableArrayList("attachments", uris);
}
} else
2018-09-04 10:33:27 +00:00
args = intent.getExtras();
2018-08-23 11:18:07 +00:00
2018-08-03 09:58:44 +00:00
FragmentCompose fragment = new FragmentCompose();
2018-08-23 11:18:07 +00:00
fragment.setArguments(args);
2018-08-03 09:58:44 +00:00
2018-08-02 13:33:06 +00:00
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.content_frame, fragment).addToBackStack("compose");
fragmentTransaction.commit();
}
}
@Override
public void onBackStackChanged() {
if (getSupportFragmentManager().getBackStackEntryCount() == 0)
finish();
}
}