mirror of https://github.com/M66B/FairEmail.git
Added share files into existing draft
This commit is contained in:
parent
702317acd7
commit
a69e4a090d
|
@ -30,6 +30,7 @@ import android.text.TextUtils;
|
|||
|
||||
import androidx.core.app.TaskStackBuilder;
|
||||
import androidx.core.net.MailTo;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
|
@ -54,14 +55,14 @@ public class ActivityCompose extends ActivityBase implements FragmentManager.OnB
|
|||
getSupportFragmentManager().addOnBackStackChangedListener(this);
|
||||
|
||||
if (getSupportFragmentManager().getBackStackEntryCount() == 0)
|
||||
handle(getIntent());
|
||||
handle(getIntent(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
setIntent(intent);
|
||||
handle(intent);
|
||||
handle(intent, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -84,13 +85,13 @@ public class ActivityCompose extends ActivityBase implements FragmentManager.OnB
|
|||
}
|
||||
}
|
||||
|
||||
private void handle(Intent intent) {
|
||||
private void handle(Intent intent, boolean create) {
|
||||
Bundle args;
|
||||
String action = intent.getAction();
|
||||
Log.i("Handle action=" + action + " create=" + create + " " + this);
|
||||
|
||||
if (isShared(action)) {
|
||||
args = new Bundle();
|
||||
args.putString("action", "new");
|
||||
args.putLong("account", -1);
|
||||
|
||||
Uri uri = intent.getData();
|
||||
if (uri != null && "mailto".equalsIgnoreCase(uri.getScheme())) {
|
||||
|
@ -204,10 +205,27 @@ public class ActivityCompose extends ActivityBase implements FragmentManager.OnB
|
|||
} else
|
||||
args = intent.getExtras();
|
||||
|
||||
FragmentManager fm = getSupportFragmentManager();
|
||||
|
||||
if (!create &&
|
||||
args.size() == 1 && args.containsKey("attachments")) {
|
||||
List<Fragment> fragments = fm.getFragments();
|
||||
if (fragments.size() == 1) {
|
||||
((FragmentCompose) fragments.get(0)).onSharedAttachments(
|
||||
args.getParcelableArrayList("attachments"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (isShared(action)) {
|
||||
args.putString("action", "new");
|
||||
args.putLong("account", -1);
|
||||
}
|
||||
|
||||
FragmentCompose fragment = new FragmentCompose();
|
||||
fragment.setArguments(args);
|
||||
|
||||
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
|
||||
FragmentTransaction fragmentTransaction = fm.beginTransaction();
|
||||
fragmentTransaction.replace(R.id.content_frame, fragment).addToBackStack("compose");
|
||||
fragmentTransaction.commit();
|
||||
}
|
||||
|
|
|
@ -2852,6 +2852,62 @@ public class FragmentCompose extends FragmentBase {
|
|||
}.setExecutor(executor).execute(this, args, "compose:attachment:add");
|
||||
}
|
||||
|
||||
void onSharedAttachments(ArrayList<Uri> uris) {
|
||||
Bundle args = new Bundle();
|
||||
args.putLong("id", working);
|
||||
args.putParcelableArrayList("uris", uris);
|
||||
|
||||
new SimpleTask<ArrayList<Uri>>() {
|
||||
@Override
|
||||
protected ArrayList<Uri> onExecute(Context context, Bundle args) throws Throwable {
|
||||
long id = args.getLong("id");
|
||||
List<Uri> uris = args.getParcelableArrayList("uris");
|
||||
|
||||
ArrayList<Uri> images = new ArrayList<>();
|
||||
for (Uri uri : uris)
|
||||
try {
|
||||
UriInfo info = getInfo(uri, context);
|
||||
if (info.isImage())
|
||||
images.add(uri);
|
||||
else
|
||||
addAttachment(context, id, uri, false, 0, false);
|
||||
} catch (IOException ex) {
|
||||
Log.e(ex);
|
||||
}
|
||||
|
||||
return images;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onExecuted(Bundle args, ArrayList<Uri> images) {
|
||||
if (images.size() == 0)
|
||||
return;
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
boolean image_dialog = prefs.getBoolean("image_dialog", true);
|
||||
|
||||
if (image_dialog) {
|
||||
Helper.hideKeyboard(view);
|
||||
|
||||
Bundle aargs = new Bundle();
|
||||
aargs.putInt("title", android.R.string.ok);
|
||||
aargs.putParcelableArrayList("images", images);
|
||||
|
||||
FragmentDialogAddImage fragment = new FragmentDialogAddImage();
|
||||
fragment.setArguments(aargs);
|
||||
fragment.setTargetFragment(FragmentCompose.this, REQUEST_SHARED);
|
||||
fragment.show(getParentFragmentManager(), "compose:shared");
|
||||
} else
|
||||
onAddImageFile(images);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
Log.unexpectedError(getParentFragmentManager(), ex);
|
||||
}
|
||||
}.execute(this, args, "compose:shared");
|
||||
}
|
||||
|
||||
private List<Uri> getUris(Intent data) {
|
||||
List<Uri> result = new ArrayList<>();
|
||||
|
||||
|
|
Loading…
Reference in New Issue