Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter for images and video in add media picker #10576

Merged
merged 18 commits into from
Oct 14, 2019
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class RequestCodes {
public static final int PICTURE_LIBRARY = 2000;
public static final int TAKE_PHOTO = 2100;
public static final int VIDEO_LIBRARY = 2200;
public static final int MEDIA_LIBRARY = 2210;
public static final int TAKE_VIDEO = 2300;
public static final int CROP_PHOTO = 2400;
public static final int PICTURE_LIBRARY_OR_CAPTURE = 2500;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3128,6 +3128,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
}
}
break;
case RequestCodes.MEDIA_LIBRARY:
case RequestCodes.PICTURE_LIBRARY:
advertiseImageOptimisationAndAddMedia(data);
break;
Expand Down Expand Up @@ -3546,8 +3547,14 @@ public void onCapturePhotoClicked() {
}

@Override
public void onAddVideoClicked(boolean allowMultipleSelectio) {
onPhotoPickerIconClicked(PhotoPickerIcon.ANDROID_CHOOSE_VIDEO, allowMultipleSelectio);
public void onAddVideoClicked(boolean allowMultipleSelection) {
onPhotoPickerIconClicked(PhotoPickerIcon.ANDROID_CHOOSE_VIDEO, allowMultipleSelection);
}

@Override
public void onAddMediaClicked(boolean allowMultipleSelection) {
mAllowMultipleSelection = allowMultipleSelection;
WPMediaUtils.launchMediaLibrary(this, mAllowMultipleSelection);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm definitely not familiar enough with Android and I'd recommend another reviewer, but I was aware of the MediaBrowserType enum, and I see that the other addMedia methods use ActivityLauncher.viewMediaPickerForResult instead. Is there a reason not to use the same thing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great question! The viewMediaPickerForResult method actually prepares an intent with the "in-house" MediaBrowserActivity (i.e. "WordPress Media Library"). At first glance at the code, I had the same thought, and that may be an indication that the name is ambiguous. OTOH, I'm not sure I can offer a better name, since the MediaBrowserActivity itself has menu items that call through to the device picker (which, incidentally, use the WPMediaUtils methods).

Also, I will take your advice about adding an Android reviewer (more familiar with this area of the code base) 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "WordPress Media Library" flow has also been addressed in this PR.

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,11 @@ public static void launchVideoLibrary(Activity activity, boolean multiSelect) {
RequestCodes.VIDEO_LIBRARY);
}

public static void launchMediaLibrary(Activity activity, boolean multiSelect) {
activity.startActivityForResult(prepareMediaLibraryIntent(activity, multiSelect),
RequestCodes.MEDIA_LIBRARY);
}

private static Intent prepareVideoLibraryIntent(Context context, boolean multiSelect) {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("video/*");
Expand All @@ -229,6 +234,16 @@ private static Intent prepareVideoLibraryIntent(Context context, boolean multiSe
return Intent.createChooser(intent, context.getString(R.string.pick_video));
}

private static Intent prepareMediaLibraryIntent(Context context, boolean multiSelect) {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
intent.putExtra(Intent.EXTRA_MIME_TYPES, new String[] {"image/*", "video/*"});
if (multiSelect) {
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
}
return Intent.createChooser(intent, context.getString(R.string.pick_media));
}

public static void launchVideoCamera(Activity activity) {
activity.startActivityForResult(prepareVideoCameraIntent(), RequestCodes.TAKE_VIDEO);
}
Expand Down
1 change: 1 addition & 0 deletions WordPress/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
<string name="wp_media_title">WordPress media</string>
<string name="pick_photo">Select photo</string>
<string name="pick_video">Select video</string>
<string name="pick_media">Select media</string>
<string name="capture_or_pick_photo">Capture or select photo</string>
<string name="reader_toast_err_get_post">Unable to retrieve this post</string>
<string name="media_error_no_permission">You don\'t have permission to view the media library</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ public interface EditorFragmentListener {
void onAddPhotoClicked(boolean allowMultipleSelection);
void onCapturePhotoClicked();
void onAddVideoClicked(boolean allowMultipleSelection);
void onAddMediaClicked(boolean allowMultipleSelection);
void onCaptureVideoClicked();
boolean onMediaRetryClicked(String mediaId);
void onMediaRetryAllClicked(Set<String> mediaIdSet);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,11 @@ public void onUploadVideoButtonClicked(boolean allowMultipleSelection) {
mEditorFragmentListener.onAddVideoClicked(allowMultipleSelection);
}

@Override
public void onUploadMediaButtonClicked(boolean allowMultipleSelection) {
mEditorFragmentListener.onAddMediaClicked(allowMultipleSelection);
}

@Override
public void onCaptureVideoButtonClicked() {
checkAndRequestCameraAndStoragePermissions(CAPTURE_VIDEO_PERMISSION_REQUEST_CODE);
Expand Down