Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Gutenberg - honor allowMultipleSelection js flag in StockMediaPicker #11912

Merged
merged 3 commits into from
May 14, 2020
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
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
14.9
-----
* Fix issue with Preview post not working after switching to classic editor from inside the post
* [**] Block editor: Fix bug in Free Photo Library which allowed selecting multiple images but only inserted one

14.8
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class RequestCodes {
public static final int PHOTO_PICKER = 1200;
public static final int STOCK_MEDIA_PICKER_MULTI_SELECT = 1201;
public static final int STOCK_MEDIA_PICKER_SINGLE_SELECT = 1202;
public static final int STOCK_MEDIA_PICKER_SINGLE_SELECT_FOR_GUTENBERG_BLOCK = 1203;
public static final int SHOW_LOGIN_EPILOGUE_AND_RETURN = 1300;
public static final int SHOW_SIGNUP_EPILOGUE_AND_RETURN = 1301;
public static final int SMART_LOCK_SAVE = 1400;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -970,8 +970,10 @@ public void onPhotoPickerIconClicked(@NonNull PhotoPickerIcon icon, boolean allo
ActivityLauncher.viewMediaPickerForResult(this, mSite, MediaBrowserType.EDITOR_PICKER);
break;
case STOCK_MEDIA:
ActivityLauncher.showStockMediaPickerForResult(
this, mSite, RequestCodes.STOCK_MEDIA_PICKER_MULTI_SELECT);
final int requestCode = allowMultipleSelection
? RequestCodes.STOCK_MEDIA_PICKER_MULTI_SELECT
: RequestCodes.STOCK_MEDIA_PICKER_SINGLE_SELECT_FOR_GUTENBERG_BLOCK;
ActivityLauncher.showStockMediaPickerForResult(this, mSite, requestCode);
break;
case GIF:
ActivityLauncher.showGifPickerForResult(this, mSite, RequestCodes.GIF_PICKER);
Expand Down Expand Up @@ -2291,6 +2293,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
case RequestCodes.VIDEO_LIBRARY:
case RequestCodes.TAKE_VIDEO:
case RequestCodes.STOCK_MEDIA_PICKER_MULTI_SELECT:
case RequestCodes.STOCK_MEDIA_PICKER_SINGLE_SELECT_FOR_GUTENBERG_BLOCK:
mEditorFragment.mediaSelectionCancelled();
return;
default:
Expand Down Expand Up @@ -2327,6 +2330,14 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
mEditorMedia.addFreshlyTakenVideoToEditor();
}
break;
case RequestCodes.STOCK_MEDIA_PICKER_SINGLE_SELECT_FOR_GUTENBERG_BLOCK:
if (data.hasExtra(PhotoPickerActivity.EXTRA_MEDIA_ID)) {
// pass array with single item
long[] mediaIds = {data.getLongExtra(PhotoPickerActivity.EXTRA_MEDIA_ID, 0)};
mEditorMedia
.addExistingMediaToEditorAsync(AddExistingMediaSource.STOCK_PHOTO_LIBRARY, mediaIds);
}
break;
case RequestCodes.MEDIA_LIBRARY:
case RequestCodes.PICTURE_LIBRARY:
mEditorMedia.advertiseImageOptimisationAndAddMedia(WPMediaUtils.retrieveMediaUris(data));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
}
});

if (enableMultiselect()) {
if (isMultiSelectEnabled()) {
mTextPreview.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
previewSelection();
Expand Down Expand Up @@ -267,7 +267,7 @@ public boolean onOptionsItemSelected(final MenuItem item) {
return super.onOptionsItemSelected(item);
}

private boolean enableMultiselect() {
private boolean isMultiSelectEnabled() {
return mRequestCode == RequestCodes.STOCK_MEDIA_PICKER_MULTI_SELECT;
}

Expand Down Expand Up @@ -444,7 +444,7 @@ public void onStockMediaUploaded(OnStockMediaUploaded event) {
}

Intent intent = new Intent();
if (enableMultiselect()) {
if (isMultiSelectEnabled()) {
long[] idArray = new long[count];
for (int i = 0; i < count; i++) {
idArray[i] = event.mediaList.get(i).getMediaId();
Expand Down Expand Up @@ -501,7 +501,7 @@ private void showSelectionBar(final boolean show) {
private void notifySelectionCountChanged() {
int numSelected = mAdapter.getSelectionCount();
if (numSelected > 0) {
if (enableMultiselect()) {
if (isMultiSelectEnabled()) {
String labelAdd = String.format(getString(R.string.add_count), numSelected);
mTextAdd.setText(labelAdd);

Expand Down Expand Up @@ -601,7 +601,7 @@ public void onBindViewHolder(@NonNull StockViewHolder holder, int position) {

boolean isSelected = isItemSelected(position);
holder.mSelectionCountTextView.setSelected(isSelected);
if (enableMultiselect()) {
if (isMultiSelectEnabled()) {
if (isSelected) {
int count = mSelectedItems.indexOf(position) + 1;
String label = Integer.toString(count);
Expand All @@ -611,7 +611,7 @@ public void onBindViewHolder(@NonNull StockViewHolder holder, int position) {
}
} else {
holder.mSelectionCountTextView.setVisibility(
isSelected || enableMultiselect() ? View.VISIBLE : View.GONE);
isSelected || isMultiSelectEnabled() ? View.VISIBLE : View.GONE);
}

float scale = isSelected ? SCALE_SELECTED : SCALE_NORMAL;
Expand Down Expand Up @@ -654,7 +654,7 @@ void setItemSelected(StockViewHolder holder, int position, boolean selected) {
if (!isValidPosition(position)) return;

// if this is single select, make sure to deselect any existing selection
if (selected && !enableMultiselect() && !mSelectedItems.isEmpty()) {
if (selected && !isMultiSelectEnabled() && !mSelectedItems.isEmpty()) {
int prevPosition = mSelectedItems.get(0);
StockViewHolder prevHolder = (StockViewHolder) mRecycler.findViewHolderForAdapterPosition(prevPosition);
if (prevHolder != null) {
Expand All @@ -676,7 +676,7 @@ void setItemSelected(StockViewHolder holder, int position, boolean selected) {
}

// show and animate the count bubble
if (enableMultiselect()) {
if (isMultiSelectEnabled()) {
if (selected) {
String label = Integer.toString(mSelectedItems.indexOf(position) + 1);
holder.mSelectionCountTextView.setText(label);
Expand Down