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 1ed3698fe56c..c451fc57379b 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 @@ -12,6 +12,7 @@ import android.os.Handler; import android.preference.PreferenceManager; import android.text.TextUtils; +import android.util.Log; import android.view.DragEvent; import android.view.Menu; import android.view.MenuInflater; @@ -2553,6 +2554,7 @@ private void setFeaturedImageId(final long mediaId, final boolean imagePicked) { } } + /** * Sets the content of the reblogged post */ @@ -2974,6 +2976,11 @@ public void onEditPostPublishedSettingsClick() { * EditorFragmentListener methods */ + @Override + public void updateFeaturedImage(final long mediaId, final boolean imagePicked) { + mEditPostSettingsFragment.updateFeaturedImage(mediaId, imagePicked); + } + @Override public void onAddMediaClicked() { if (mEditorPhotoPicker.isPhotoPickerShowing()) { 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 a230aa7ddbd7..21cf9b3bafc0 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 @@ -91,6 +91,7 @@ public static MediaType fromString(String value) { protected EditorFragmentListener mEditorFragmentListener; protected EditorDragAndDropListener mEditorDragAndDropListener; protected EditorImagePreviewListener mEditorImagePreviewListener; + // protected EditPostSettingsFragment mEditPostSettingsFragment; protected EditorEditMediaListener mEditorEditMediaListener; protected boolean mFeaturedImageSupported; protected long mFeaturedImageId; @@ -98,6 +99,8 @@ public static MediaType fromString(String value) { protected ImageLoader mImageLoader; protected boolean mDebugModeEnabled; + // protected EditPostSettingsFragment mEditPostSettingsFragment; + protected HashMap mCustomHttpHeaders; @Override @@ -179,6 +182,7 @@ public interface EditorFragmentListener extends DialogVisibilityProvider { void onEditorFragmentInitialized(); void onEditorFragmentContentReady(ArrayList unsupportedBlocks, boolean replaceBlockActionWaiting); void onAddMediaClicked(); + void updateFeaturedImage(long mediaId, boolean imagePicked); void onAddMediaImageClicked(boolean allowMultipleSelection); void onAddMediaVideoClicked(boolean allowMultipleSelection); void onAddLibraryMediaClicked(boolean allowMultipleSelection); diff --git a/libs/editor/WordPressEditor/src/main/java/org/wordpress/android/editor/gutenberg/GutenbergContainerFragment.java b/libs/editor/WordPressEditor/src/main/java/org/wordpress/android/editor/gutenberg/GutenbergContainerFragment.java index e23ebaf32602..049602b29740 100644 --- a/libs/editor/WordPressEditor/src/main/java/org/wordpress/android/editor/gutenberg/GutenbergContainerFragment.java +++ b/libs/editor/WordPressEditor/src/main/java/org/wordpress/android/editor/gutenberg/GutenbergContainerFragment.java @@ -56,6 +56,7 @@ public boolean hasReceivedAnyContent() { public void attachToContainer(ViewGroup viewGroup, OnMediaLibraryButtonListener onMediaLibraryButtonListener, OnReattachMediaUploadQueryListener onReattachQueryListener, + // OnSetFeaturedImageListener onSetFeaturedImageListener, OnReattachMediaSavingQueryListener onStorySavingReattachQueryListener, OnEditorMountListener onEditorMountListener, OnEditorAutosaveListener onEditorAutosaveListener, @@ -78,6 +79,7 @@ public void attachToContainer(ViewGroup viewGroup, OnMediaLibraryButtonListener onMediaLibraryButtonListener, onReattachQueryListener, onStorySavingReattachQueryListener, + // onSetFeaturedImageListener, onEditorMountListener, onEditorAutosaveListener, onAuthHeaderRequestedListener, @@ -257,7 +259,11 @@ public void onStorySaveResult(final String storyFirstMediaId, final boolean succ mWPAndroidGlueCode.mediaCollectionFinalSaveResult(storyFirstMediaId, success); } - public void onMediaModelCreatedForFile(String oldId, String newId, String oldUrl) { + public void onMediaModelCreatedForFile(String oldId, String newId, final String oldUrl) { mWPAndroidGlueCode.mediaIdChanged(oldId, newId, oldUrl); } + + public void featuredImageIdNotifier(int mediaId) { + mWPAndroidGlueCode.featuredImageIdNotifier(mediaId); + } } 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 e82049599519..4ac6e7d12715 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 @@ -23,6 +23,7 @@ import androidx.annotation.Nullable; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.app.AlertDialog.Builder; import androidx.appcompat.app.AppCompatActivity; import androidx.core.util.Consumer; import androidx.fragment.app.FragmentActivity; @@ -220,6 +221,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa @Override public void onMediaLibraryImageButtonClicked(boolean allowMultipleSelection) { mEditorFragmentListener.onTrackableEvent(TrackableEvent.MEDIA_BUTTON_TAPPED); mEditorFragmentListener.onAddMediaImageClicked(allowMultipleSelection); + // private EditPostSettingsFragment mEditPostSettingsFragment; } @Override @@ -287,6 +289,7 @@ public void onCancelUploadForMediaDueToDeletedBlock(int mediaId) { @Override public void onSetFeaturedImageButtonClicked(int mediaId) { showFeaturedImageConfirmationDialog(mediaId); + //mEditorFragmentListener.setFeaturedImageId(mediaId, true); } @Override @@ -429,7 +432,7 @@ public void gutenbergDidSendButtonPressedAction(String buttonType) { showCancelMediaCollectionSaveDialog(mediaFiles); } - @Override public void onMediaFilesBlockReplaceSync(ArrayList mediaFiles, String blockId) { + /* @Override public void onMediaFilesBlockReplaceSync(ArrayList mediaFiles, String blockId) { if (mStoryBlockReplacedSignalWait) { // in case we were expecting a fresh block replacement sync signal, let the fragment // listener know so it can process all of the pending block save / update / upload events @@ -461,7 +464,7 @@ public void gutenbergDidSendButtonPressedAction(String buttonType) { // other than the one that was actually edited. Just skip it. } } - } + } */ }, new OnFocalPointPickerTooltipShownEventListener() { @Override @@ -801,10 +804,31 @@ public void onClick(DialogInterface dialog, int id) { } private void showFeaturedImageConfirmationDialog(final int mediaId) { - AlertDialog.Builder builder = new MaterialAlertDialogBuilder(getActivity()); - builder.setTitle("Hello World" + mediaId); - AlertDialog dialog = builder.create(); - dialog.show(); + + if (mFeaturedImageId != mediaId) { + Builder builder = new MaterialAlertDialogBuilder(getActivity()); + builder.setTitle("Replace current?"); + builder.setMessage("You already have a featured image set. Do you want to replace it?"); + builder.setPositiveButton("Replace", + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + mEditorFragmentListener.updateFeaturedImage(mediaId, true); + setFeaturedImageId(mediaId); + dialog.dismiss(); + ToastUtils.showToast(getActivity(), "Set as Featured Image").show(); + getGutenbergContainerFragment().featuredImageIdNotifier(mediaId); + } + }); + + builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + dialog.dismiss(); + } + }); + + AlertDialog dialog = builder.create(); + dialog.show(); + } } private void showCancelMediaCollectionUploadDialog(ArrayList mediaFiles) { @@ -1345,6 +1369,10 @@ public void onEditorThemeUpdated(Bundle editorTheme) { getGutenbergContainerFragment().onMediaModelCreatedForFile(oldId, newId, oldUrl); } + /* public void onFeaturedImageSet(int mediaId) { + getGutenbergContainerFragment().featuredImageIdNotifier(mediaId); + } */ + @Override public void onStoryMediaSavedToRemote(String localId, String remoteId, String oldUrl, String newUrl) { mUploadingMediaProgressMax.remove(localId); // this method may end up being called twice if the original FluxC OnMediaUploaded event was correctly caught