Skip to content

Commit

Permalink
Merge pull request #1412 from wordpress-mobile/try/fix-media-text-dev…
Browse files Browse the repository at this point in the history
…ice-picker-android

Filter for images and video in add media picker
  • Loading branch information
mkevins authored Oct 14, 2019
2 parents f5a2739 + fe20493 commit 50ed338
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public static LogLevel valueOf(int id) {
enum MediaType {
IMAGE("image"),
VIDEO("video"),
MEDIA("media"),
AUDIO("audio"),
OTHER("other");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.facebook.react.modules.core.DeviceEventManagerModule;

import org.wordpress.mobile.ReactNativeGutenbergBridge.GutenbergBridgeJS2Parent.MediaSelectedCallback;
import org.wordpress.mobile.ReactNativeGutenbergBridge.GutenbergBridgeJS2Parent.MediaType;
import org.wordpress.mobile.ReactNativeGutenbergBridge.GutenbergBridgeJS2Parent.RNMedia;

import java.util.List;
Expand Down Expand Up @@ -107,7 +108,7 @@ public void editorDidMount(ReadableArray unsupportedBlockNames) {

@ReactMethod
public void requestMediaPickFrom(String mediaSource, ReadableArray filter, Boolean allowMultipleSelection, final Callback onUploadMediaSelected) {
GutenbergBridgeJS2Parent.MediaType mediaType = getMediaTypeFromFilter(filter);
MediaType mediaType = getMediaTypeFromFilter(filter);
if (mediaSource.equals(MEDIA_SOURCE_MEDIA_LIBRARY)) {
mGutenbergBridgeJS2Parent.requestMediaPickFromMediaLibrary(getNewMediaSelectedCallback(allowMultipleSelection, onUploadMediaSelected), allowMultipleSelection, mediaType);
} else if (mediaSource.equals(MEDIA_SOURCE_DEVICE_LIBRARY)) {
Expand All @@ -117,13 +118,21 @@ public void requestMediaPickFrom(String mediaSource, ReadableArray filter, Boole
}
}

private GutenbergBridgeJS2Parent.MediaType getMediaTypeFromFilter(ReadableArray filter) {
for (Object object : filter.toArrayList()) {
String filterValue = (String) object;
return GutenbergBridgeJS2Parent.MediaType.getEnum(filterValue);
}
private MediaType getMediaTypeFromFilter(ReadableArray filter) {
switch (filter.size()) {
case 1:
return MediaType.getEnum(filter.getString(0));
case 2:
MediaType filter0 = MediaType.getEnum(filter.getString(0));
MediaType filter1 = MediaType.getEnum(filter.getString(1));

return GutenbergBridgeJS2Parent.MediaType.OTHER;
if ((filter0.equals(MediaType.VIDEO) && filter1.equals(MediaType.IMAGE))
|| (filter0.equals(MediaType.IMAGE) && filter1.equals(MediaType.VIDEO))) {
return MediaType.MEDIA;
}
default:
return MediaType.OTHER;
}
}

@ReactMethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,11 @@ public boolean isContentChanged() {
public interface OnMediaLibraryButtonListener {
void onMediaLibraryImageButtonClicked(boolean allowMultipleSelection);
void onMediaLibraryVideoButtonClicked(boolean allowMultipleSelection);
void onMediaLibraryMediaButtonClicked(boolean allowMultipleSelection);
void onUploadPhotoButtonClicked(boolean allowMultipleSelection);
void onCapturePhotoButtonClicked();
void onUploadVideoButtonClicked(boolean allowMultipleSelection);
void onUploadMediaButtonClicked(boolean allowMultipleSelection);
void onCaptureVideoButtonClicked();
void onRetryUploadForMediaClicked(int mediaId);
void onCancelUploadForMediaClicked(int mediaId);
Expand Down Expand Up @@ -158,6 +160,8 @@ public void requestMediaPickFromMediaLibrary(MediaSelectedCallback mediaSelected
mOnMediaLibraryButtonListener.onMediaLibraryImageButtonClicked(allowMultipleSelection);
} else if (mediaType == MediaType.VIDEO) {
mOnMediaLibraryButtonListener.onMediaLibraryVideoButtonClicked(allowMultipleSelection);
} else if (mediaType == MediaType.MEDIA) {
mOnMediaLibraryButtonListener.onMediaLibraryMediaButtonClicked(allowMultipleSelection);
}
}

Expand All @@ -169,8 +173,10 @@ public void requestMediaPickFromDeviceLibrary(MediaUploadCallback mediaUploadCal
mOnMediaLibraryButtonListener.onUploadPhotoButtonClicked(allowMultipleSelection);
} else if (mediaType == MediaType.VIDEO) {
mOnMediaLibraryButtonListener.onUploadVideoButtonClicked(allowMultipleSelection);
}
} else if (mediaType == MediaType.MEDIA) {
mOnMediaLibraryButtonListener.onUploadMediaButtonClicked(allowMultipleSelection);
}
}

@Override
public void requestMediaPickerFromDeviceCamera(MediaUploadCallback mediaUploadCallback, MediaType mediaType) {
Expand Down

0 comments on commit 50ed338

Please sign in to comment.