From 3060e8beb7c464cf408132e170da3d55cdaffa02 Mon Sep 17 00:00:00 2001 From: Matthew Kevins Date: Thu, 14 May 2020 15:31:15 +1000 Subject: [PATCH 1/3] Refactor method name for clarity --- .../ui/stockmedia/StockMediaPickerActivity.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stockmedia/StockMediaPickerActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/stockmedia/StockMediaPickerActivity.java index 6d4fc88b1395..802d2464624d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stockmedia/StockMediaPickerActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/stockmedia/StockMediaPickerActivity.java @@ -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(); @@ -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; } @@ -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(); @@ -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); @@ -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); @@ -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; @@ -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) { @@ -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); From d8f3802c7c1d9af49fda5201530aaccb85beb0ae Mon Sep 17 00:00:00 2001 From: Matthew Kevins Date: Thu, 14 May 2020 15:31:31 +1000 Subject: [PATCH 2/3] Add request code for gutenberg free photos single image picker --- .../org/wordpress/android/ui/RequestCodes.java | 1 + .../android/ui/posts/EditPostActivity.java | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/RequestCodes.java b/WordPress/src/main/java/org/wordpress/android/ui/RequestCodes.java index 664b21b57bdf..d76265203a34 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/RequestCodes.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/RequestCodes.java @@ -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; 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 f9ef14734bf9..7fd1637d5541 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 @@ -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); @@ -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: @@ -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)); From b24b7e4da992e0b5e2f1348d26ad2b5b5e172ddb Mon Sep 17 00:00:00 2001 From: Matthew Kevins Date: Thu, 14 May 2020 17:28:10 +1000 Subject: [PATCH 3/3] Add release note --- RELEASE-NOTES.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index 7e339720705d..0c92c9074e35 100644 --- a/RELEASE-NOTES.txt +++ b/RELEASE-NOTES.txt @@ -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 -----