Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -37,7 +37,6 @@ public class RequestCodes {
public static final int VIDEO_LIBRARY = 2200;
public static final int MEDIA_LIBRARY = 2210;
public static final int FILE_LIBRARY = 2220;
public static final int AUDIO_LIBRARY = 2230;
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 @@ -213,8 +213,6 @@ public void onCreate(Bundle savedInstanceState) {
filter = MediaFilter.FILTER_IMAGES;
} else if (mBrowserType == MediaBrowserType.GUTENBERG_VIDEO_PICKER) {
filter = MediaFilter.FILTER_VIDEOS;
} else if (mBrowserType == MediaBrowserType.GUTENBERG_SINGLE_AUDIO_FILE_PICKER) {
filter = MediaFilter.FILTER_AUDIO;
} else if (savedInstanceState != null) {
filter = (MediaFilter) savedInstanceState.getSerializable(ARG_FILTER);
} else {
Expand Down Expand Up @@ -476,7 +474,6 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
case RequestCodes.PICTURE_LIBRARY:
case RequestCodes.VIDEO_LIBRARY:
case RequestCodes.FILE_LIBRARY:
case RequestCodes.AUDIO_LIBRARY:
if (resultCode == Activity.RESULT_OK && data != null) {
if (mConsolidatedMediaPickerFeatureConfig.isEnabled()) {
if (data.hasExtra(MediaPickerConstants.EXTRA_MEDIA_URIS)) {
Expand Down Expand Up @@ -710,12 +707,11 @@ public void onMediaItemSelected(int localMediaId, boolean isLongClick) {
// show detail view when tapped if we're browsing media, when used as a picker show detail
// when long tapped (to mimic native photo picker)
if (mBrowserType.isBrowser() && !isLongClick
|| mBrowserType.isPicker() && isLongClick) {
|| mBrowserType.isPicker() && isLongClick) {
showMediaSettings(media);
} else if ((mBrowserType.isSingleImagePicker() || mBrowserType.isSingleMediaPicker() || mBrowserType
.isSingleFilePicker() || mBrowserType
.isSingleAudioFilePicker()) && !isLongClick) {
// if we're picking a single media item, we're done
.isSingleFilePicker()) && !isLongClick) {
// if we're picking a single image, we're done
Intent intent = new Intent();
ArrayList<Long> remoteMediaIds = new ArrayList<>();
remoteMediaIds.add(media.getMediaId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public enum MediaBrowserType {
GUTENBERG_SINGLE_MEDIA_PICKER, // select a single image or video to insert into a post
GUTENBERG_MEDIA_PICKER, // select multiple images or videos to insert into a post
GUTENBERG_SINGLE_FILE_PICKER, // select a file to insert into a post
GUTENBERG_SINGLE_AUDIO_FILE_PICKER, // select an audio file to insert into a post
WP_STORIES_MEDIA_PICKER; // select multiple images or videos to insert as Story frames in a Story

public boolean isPicker() {
Expand Down Expand Up @@ -58,7 +57,7 @@ public boolean isVideoPicker() {
}

public boolean isAudioPicker() {
return this == GUTENBERG_SINGLE_FILE_PICKER || this == GUTENBERG_SINGLE_AUDIO_FILE_PICKER;
return this == GUTENBERG_SINGLE_FILE_PICKER;
}

public boolean isDocumentPicker() {
Expand All @@ -72,8 +71,7 @@ public boolean isGutenbergPicker() {
|| this == GUTENBERG_SINGLE_VIDEO_PICKER
|| this == GUTENBERG_SINGLE_MEDIA_PICKER
|| this == GUTENBERG_MEDIA_PICKER
|| this == GUTENBERG_SINGLE_FILE_PICKER
|| this == GUTENBERG_SINGLE_AUDIO_FILE_PICKER;
|| this == GUTENBERG_SINGLE_FILE_PICKER;
}

public boolean isWPStoriesPicker() {
Expand All @@ -84,10 +82,6 @@ public boolean isSingleFilePicker() {
return this == GUTENBERG_SINGLE_FILE_PICKER;
}

public boolean isSingleAudioFilePicker() {
return this == GUTENBERG_SINGLE_AUDIO_FILE_PICKER;
}

public boolean isSingleMediaPicker() {
return this == GUTENBERG_SINGLE_MEDIA_PICKER;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,7 @@ List<MediaModel> getFilteredMedia() {
} else if (mBrowserType.isSingleImagePicker()) {
mediaList = mMediaStore.getSiteImages(mSite);
} else if (mBrowserType.canFilter() || mBrowserType.canOnlyDoInitialFilter() || mBrowserType
.isSingleFilePicker() || mBrowserType
.isSingleAudioFilePicker()) {
.isSingleFilePicker()) {
mediaList = getMediaList();
} else {
List<MediaModel> allMedia = mMediaStore.getAllSiteMedia(mSite);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ class MediaPickerFragment : Fragment() {
PHOTO(ACTION_GET_CONTENT, UiStringRes(R.string.pick_photo), "image/*"),
VIDEO(ACTION_GET_CONTENT, UiStringRes(R.string.pick_video), "video/*"),
PHOTO_OR_VIDEO(ACTION_GET_CONTENT, UiStringRes(R.string.pick_media), "*/*"),
AUDIO(ACTION_GET_CONTENT, UiStringRes(R.string.pick_audio), "*/*"),
MEDIA_FILE(ACTION_OPEN_DOCUMENT, UiStringRes(R.string.pick_file), "*/*");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,10 @@ class MediaPickerViewModel @Inject constructor(
else -> {
val isImagePicker = mediaPickerSetup.allowedTypes.contains(IMAGE)
val isVideoPicker = mediaPickerSetup.allowedTypes.contains(VIDEO)
val isAudioPicker = mediaPickerSetup.allowedTypes.contains(AUDIO)
if (isImagePicker && isVideoPicker) {
UiStringRes(R.string.photo_picker_use_media)
} else if (isVideoPicker) {
UiStringRes(R.string.photo_picker_use_video)
} else if (isAudioPicker) {
UiStringRes(R.string.photo_picker_use_audio)
} else {
UiStringRes(R.string.photo_picker_use_photo)
}
Expand Down Expand Up @@ -518,9 +515,6 @@ class MediaPickerViewModel @Inject constructor(
listOf(IMAGE, VIDEO).containsAll(allowedTypes) -> {
Pair(ChooserContext.PHOTO_OR_VIDEO, MimeTypes().getVideoAndImageTypesOnly())
}
listOf(AUDIO).containsAll(allowedTypes) -> {
Pair(ChooserContext.AUDIO, MimeTypes().getAudioTypesOnly())
}
else -> {
Pair(ChooserContext.MEDIA_FILE, MimeTypes().getAllTypes())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.wordpress.android.ui.photopicker

import android.app.Activity
import android.content.Intent
import androidx.annotation.StringRes
import androidx.fragment.app.Fragment
import org.wordpress.android.R
import org.wordpress.android.R.string
Expand Down Expand Up @@ -185,33 +184,8 @@ class MediaPickerLauncher @Inject constructor(
}

fun showFilePicker(activity: Activity, canMultiselect: Boolean = true) {
showFilePicker(
activity,
canMultiselect,
mutableSetOf(IMAGE, VIDEO, AUDIO, DOCUMENT),
RequestCodes.FILE_LIBRARY,
string.photo_picker_choose_file
)
}

fun showAudioFilePicker(activity: Activity, canMultiselect: Boolean = false) {
showFilePicker(
activity,
canMultiselect,
mutableSetOf(AUDIO),
RequestCodes.AUDIO_LIBRARY,
string.photo_picker_choose_audio
)
}

private fun showFilePicker(
activity: Activity,
canMultiselect: Boolean = false,
allowedTypes: Set<MediaType>,
requestCode: Int,
@StringRes title: Int
) {
if (consolidatedMediaPickerFeatureConfig.isEnabled()) {
val allowedTypes = mutableSetOf(IMAGE, VIDEO, AUDIO, DOCUMENT)
val mediaPickerSetup = MediaPickerSetup(
primaryDataSource = DEVICE,
availableDataSources = setOf(),
Expand All @@ -223,18 +197,18 @@ class MediaPickerLauncher @Inject constructor(
editingEnabled = true,
queueResults = false,
defaultSearchView = false,
title = title
title = R.string.photo_picker_choose_file
)
val intent = MediaPickerActivity.buildIntent(
activity,
mediaPickerSetup
)
activity.startActivityForResult(
intent,
requestCode
RequestCodes.FILE_LIBRARY
)
} else {
WPMediaUtils.launchFileLibrary(activity, canMultiselect, requestCode)
WPMediaUtils.launchFileLibrary(activity, canMultiselect)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2753,7 +2753,6 @@ postId, getSite(), mediaUri,
}
break;
case RequestCodes.FILE_LIBRARY:
case RequestCodes.AUDIO_LIBRARY:
if (mConsolidatedMediaPickerFeatureConfig.isEnabled()) {
if (data.hasExtra(MediaPickerConstants.EXTRA_MEDIA_URIS)) {
List<Uri> uriResults = convertStringArrayIntoUrisList(
Expand All @@ -2765,16 +2764,7 @@ postId, getSite(), mediaUri,
}
} else {
uris = WPMediaUtils.retrieveMediaUris(data);

switch (requestCode) {
case RequestCodes.FILE_LIBRARY:
mAnalyticsTrackerWrapper.track(Stat.EDITOR_ADDED_FILE_VIA_LIBRARY);
break;
case RequestCodes.AUDIO_LIBRARY:
mAnalyticsTrackerWrapper.track(Stat.EDITOR_ADDED_AUDIO_FILE_VIA_LIBRARY);
break;
}

mAnalyticsTrackerWrapper.track(Stat.EDITOR_ADDED_FILE_VIA_LIBRARY);
for (Uri item : uris) {
mEditorMedia.addNewMediaToEditorAsync(item, false);
}
Expand Down Expand Up @@ -2985,11 +2975,6 @@ public void onAddLibraryMediaClicked(boolean allowMultipleSelection) {
.viewWPMediaLibraryPickerForResult(this, mSite, MediaBrowserType.GUTENBERG_SINGLE_FILE_PICKER);
}

@Override public void onAddLibraryAudioFileClicked(boolean allowMultipleSelection) {
mMediaPickerLauncher
.viewWPMediaLibraryPickerForResult(this, mSite, MediaBrowserType.GUTENBERG_SINGLE_AUDIO_FILE_PICKER);
}

@Override
public void onAddPhotoClicked(boolean allowMultipleSelection) {
if (allowMultipleSelection) {
Expand Down Expand Up @@ -3043,10 +3028,6 @@ public void onAddFileClicked(boolean allowMultipleSelection) {
mMediaPickerLauncher.showFilePicker(this, allowMultipleSelection);
}

@Override public void onAddAudioFileClicked(boolean allowMultipleSelection) {
mMediaPickerLauncher.showAudioFilePicker(this, allowMultipleSelection);
}

@Override
public void onPerformFetch(String path, Consumer<String> onResult, Consumer<Bundle> onError) {
if (mSite != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat;
import androidx.core.content.FileProvider;
Expand Down Expand Up @@ -242,15 +241,9 @@ public static void launchMediaLibrary(Activity activity, boolean multiSelect) {
RequestCodes.MEDIA_LIBRARY);
}

public static void launchFileLibrary(Activity activity, boolean multiSelect, int requestCode) {
switch (requestCode) {
case RequestCodes.FILE_LIBRARY:
activity.startActivityForResult(prepareFileLibraryIntent(activity, multiSelect), requestCode);
break;
case RequestCodes.AUDIO_LIBRARY:
activity.startActivityForResult(prepareAudioLibraryIntent(activity, multiSelect), requestCode);
break;
}
public static void launchFileLibrary(Activity activity, boolean multiSelect) {
activity.startActivityForResult(prepareFileLibraryIntent(activity, multiSelect),
RequestCodes.FILE_LIBRARY);
}

public static void launchChooserWithContext(
Expand All @@ -263,40 +256,34 @@ public static void launchChooserWithContext(
requestCode);
}

private static Intent preparePictureLibraryIntent(Context context, boolean multiSelect) {
return prepareIntent(context, multiSelect, Intent.ACTION_GET_CONTENT, "image/*",
new MimeTypes().getImageTypesOnly(), R.string.pick_photo);
}

private static Intent prepareVideoLibraryIntent(Context context, boolean multiSelect) {
return prepareIntent(context, multiSelect, Intent.ACTION_GET_CONTENT, "video/*",
new MimeTypes().getVideoTypesOnly(), R.string.pick_video);
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("video/*");
intent.putExtra(Intent.EXTRA_MIME_TYPES, new MimeTypes().getVideoTypesOnly());
if (multiSelect) {
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
}
return Intent.createChooser(intent, context.getString(R.string.pick_video));
}

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

private static Intent prepareFileLibraryIntent(Context context, boolean multiSelect) {
return prepareIntent(context, multiSelect, Intent.ACTION_OPEN_DOCUMENT, "*/*",
new MimeTypes().getAllTypes(), R.string.pick_file);
}

private static Intent prepareAudioLibraryIntent(Context context, boolean multiSelect) {
return prepareIntent(context, multiSelect, Intent.ACTION_GET_CONTENT, "*/*",
new MimeTypes().getAudioTypesOnly(), R.string.pick_audio);
}

private static Intent prepareIntent(Context context, boolean multiSelect, String action, String intentType,
String[] mimeTypes, @StringRes int title) {
Intent intent = new Intent(action);
intent.setType(intentType);
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.setType("*/*");
intent.putExtra(Intent.EXTRA_MIME_TYPES, new MimeTypes().getAllTypes());
if (multiSelect) {
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
}
return Intent.createChooser(intent, context.getString(title));
return Intent.createChooser(intent, context.getString(R.string.pick_file));
}

private static Intent prepareChooserIntent(
Expand Down Expand Up @@ -324,10 +311,19 @@ private static Intent prepareVideoCameraIntent() {

public static void launchPictureLibrary(Activity activity, boolean multiSelect) {
activity.startActivityForResult(
preparePictureLibraryIntent(activity, multiSelect),
preparePictureLibraryIntent(activity.getString(R.string.pick_photo), multiSelect),
RequestCodes.PICTURE_LIBRARY);
}

private static Intent preparePictureLibraryIntent(String title, boolean multiSelect) {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_MIME_TYPES, new MimeTypes().getImageTypesOnly());
if (multiSelect) {
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
}
return Intent.createChooser(intent, title);
}

private static Intent prepareGalleryIntent(String title) {
Intent intent = new Intent(Intent.ACTION_PICK);
Expand Down
3 changes: 0 additions & 3 deletions WordPress/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@
<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_audio">Select audio</string>
<string name="pick_media">Add image or video</string>
<string name="pick_file">Add file</string>
<string name="capture_or_pick_photo">Capture or select photo</string>
Expand Down Expand Up @@ -2447,7 +2446,6 @@
<string name="photo_picker_choose_photo">Choose photo from device</string>
<string name="photo_picker_choose_video">Choose video from device</string>
<string name="photo_picker_choose_file">Choose from device</string>
<string name="photo_picker_choose_audio">Choose audio from device</string>
<string name="photo_picker_capture_photo">Take photo</string>
<string name="photo_picker_capture_video">Take video</string>
<string name="photo_picker_stock_media">Choose from Free Photo Library</string>
Expand All @@ -2458,7 +2456,6 @@
<string name="photo_picker_soft_ask_permissions_denied">%1$s was denied access to your photos. To fix this, edit your permissions and turn on %2$s.</string>
<string name="photo_picker_use_photo">Use this photo</string>
<string name="photo_picker_use_video">Use this video</string>
<string name="photo_picker_use_audio">Use this audio</string>
<string name="photo_picker_use_media">Use this media</string>
<string name="photo_picker_use_gif">Use this GIF</string>
<string name="photo_picker_image_thumbnail_content_description">Image Thumbnail</string>
Expand Down
Loading