Skip to content

Commit

Permalink
Set featured image
Browse files Browse the repository at this point in the history
This commit introduces code that sets a featured image when the "set as featured" button is clicked from an image block. A function within "EditPostSettingsFragment" is currently utilised for this purpose, though this is likely not the optimal approach.
  • Loading branch information
Siobhan committed Mar 5, 2021
1 parent 6558a65 commit b251e4b
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -2553,6 +2554,7 @@ private void setFeaturedImageId(final long mediaId, final boolean imagePicked) {
}
}


/**
* Sets the content of the reblogged post
*/
Expand Down Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,16 @@ 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;
protected String mBlogSettingMaxImageWidth;
protected ImageLoader mImageLoader;
protected boolean mDebugModeEnabled;

// protected EditPostSettingsFragment mEditPostSettingsFragment;

protected HashMap<String, String> mCustomHttpHeaders;

@Override
Expand Down Expand Up @@ -179,6 +182,7 @@ public interface EditorFragmentListener extends DialogVisibilityProvider {
void onEditorFragmentInitialized();
void onEditorFragmentContentReady(ArrayList<Object> unsupportedBlocks, boolean replaceBlockActionWaiting);
void onAddMediaClicked();
void updateFeaturedImage(long mediaId, boolean imagePicked);
void onAddMediaImageClicked(boolean allowMultipleSelection);
void onAddMediaVideoClicked(boolean allowMultipleSelection);
void onAddLibraryMediaClicked(boolean allowMultipleSelection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public boolean hasReceivedAnyContent() {

public void attachToContainer(ViewGroup viewGroup, OnMediaLibraryButtonListener onMediaLibraryButtonListener,
OnReattachMediaUploadQueryListener onReattachQueryListener,
// OnSetFeaturedImageListener onSetFeaturedImageListener,
OnReattachMediaSavingQueryListener onStorySavingReattachQueryListener,
OnEditorMountListener onEditorMountListener,
OnEditorAutosaveListener onEditorAutosaveListener,
Expand All @@ -78,6 +79,7 @@ public void attachToContainer(ViewGroup viewGroup, OnMediaLibraryButtonListener
onMediaLibraryButtonListener,
onReattachQueryListener,
onStorySavingReattachQueryListener,
// onSetFeaturedImageListener,
onEditorMountListener,
onEditorAutosaveListener,
onAuthHeaderRequestedListener,
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -287,6 +289,7 @@ public void onCancelUploadForMediaDueToDeletedBlock(int mediaId) {
@Override
public void onSetFeaturedImageButtonClicked(int mediaId) {
showFeaturedImageConfirmationDialog(mediaId);
//mEditorFragmentListener.setFeaturedImageId(mediaId, true);
}

@Override
Expand Down Expand Up @@ -429,7 +432,7 @@ public void gutenbergDidSendButtonPressedAction(String buttonType) {
showCancelMediaCollectionSaveDialog(mediaFiles);
}

@Override public void onMediaFilesBlockReplaceSync(ArrayList<Object> mediaFiles, String blockId) {
/* @Override public void onMediaFilesBlockReplaceSync(ArrayList<Object> 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
Expand Down Expand Up @@ -461,7 +464,7 @@ public void gutenbergDidSendButtonPressedAction(String buttonType) {
// other than the one that was actually edited. Just skip it.
}
}
}
} */
},
new OnFocalPointPickerTooltipShownEventListener() {
@Override
Expand Down Expand Up @@ -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<Object> mediaFiles) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b251e4b

Please sign in to comment.