diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index 3fffc3d43b0fd5f29e08497f2febe81d7f4845d1..fd6bae9e189035bd92ff4de47ef186d1c9de211d 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -2109,8 +2109,8 @@ public class ConversationFragment extends XmppFragment handleEncryptionSelection(item); break; case R.id.attach_choose_picture: - case R.id.attach_take_picture: - case R.id.attach_record_video: + //case R.id.attach_take_picture: + //case R.id.attach_record_video: case R.id.attach_choose_file: case R.id.attach_record_voice: case R.id.attach_location: @@ -2394,12 +2394,12 @@ public class ConversationFragment extends XmppFragment case R.id.attach_choose_picture: attachFile(ATTACHMENT_CHOICE_CHOOSE_IMAGE); break; - case R.id.attach_take_picture: + /*case R.id.attach_take_picture: attachFile(ATTACHMENT_CHOICE_TAKE_PHOTO); break; case R.id.attach_record_video: attachFile(ATTACHMENT_CHOICE_RECORD_VIDEO); - break; + break;*/ case R.id.attach_choose_file: attachFile(ATTACHMENT_CHOICE_CHOOSE_FILE); break; @@ -2757,31 +2757,39 @@ public class ConversationFragment extends XmppFragment protected void invokeAttachFileIntent(final int attachmentChoice) { Intent intent = new Intent(); - boolean chooser = false; + + final var takePhotoIntent = new Intent(); + final Uri takePhotoUri = activity.xmppConnectionService.getFileBackend().getTakePhotoUri(); + pendingTakePhotoUri.push(takePhotoUri); + takePhotoIntent.putExtra(MediaStore.EXTRA_OUTPUT, takePhotoUri); + takePhotoIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); + takePhotoIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + takePhotoIntent.setAction(MediaStore.ACTION_IMAGE_CAPTURE); + + final var takeVideoIntent = new Intent(); + takeVideoIntent.setAction(MediaStore.ACTION_VIDEO_CAPTURE); + switch (attachmentChoice) { case ATTACHMENT_CHOICE_CHOOSE_IMAGE: intent.setAction(Intent.ACTION_GET_CONTENT); intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); - intent.setType("image/*"); - chooser = true; + intent.setType("*/*"); + intent.putExtra(Intent.EXTRA_MIME_TYPES, new String[] {"image/*", "video/*"}); + intent = Intent.createChooser(intent, getString(R.string.perform_action_with)); + intent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { takePhotoIntent, takeVideoIntent }); break; case ATTACHMENT_CHOICE_RECORD_VIDEO: - intent.setAction(MediaStore.ACTION_VIDEO_CAPTURE); + intent = takeVideoIntent; 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); + intent = takePhotoIntent; break; case ATTACHMENT_CHOICE_CHOOSE_FILE: - chooser = true; - intent.setType("*/*"); + intent.setAction(Intent.ACTION_GET_CONTENT); intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); + intent.setType("*/*"); intent.addCategory(Intent.CATEGORY_OPENABLE); - intent.setAction(Intent.ACTION_GET_CONTENT); + intent = Intent.createChooser(intent, getString(R.string.perform_action_with)); break; case ATTACHMENT_CHOICE_RECORD_VOICE: intent = new Intent(getActivity(), RecordingActivity.class); @@ -2795,13 +2803,7 @@ public class ConversationFragment extends XmppFragment return; } try { - if (chooser) { - startActivityForResult( - Intent.createChooser(intent, getString(R.string.perform_action_with)), - attachmentChoice); - } else { - startActivityForResult(intent, attachmentChoice); - } + startActivityForResult(intent, attachmentChoice); } catch (final ActivityNotFoundException e) { Toast.makeText(context, R.string.no_application_found, Toast.LENGTH_LONG).show(); } 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 885b5da13777d969b6878536223214a880f959db..5555ce13d324a2c5666ebbedfd5971d59b86072a 100644 --- a/src/main/java/eu/siacs/conversations/ui/util/Attachment.java +++ b/src/main/java/eu/siacs/conversations/ui/util/Attachment.java @@ -202,7 +202,7 @@ public class Attachment implements Parcelable { final Uri uri = clipData.getItemAt(i).getUri(); final String mime = MimeUtils.guessMimeTypeFromUriAndMime(context, uri, contentType); - uris.add(new Attachment(uri, type, mime)); + uris.add(new Attachment(uri, type != Type.IMAGE || mime.startsWith("image/") ? type : Type.FILE, mime)); } } } else { diff --git a/src/main/res/menu/fragment_conversation.xml b/src/main/res/menu/fragment_conversation.xml index 16c2276f2b8beccfef10bc0fd3a058404262e5d0..9f65e90b4b982b519518f5cf525719d7cbc567db 100644 --- a/src/main/res/menu/fragment_conversation.xml +++ b/src/main/res/menu/fragment_conversation.xml @@ -42,16 +42,6 @@ android:icon="@drawable/ic_image_24dp" android:title="@string/attach_choose_picture" /> - - - - + Send presence updates Receive presence updates Ask for presence updates - Choose picture + Choose media Take picture Preemptively grant subscription request The file you selected is not an image @@ -526,7 +526,7 @@ Notifications disabled Notifications paused Image Compression - Hint: Use ‘Choose file’ instead of ‘Choose picture’ to send individual images uncompressed regardless of this setting. + Hint: Use ‘Choose file’ instead of ‘Choose media’ to send individual images uncompressed regardless of this setting. Always Large images only Battery optimizations enabled