From bcab77a0448da4f54912ca7c14f7b2febc7e9ad6 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 27 Apr 2019 14:41:43 +0200 Subject: [PATCH] wait with presence selection until attachment commit --- .../ui/ConversationFragment.java | 112 +++++++++--------- .../conversations/ui/util/Attachment.java | 9 ++ 2 files changed, 63 insertions(+), 58 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index b6f33204e..72bcb3052 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -877,7 +877,10 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke mediaPreviewAdapter.notifyDataSetChanged(); toggleInputMethod(); }; - if (conversation == null || conversation.getMode() == Conversation.MODE_MULTI || FileBackend.allFilesUnderSize(getActivity(), attachments, getMaxHttpUploadSize(conversation))) { + if (conversation == null + || conversation.getMode() == Conversation.MODE_MULTI + || Attachment.canBeSendInband(attachments) + || (conversation.getAccount().httpUploadAvailable() && FileBackend.allFilesUnderSize(getActivity(), attachments, getMaxHttpUploadSize(conversation)))) { callback.onPresenceSelected(); } else { activity.selectPresence(conversation, callback); @@ -1329,7 +1332,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke @Override public void success(Contact contact) { - selectPresenceToAttachFile(attachmentChoice); + invokeAttachFileIntent(attachmentChoice); } @Override @@ -1343,19 +1346,19 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke warning.setGravity(Gravity.CENTER_VERTICAL, 0, 0); warning.show(); } - selectPresenceToAttachFile(attachmentChoice); + invokeAttachFileIntent(attachmentChoice); } else { showNoPGPKeyDialog(false, (dialog, which) -> { conversation.setNextEncryption(Message.ENCRYPTION_NONE); activity.xmppConnectionService.updateConversation(conversation); - selectPresenceToAttachFile(attachmentChoice); + invokeAttachFileIntent(attachmentChoice); }); } } else { activity.showInstallPgpDialog(); } } else { - selectPresenceToAttachFile(attachmentChoice); + invokeAttachFileIntent(attachmentChoice); } } @@ -1509,61 +1512,54 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke getActivity().invalidateOptionsMenu(); } - protected void selectPresenceToAttachFile(final int attachmentChoice) { - final Account account = conversation.getAccount(); - final PresenceSelector.OnPresenceSelected callback = () -> { - Intent intent = new Intent(); - boolean chooser = false; - switch (attachmentChoice) { - case ATTACHMENT_CHOICE_CHOOSE_IMAGE: - intent.setAction(Intent.ACTION_GET_CONTENT); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { - intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); - } - intent.setType("image/*"); - chooser = true; - break; - case ATTACHMENT_CHOICE_RECORD_VIDEO: - intent.setAction(MediaStore.ACTION_VIDEO_CAPTURE); - break; - case ATTACHMENT_CHOICE_TAKE_PHOTO: - final Uri uri = activity.xmppConnectionService.getFileBackend().getTakePhotoUri(); - pendingTakePhotoUri.push(uri); - intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); - intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE); - break; - case ATTACHMENT_CHOICE_CHOOSE_FILE: - chooser = true; - intent.setType("*/*"); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { - intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); - } - intent.addCategory(Intent.CATEGORY_OPENABLE); - intent.setAction(Intent.ACTION_GET_CONTENT); - break; - case ATTACHMENT_CHOICE_RECORD_VOICE: - intent = new Intent(getActivity(), RecordingActivity.class); - break; - case ATTACHMENT_CHOICE_LOCATION: - intent = GeoHelper.getFetchIntent(activity); - break; - } - if (intent.resolveActivity(getActivity().getPackageManager()) != null) { - if (chooser) { - startActivityForResult( - Intent.createChooser(intent, getString(R.string.perform_action_with)), - attachmentChoice); - } else { - startActivityForResult(intent, attachmentChoice); + + protected void invokeAttachFileIntent(final int attachmentChoice) { + Intent intent = new Intent(); + boolean chooser = false; + switch (attachmentChoice) { + case ATTACHMENT_CHOICE_CHOOSE_IMAGE: + intent.setAction(Intent.ACTION_GET_CONTENT); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { + intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); } + intent.setType("image/*"); + chooser = true; + break; + case ATTACHMENT_CHOICE_RECORD_VIDEO: + intent.setAction(MediaStore.ACTION_VIDEO_CAPTURE); + break; + case ATTACHMENT_CHOICE_TAKE_PHOTO: + final Uri uri = activity.xmppConnectionService.getFileBackend().getTakePhotoUri(); + pendingTakePhotoUri.push(uri); + intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); + intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE); + break; + case ATTACHMENT_CHOICE_CHOOSE_FILE: + chooser = true; + intent.setType("*/*"); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { + intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); + } + intent.addCategory(Intent.CATEGORY_OPENABLE); + intent.setAction(Intent.ACTION_GET_CONTENT); + break; + case ATTACHMENT_CHOICE_RECORD_VOICE: + intent = new Intent(getActivity(), RecordingActivity.class); + break; + case ATTACHMENT_CHOICE_LOCATION: + intent = GeoHelper.getFetchIntent(activity); + break; + } + if (intent.resolveActivity(getActivity().getPackageManager()) != null) { + if (chooser) { + startActivityForResult( + Intent.createChooser(intent, getString(R.string.perform_action_with)), + attachmentChoice); + } else { + startActivityForResult(intent, attachmentChoice); } - }; - if (account.httpUploadAvailable() || attachmentChoice == ATTACHMENT_CHOICE_LOCATION) { - callback.onPresenceSelected(); - } else { - activity.selectPresence(conversation, callback); } } diff --git a/src/main/java/eu/siacs/conversations/ui/util/Attachment.java b/src/main/java/eu/siacs/conversations/ui/util/Attachment.java index 4a13be151..299e92486 100644 --- a/src/main/java/eu/siacs/conversations/ui/util/Attachment.java +++ b/src/main/java/eu/siacs/conversations/ui/util/Attachment.java @@ -111,6 +111,15 @@ public class Attachment implements Parcelable { this.uuid = UUID.randomUUID(); } + public static boolean canBeSendInband(final List attachments) { + for(Attachment attachment : attachments) { + if (attachment.type != Type.LOCATION) { + return false; + } + } + return true; + } + public static List of(final Context context, Uri uri, Type type) { final String mime = type == Type.LOCATION ?null :MimeUtils.guessMimeTypeFromUri(context, uri); return Collections.singletonList(new Attachment(uri, type, mime));