diff --git a/react-native-gutenberg-bridge/android/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/GutenbergBridgeJS2Parent.java b/react-native-gutenberg-bridge/android/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/GutenbergBridgeJS2Parent.java index 5a1c2044b8bfef..856661273ccdd4 100644 --- a/react-native-gutenberg-bridge/android/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/GutenbergBridgeJS2Parent.java +++ b/react-native-gutenberg-bridge/android/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/GutenbergBridgeJS2Parent.java @@ -55,6 +55,7 @@ public static LogLevel valueOf(int id) { enum MediaType { IMAGE("image"), VIDEO("video"), + MEDIA("media"), AUDIO("audio"), OTHER("other"); diff --git a/react-native-gutenberg-bridge/android/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/RNReactNativeGutenbergBridgeModule.java b/react-native-gutenberg-bridge/android/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/RNReactNativeGutenbergBridgeModule.java index c3f595e5ce8663..4ef6fb00c280d6 100644 --- a/react-native-gutenberg-bridge/android/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/RNReactNativeGutenbergBridgeModule.java +++ b/react-native-gutenberg-bridge/android/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/RNReactNativeGutenbergBridgeModule.java @@ -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; @@ -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)) { @@ -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 diff --git a/react-native-gutenberg-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/WPAndroidGlueCode.java b/react-native-gutenberg-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/WPAndroidGlueCode.java index 668513817ff265..40c7707076bef2 100644 --- a/react-native-gutenberg-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/WPAndroidGlueCode.java +++ b/react-native-gutenberg-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/WPAndroidGlueCode.java @@ -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); @@ -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); } } @@ -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) {