diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.java index 40ce09bbbaf0..c36d826ff8ee 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.java @@ -2720,6 +2720,13 @@ postId, getSite(), mediaUri, mOnGetMentionResult = null; } break; + case RequestCodes.FILE_LIBRARY: + uris = WPMediaUtils.retrieveMediaUris(data); + mAnalyticsTrackerWrapper.track(Stat.EDITOR_ADDED_FILE_VIA_LIBRARY); + for (Uri item : uris) { + mEditorMedia.addNewMediaToEditorAsync(item, false); + } + break; } } @@ -2967,6 +2974,11 @@ public void onAddGifClicked(boolean allowMultipleSelection) { onPhotoPickerIconClicked(PhotoPickerIcon.GIF, allowMultipleSelection); } + @Override + public void onAddFileClicked(boolean allowMultipleSelection) { + WPMediaUtils.launchFileLibrary(this, allowMultipleSelection); + } + @Override public void onPerformFetch(String path, Consumer onResult, Consumer onError) { if (mSite != null) { diff --git a/libs/analytics/WordPressAnalytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java b/libs/analytics/WordPressAnalytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java index c509b7429660..4f66bebe668f 100644 --- a/libs/analytics/WordPressAnalytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java +++ b/libs/analytics/WordPressAnalytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java @@ -139,6 +139,7 @@ public enum Stat { EDITOR_ADDED_PHOTO_VIA_WP_MEDIA_LIBRARY, EDITOR_ADDED_VIDEO_VIA_WP_MEDIA_LIBRARY, EDITOR_ADDED_PHOTO_VIA_STOCK_MEDIA_LIBRARY, + EDITOR_ADDED_FILE_VIA_LIBRARY, MEDIA_PHOTO_OPTIMIZED, MEDIA_PHOTO_OPTIMIZE_ERROR, MEDIA_VIDEO_OPTIMIZED, diff --git a/libs/analytics/WordPressAnalytics/src/main/java/org/wordpress/android/analytics/AnalyticsTrackerNosara.java b/libs/analytics/WordPressAnalytics/src/main/java/org/wordpress/android/analytics/AnalyticsTrackerNosara.java index ed10fbfead68..76e52f04e463 100644 --- a/libs/analytics/WordPressAnalytics/src/main/java/org/wordpress/android/analytics/AnalyticsTrackerNosara.java +++ b/libs/analytics/WordPressAnalytics/src/main/java/org/wordpress/android/analytics/AnalyticsTrackerNosara.java @@ -793,6 +793,8 @@ public static String getEventNameForStat(AnalyticsTracker.Stat stat) { return "editor_video_added"; case EDITOR_ADDED_PHOTO_VIA_STOCK_MEDIA_LIBRARY: return "editor_photo_added"; + case EDITOR_ADDED_FILE_VIA_LIBRARY: + return "editor_file_added"; case MEDIA_PHOTO_OPTIMIZED: return "media_photo_optimized"; case MEDIA_PHOTO_OPTIMIZE_ERROR: diff --git a/libs/editor/WordPressEditor/src/main/java/org/wordpress/android/editor/EditorFragmentAbstract.java b/libs/editor/WordPressEditor/src/main/java/org/wordpress/android/editor/EditorFragmentAbstract.java index c3ca0429d248..6f270548fcdc 100644 --- a/libs/editor/WordPressEditor/src/main/java/org/wordpress/android/editor/EditorFragmentAbstract.java +++ b/libs/editor/WordPressEditor/src/main/java/org/wordpress/android/editor/EditorFragmentAbstract.java @@ -199,6 +199,7 @@ public interface EditorFragmentListener extends DialogVisibilityProvider { void onHtmlModeToggledInToolbar(); void onAddStockMediaClicked(boolean allowMultipleSelection); void onAddGifClicked(boolean allowMultipleSelection); + void onAddFileClicked(boolean allowMultipleSelection); void onPerformFetch(String path, Consumer onResult, Consumer onError); void onGutenbergEditorSessionTemplateApplyTracked(String template); void onGutenbergEditorSessionTemplatePreviewTracked(String template); diff --git a/libs/editor/WordPressEditor/src/main/java/org/wordpress/android/editor/gutenberg/GutenbergEditorFragment.java b/libs/editor/WordPressEditor/src/main/java/org/wordpress/android/editor/gutenberg/GutenbergEditorFragment.java index b61743db4930..6344fe333ad2 100644 --- a/libs/editor/WordPressEditor/src/main/java/org/wordpress/android/editor/gutenberg/GutenbergEditorFragment.java +++ b/libs/editor/WordPressEditor/src/main/java/org/wordpress/android/editor/gutenberg/GutenbergEditorFragment.java @@ -97,6 +97,7 @@ public class GutenbergEditorFragment extends EditorFragmentAbstract implements private static final int CAPTURE_PHOTO_PERMISSION_REQUEST_CODE = 101; private static final int CAPTURE_VIDEO_PERMISSION_REQUEST_CODE = 102; + private static final String MEDIA_SOURCE_FILE = "MEDIA_SOURCE_FILE"; private static final String MEDIA_SOURCE_STOCK_MEDIA = "MEDIA_SOURCE_STOCK_MEDIA"; private static final String GIF_MEDIA = "GIF_MEDIA"; @@ -263,12 +264,27 @@ public ArrayList onGetOtherMediaImageOptions() { return otherMediaImageOptions; } + @Override + public ArrayList onGetOtherMediaFileOptions() { + ArrayList otherMediaFileOptions = initOtherMediaFileOptions(); + return otherMediaFileOptions; + } + @Override public void onOtherMediaButtonClicked(String mediaSource, boolean allowMultipleSelection) { - if (mediaSource.equals(MEDIA_SOURCE_STOCK_MEDIA)) { - mEditorFragmentListener.onAddStockMediaClicked(allowMultipleSelection); - } else if (mediaSource.equals(GIF_MEDIA)) { - mEditorFragmentListener.onAddGifClicked(allowMultipleSelection); + switch (mediaSource) { + case MEDIA_SOURCE_STOCK_MEDIA: + mEditorFragmentListener.onAddStockMediaClicked(allowMultipleSelection); + break; + case GIF_MEDIA: + mEditorFragmentListener.onAddGifClicked(allowMultipleSelection); + break; + case MEDIA_SOURCE_FILE: + mEditorFragmentListener.onAddFileClicked(allowMultipleSelection); + break; + default: + AppLog.e(T.EDITOR, + "Unsupported media source " + mediaSource); } } }, @@ -503,6 +519,26 @@ private ArrayList initOtherMediaImageOptions() { return otherMediaOptions; } + private ArrayList initOtherMediaFileOptions() { + ArrayList otherMediaOptions = new ArrayList<>(); + + FragmentActivity activity = getActivity(); + if (activity == null) { + AppLog.e(T.EDITOR, + "Failed to initialize other media options because the activity is null"); + return otherMediaOptions; + } + + String packageName = activity.getApplication().getPackageName(); + + int chooseFileResourceId = + getResources().getIdentifier("photo_picker_choose_file", "string", packageName); + + otherMediaOptions.add(new MediaOption(MEDIA_SOURCE_FILE, getString(chooseFileResourceId))); + + return otherMediaOptions; + } + @Override public void onResume() { super.onResume(); @@ -1016,7 +1052,8 @@ public void appendMediaFiles(Map mediaList) { rnMediaList.add(createRNMediaUsingMimeType(mediaId, url, mediaEntry.getValue().getMimeType(), - mediaEntry.getValue().getCaption())); + mediaEntry.getValue().getCaption(), + mediaEntry.getValue().getTitle())); } getGutenbergContainerFragment().appendMediaFiles(rnMediaList); diff --git a/libs/gutenberg-mobile b/libs/gutenberg-mobile index 37ce251026f5..24ea2e0f6a4d 160000 --- a/libs/gutenberg-mobile +++ b/libs/gutenberg-mobile @@ -1 +1 @@ -Subproject commit 37ce251026f5332b9ea53f0692104cc377617859 +Subproject commit 24ea2e0f6a4dd1abbd77aea92217c1802c34c449