From edfae08bb86950f5afb2f45c1aaa6a0c48e50da6 Mon Sep 17 00:00:00 2001 From: Matthew Kevins Date: Mon, 7 Oct 2019 15:09:37 +1000 Subject: [PATCH 1/7] Add upload media to button listener interface in glue code --- .../org/wordpress/mobile/WPAndroidGlue/WPAndroidGlueCode.java | 1 + 1 file changed, 1 insertion(+) 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 b0a79684da9158..1c696f997c1347 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 @@ -109,6 +109,7 @@ public interface OnMediaLibraryButtonListener { void onUploadPhotoButtonClicked(boolean allowMultipleSelection); void onCapturePhotoButtonClicked(); void onUploadVideoButtonClicked(boolean allowMultipleSelection); + void onUploadMediaButtonClicked(boolean allowMultipleSelection); void onCaptureVideoButtonClicked(); void onRetryUploadForMediaClicked(int mediaId); void onCancelUploadForMediaClicked(int mediaId); From 56ffdcbbe384652725ece3f60ff1a66c89df88bf Mon Sep 17 00:00:00 2001 From: Matthew Kevins Date: Mon, 7 Oct 2019 15:10:15 +1000 Subject: [PATCH 2/7] Add "media" MediaType --- .../ReactNativeGutenbergBridge/GutenbergBridgeJS2Parent.java | 1 + 1 file changed, 1 insertion(+) 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"); From 796d3caacda13bce43138dd9403d8535bf90600a Mon Sep 17 00:00:00 2001 From: Matthew Kevins Date: Mon, 7 Oct 2019 15:11:14 +1000 Subject: [PATCH 3/7] Detect "media" MediaType from filter --- .../RNReactNativeGutenbergBridgeModule.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) 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..aec3e876e22100 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; @@ -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 From fc8574802fa94d764a9c85a7f6ae34e1fadd5c74 Mon Sep 17 00:00:00 2001 From: Matthew Kevins Date: Mon, 7 Oct 2019 15:12:18 +1000 Subject: [PATCH 4/7] Invoke button listener method for "media" MediaType --- .../org/wordpress/mobile/WPAndroidGlue/WPAndroidGlueCode.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 1c696f997c1347..36e7f505c16301 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 @@ -169,8 +169,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) { From 4097c575f8eb2f9b810cd47288d7b6294c6ca855 Mon Sep 17 00:00:00 2001 From: Matthew Kevins Date: Mon, 7 Oct 2019 15:14:27 +1000 Subject: [PATCH 5/7] Use MediaType static import consistently --- .../RNReactNativeGutenbergBridgeModule.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 aec3e876e22100..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 @@ -108,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)) { From 2fb8c33e905c3d637421db5125e8888615f2262a Mon Sep 17 00:00:00 2001 From: Matthew Kevins Date: Thu, 10 Oct 2019 22:30:21 +1000 Subject: [PATCH 6/7] Update gutenberg reference --- gutenberg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gutenberg b/gutenberg index a5be0065621bd2..70aa7c9f61ee2b 160000 --- a/gutenberg +++ b/gutenberg @@ -1 +1 @@ -Subproject commit a5be0065621bd2799e23d94ae6a6b34ed1636fe5 +Subproject commit 70aa7c9f61ee2b4dd4c9c38b175b6b6b8543d8e8 From 3bfb7aabfbb4856b7548bd0624e0d1e2e5ac0225 Mon Sep 17 00:00:00 2001 From: Matthew Kevins Date: Thu, 10 Oct 2019 23:17:41 +1000 Subject: [PATCH 7/7] Call media library method for media mediatype --- .../org/wordpress/mobile/WPAndroidGlue/WPAndroidGlueCode.java | 3 +++ 1 file changed, 3 insertions(+) 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 0fba0b588f918f..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,6 +107,7 @@ 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); @@ -159,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); } }