Allow selecting multiple attachments

pull/147/head
M66B 6 years ago
parent 857765727e
commit e01728a202

@ -22,6 +22,7 @@ package eu.faircode.email;
import android.Manifest; import android.Manifest;
import android.app.Activity; import android.app.Activity;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.ClipData;
import android.content.ClipboardManager; import android.content.ClipboardManager;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
@ -698,6 +699,7 @@ public class FragmentCompose extends FragmentEx {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE); intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*"); intent.setType("*/*");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
PackageManager pm = getContext().getPackageManager(); PackageManager pm = getContext().getPackageManager();
if (intent.resolveActivity(pm) == null) if (intent.resolveActivity(pm) == null)
Snackbar.make(view, R.string.title_no_saf, Snackbar.LENGTH_LONG).show(); Snackbar.make(view, R.string.title_no_saf, Snackbar.LENGTH_LONG).show();
@ -919,11 +921,22 @@ public class FragmentCompose extends FragmentEx {
public void onActivityResult(int requestCode, int resultCode, Intent data) { public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) { if (resultCode == RESULT_OK) {
if (requestCode == ActivityCompose.REQUEST_IMAGE) { if (requestCode == ActivityCompose.REQUEST_IMAGE) {
if (data != null) if (data != null) {
handleAddAttachment(data, true); Uri uri = data.getData();
if (uri != null)
handleAddAttachment(uri, true);
}
} else if (requestCode == ActivityCompose.REQUEST_ATTACHMENT) { } else if (requestCode == ActivityCompose.REQUEST_ATTACHMENT) {
if (data != null) if (data != null) {
handleAddAttachment(data, false); ClipData clipData = data.getClipData();
if (clipData != null)
for (int i = 0; i < clipData.getItemCount(); i++) {
ClipData.Item item = clipData.getItemAt(i);
Uri uri = item.getUri();
if (uri != null)
handleAddAttachment(uri, false);
}
}
} else if (requestCode == ActivityCompose.REQUEST_ENCRYPT) { } else if (requestCode == ActivityCompose.REQUEST_ENCRYPT) {
if (data != null) { if (data != null) {
data.setAction(OpenPgpApi.ACTION_SIGN_AND_ENCRYPT); data.setAction(OpenPgpApi.ACTION_SIGN_AND_ENCRYPT);
@ -981,14 +994,10 @@ public class FragmentCompose extends FragmentEx {
} }
} }
private void handleAddAttachment(Intent data, final boolean image) { private void handleAddAttachment(Uri uri, final boolean image) {
Uri uri = data.getData();
if (uri == null)
return;
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("id", working); args.putLong("id", working);
args.putParcelable("uri", data.getData()); args.putParcelable("uri", uri);
new SimpleTask<EntityAttachment>() { new SimpleTask<EntityAttachment>() {
@Override @Override

Loading…
Cancel
Save