Skip to content
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
85774dc
Update strings.xml with text to be used
SiobhyB Apr 21, 2021
4190066
Add OnSetFeaturedImageListener()
SiobhyB Apr 21, 2021
86e6bb0
Add onSetFeaturedImageButtonClicked() function
SiobhyB Apr 21, 2021
51be414
Add updateFeaturedImage() function
SiobhyB Apr 21, 2021
4ab70b2
Add setFeaturedImage() and removeFeaturedImage() functions
SiobhyB Apr 21, 2021
0dd7399
Create dialog in showFeaturedImageConfirmationDialog()
SiobhyB Apr 21, 2021
29d2d0b
Send a notice depending on whether a featured image is set or removed
SiobhyB Apr 21, 2021
7ee5029
Update reference to latest Gutenberg Mobile commit
SiobhyB Apr 21, 2021
0f54607
added an update featured image use case.
jd-alexander Apr 23, 2021
9d72f88
Created mechanisms to track when the gb featured image is picked
jd-alexander Apr 23, 2021
d3b8972
Integrated the new use case and approach to EditPost and Post Settings
jd-alexander Apr 23, 2021
ce3785e
Update remaining references to "IMAGE_PICKED" to "IMAGE_PICKED_POST_S…
SiobhyB Apr 27, 2021
c1278d6
Remove unused imports from EditPostSettingsFragment.java
SiobhyB Apr 27, 2021
dfc7be8
Merge branch 'develop' into gb/1011-set-featured-button
SiobhyB Apr 27, 2021
08efc40
Remove removeFeaturedImage() function and consolidate into a single s…
SiobhyB Apr 27, 2021
655bb60
Bump Gutenberg Mobile
SiobhyB Apr 27, 2021
cffaf48
Merge branch 'develop' into gb/1011-set-featured-button
SiobhyB May 11, 2021
2e5b213
Refactor logic for around showFeaturedImageConfirmationDialog()
SiobhyB May 11, 2021
71f8f36
Update build.gradle with latest Gutenberg Mobile reference
SiobhyB May 12, 2021
34b78ce
Update build.gradle to reference latest commit from Gutenberg Mobile
SiobhyB May 12, 2021
6ba7938
Merge branch 'develop' into gb/1011-set-featured-button
SiobhyB May 12, 2021
e0b301d
Merge branch 'develop' into gb/1011-set-featured-button
SiobhyB May 12, 2021
74323e9
Merge branch 'develop' into gb/1011-set-featured-button
SiobhyB May 12, 2021
754688a
Merge branch 'develop' into gb/1011-set-featured-button
SiobhyB May 12, 2021
3ccdc1d
Merge branch 'develop' into gb/1011-set-featured-button
SiobhyB May 16, 2021
f4358c4
Update reference to latest Gutenberg Mobile commit
SiobhyB May 16, 2021
6ba9fc2
Merge branch 'develop' into gb/1011-set-featured-button
SiobhyB May 16, 2021
d6d26ec
Merge branch 'gb/1011-set-featured-button' of github.com:wordpress-mo…
SiobhyB May 16, 2021
621ce38
Update reference to latest Gutenberg Mobile commit
SiobhyB May 16, 2021
57c3059
Bump Gutenberg Mobile reference
SiobhyB May 18, 2021
1187bc1
Updated gutenberg-mobile ref.
jd-alexander May 19, 2021
610348e
added inject annotation to the constructor of the use case.
jd-alexander May 19, 2021
0cfaf4f
Updated gutenberg-mobile ref.
jd-alexander May 20, 2021
617c5e2
removed comment about disabling Audio block since it is now on all sites
jd-alexander May 20, 2021
672fd07
Merge branch 'gb/1011-set-featured-button' into gb/1011-set-featured-…
jd-alexander May 20, 2021
70dff2c
formatted the use case.
jd-alexander May 20, 2021
d1e7eda
sync stories submodule.
jd-alexander May 20, 2021
fa76582
Create GutenbergDialogFragment.kt using BasicDialogFragment.kt as a t…
SiobhyB May 20, 2021
41c25e0
Add mediaId to GutenbergDialogFragment's constructor
SiobhyB May 20, 2021
d772cbf
Edit "onNegativeClicked" and "onPositiveClicked" so that interface ca…
SiobhyB May 20, 2021
193a41b
Implement BasicDialogPositiveClickInterface and BasicDialogNegativeCl…
SiobhyB May 20, 2021
1a988c7
Refactor showFeaturedImageConfirmationDialog() to use new GutenbergDi…
SiobhyB May 20, 2021
246334e
Add "org.jetbrains.annotations.NotNull" import
SiobhyB May 20, 2021
8bb8837
Fill out "onPositiveClicked" function
SiobhyB May 20, 2021
f35cea5
Fill out onNegativeClicked() function
SiobhyB May 20, 2021
3da4908
Rename instances of "BasicDialog" to "GutenbergDialog"
SiobhyB May 20, 2021
983ff6c
Update reference to Gutenberg Mobile
SiobhyB May 20, 2021
cd572af
Rename "onPositiveClicked" and "onNegativeClicked"
SiobhyB May 20, 2021
f0ff0ba
Merge branch 'develop' into gb/1011-set-featured-button
SiobhyB May 20, 2021
349fe90
Reformat code in GutenbergDialogFragment.kt
SiobhyB May 20, 2021
010505f
Update build.grade with latest reference to Gutenberg Mobile
SiobhyB May 20, 2021
f57eeaf
Save "mFeaturedImageId" in savedInstanceState() and onSaveInstanceSta…
SiobhyB May 20, 2021
3e18f04
Remove redundant comma
SiobhyB May 20, 2021
aa15b61
Add checks to ensure GutenbergDialogPositiveClickInterface and Gutenb…
SiobhyB May 21, 2021
101970c
Don't allow "mPositiveButtonLabel" to be null
SiobhyB May 21, 2021
24a0532
Add "lateinit" modifier to mPositiveButtonLabel
SiobhyB May 21, 2021
f7b81e9
Merge branch 'gb/1011-set-featured-button' into gb/1011-set-featured-…
SiobhyB May 21, 2021
7348943
Add Tracks event that fires when a featured image is removed from the…
SiobhyB May 21, 2021
bf1942f
Refactor null-checks and casting in setPositiveButton() and setNegati…
SiobhyB May 24, 2021
fe93e0b
Refactor if/else statement in onSetFeaturedImageButtonClicked()
SiobhyB May 24, 2021
33fd368
Remove call to sendToJSFeaturedImageId() from within setFeaturedImage()
SiobhyB May 24, 2021
854dd6d
Remove unnecessary semi-colons
SiobhyB May 24, 2021
62caa42
Refine string names
SiobhyB May 24, 2021
b4863bb
Merge branch 'develop' into gb/1011-set-featured-button
SiobhyB May 24, 2021
6fd6fc0
Update string name being passed to showNotice() calls
SiobhyB May 24, 2021
3751c08
Update comment to clarify reasoning behind "setFeaturedImageId" call
SiobhyB May 25, 2021
b4dc825
Reword "featured_image_replace_dialog_title" string
SiobhyB May 25, 2021
9630c29
Introduce "MEDIA_ID_NO_FEATURED_IMAGE_SET" const
SiobhyB May 25, 2021
7924341
Refactor onDismiss() in GutenbergDialogFragment
SiobhyB May 26, 2021
d41cd34
Bump reference to Gutenberg Mobile
SiobhyB May 26, 2021
ccb7292
Merge branch 'develop' into gb/1011-set-featured-button
SiobhyB May 26, 2021
36b6e2e
Remove unecessary comment before 'setFeaturedImageId'
SiobhyB May 26, 2021
1be6762
Fix 'exceeded max line length' ktlint error
SiobhyB May 26, 2021
c917a0c
Remove conditional surrounding 'GutenbergDialogOnDismissByOutsideTouc…
SiobhyB May 26, 2021
c0626bf
Update build.gradle reference to latest commit from Gutenberg Mobile
SiobhyB May 26, 2021
2e07265
Merge branch 'develop' into gutenberg/audio-block-capability
jd-alexander May 27, 2021
58c6d56
Merge branch 'develop' into gutenberg/audio-block-capability
jd-alexander May 27, 2021
96faacf
renamed capability
jd-alexander May 27, 2021
2fa9eb7
sync stories submodule hash.
jd-alexander May 27, 2021
74a2251
updated gutenberg-mobile ref.
jd-alexander May 27, 2021
2a1ef13
Bump Gutenberg Mobile reference
SiobhyB May 27, 2021
105509e
Merge branch 'develop' into gb/1011-set-featured-button
SiobhyB May 30, 2021
a7dabab
Update Gutenberg Mobile ref
fluiddot May 31, 2021
bccaaa9
reformatted use case
jd-alexander Jun 1, 2021
e81d2c2
Merge pull request #14521 from wordpress-mobile/gb/1011-set-featured-…
jd-alexander Jun 1, 2021
92816a9
Update Gutenberg Mobile ref
fluiddot Jun 1, 2021
d52f22c
Merge branch 'develop' into gb/1011-set-featured-button
SiobhyB Jun 1, 2021
fb3ba95
Import constant for use in EditPostActivity
SiobhyB Jun 1, 2021
40310c3
Rename references to 'mediaId' to 'id'
SiobhyB Jun 1, 2021
1eb55fa
Reword dialog's title for clarity.
SiobhyB Jun 2, 2021
c1f6842
Undo title case in notices for consistency
SiobhyB Jun 2, 2021
8c5005f
Update to latest Gutenberg Mobile reference
SiobhyB Jun 2, 2021
db9e884
Merge branch 'develop' into gutenberg/audio-block-capability
fluiddot Jun 3, 2021
54d9cf9
Update Gutenberg Mobile ref
fluiddot Jun 3, 2021
d7953d4
Update Gutenberg Mobile ref
fluiddot Jun 3, 2021
2caa7c0
Bump Gutenberg Mobile reference
SiobhyB Jun 3, 2021
3e2d759
Merge branch 'gutenberg/audio-block-capability' into gb/1011-set-feat…
fluiddot Jun 3, 2021
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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
ext.kotlin_ktx_version = '1.2.0'
ext.wordPressUtilsVersion = '1.40.0'
ext.detektVersion = '1.15.0'
ext.gutenbergMobileVersion = '3116-3407f793fccc2032a53728b879202a2421695297'
ext.gutenbergMobileVersion = '3116-7bf12e282ad0455cf534a2c8d87187589e2b835a'

repositories {
google()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
package org.wordpress.android.editor.gutenberg

import android.app.Dialog
import android.content.Context
import android.content.DialogInterface
import android.os.Bundle
import androidx.appcompat.app.AppCompatDialogFragment
import androidx.fragment.app.Fragment
import com.google.android.material.dialog.MaterialAlertDialogBuilder

class GutenbergDialogFragment() : AppCompatDialogFragment() {
private lateinit var mTag: String
private lateinit var mMessage: CharSequence
private lateinit var mPositiveButtonLabel: CharSequence
private var mTitle: CharSequence? = null
private var mNegativeButtonLabel: CharSequence? = null
private var mMediaId: Int = 0
private var dismissedByPositiveButton = false
private var dismissedByNegativeButton = false

interface GutenbergDialogPositiveClickInterface {
fun onGutenbergDialogPositiveClicked(instanceTag: String, mediaId: Int)
}

interface GutenbergDialogNegativeClickInterface {
fun onGutenbergDialogNegativeClicked(instanceTag: String)
}

interface GutenbergDialogOnDismissByOutsideTouchInterface {
fun onDismissByOutsideTouch(instanceTag: String)
}

fun initialize(
tag: String,
title: CharSequence?,
message: CharSequence,
positiveButtonLabel: CharSequence,
negativeButtonLabel: CharSequence? = null,
mediaId: Int
) {
mTag = tag
mTitle = title
mMessage = message
mPositiveButtonLabel = positiveButtonLabel
mNegativeButtonLabel = negativeButtonLabel
mMediaId = mediaId
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
this.isCancelable = true
val theme = 0
setStyle(STYLE_NORMAL, theme)

if (savedInstanceState != null) {
mTag = requireNotNull(savedInstanceState.getString(STATE_KEY_TAG))
mTitle = savedInstanceState.getCharSequence(STATE_KEY_TITLE)
mMessage = requireNotNull(savedInstanceState.getCharSequence(STATE_KEY_MESSAGE))
mPositiveButtonLabel = requireNotNull(savedInstanceState.getCharSequence(STATE_KEY_POSITIVE_BUTTON_LABEL))
mNegativeButtonLabel = savedInstanceState.getCharSequence(STATE_KEY_NEGATIVE_BUTTON_LABEL)
mMediaId = savedInstanceState.getInt(STATE_KEY_MEDIA_ID)
}
}

override fun onSaveInstanceState(outState: Bundle) {
outState.putString(STATE_KEY_TAG, mTag)
outState.putCharSequence(STATE_KEY_TITLE, mTitle)
outState.putCharSequence(STATE_KEY_MESSAGE, mMessage)
outState.putCharSequence(STATE_KEY_POSITIVE_BUTTON_LABEL, mPositiveButtonLabel)
outState.putCharSequence(STATE_KEY_NEGATIVE_BUTTON_LABEL, mNegativeButtonLabel)
outState.putInt(STATE_KEY_MEDIA_ID, mMediaId)
super.onSaveInstanceState(outState)
}

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val builder = MaterialAlertDialogBuilder(requireActivity())
builder.setMessage(mMessage)

mTitle?.let {
builder.setTitle(mTitle)
}

mPositiveButtonLabel?.let {
builder.setPositiveButton(mPositiveButtonLabel) { _, _ ->
dismissedByPositiveButton = true
val parentFragment: Fragment? = parentFragment
if (parentFragment != null) {
(parentFragment as GutenbergDialogPositiveClickInterface).onGutenbergDialogPositiveClicked(
mTag,
mMediaId
)
}
}.setCancelable(true)
}

mNegativeButtonLabel?.let {
builder.setNegativeButton(mNegativeButtonLabel) { _, _ ->
dismissedByNegativeButton = true
val parentFragment: Fragment? = parentFragment
if (parentFragment != null) {
(parentFragment as GutenbergDialogNegativeClickInterface).onGutenbergDialogNegativeClicked(mTag)
}
}
}

return builder.create()
}

override fun onAttach(context: Context) {
super.onAttach(context)
val parentFragment: Fragment? = parentFragment
if (parentFragment !is GutenbergDialogPositiveClickInterface) {
throw RuntimeException("Parent fragment must implement GutenbergDialogPositiveClickInterface")
}
if (mNegativeButtonLabel != null && parentFragment !is GutenbergDialogNegativeClickInterface) {
throw RuntimeException("Parent fragment must implement GutenbergDialogNegativeClickInterface")
}
}

override fun onDismiss(dialog: DialogInterface) {
val activity = activity
if (activity != null && activity is GutenbergDialogOnDismissByOutsideTouchInterface) {
// Only handle the event if it wasn't triggered by a button
if (!dismissedByPositiveButton && !dismissedByNegativeButton) {
(activity as GutenbergDialogOnDismissByOutsideTouchInterface).onDismissByOutsideTouch(mTag)
}
}
super.onDismiss(dialog)
}

companion object {
private const val STATE_KEY_TAG = "state_key_tag"
private const val STATE_KEY_TITLE = "state_key_title"
private const val STATE_KEY_MESSAGE = "state_key_message"
private const val STATE_KEY_POSITIVE_BUTTON_LABEL = "state_key_positive_button_label"
private const val STATE_KEY_NEGATIVE_BUTTON_LABEL = "state_key_negative_button_label"
private const val STATE_KEY_MEDIA_ID = "state_key_media_id"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.gson.Gson;

import org.jetbrains.annotations.NotNull;
import org.wordpress.android.editor.BuildConfig;
import org.wordpress.android.editor.EditorEditMediaListener;
import org.wordpress.android.editor.EditorFragmentAbstract;
Expand All @@ -44,6 +45,8 @@
import org.wordpress.android.editor.LiveTextWatcher;
import org.wordpress.android.editor.R;
import org.wordpress.android.editor.WPGutenbergWebViewActivity;
import org.wordpress.android.editor.gutenberg.GutenbergDialogFragment.GutenbergDialogPositiveClickInterface;
import org.wordpress.android.editor.gutenberg.GutenbergDialogFragment.GutenbergDialogNegativeClickInterface;
import org.wordpress.android.util.AppLog;
import org.wordpress.android.util.AppLog.T;
import org.wordpress.android.util.DateTimeUtils;
Expand Down Expand Up @@ -84,7 +87,9 @@ public class GutenbergEditorFragment extends EditorFragmentAbstract implements
EditorMediaUploadListener,
IHistoryListener,
EditorThemeUpdateListener,
StorySaveMediaListener {
StorySaveMediaListener,
GutenbergDialogPositiveClickInterface,
GutenbergDialogNegativeClickInterface {
private static final String GUTENBERG_EDITOR_NAME = "gutenberg";
private static final String KEY_HTML_MODE_ENABLED = "KEY_HTML_MODE_ENABLED";
private static final String KEY_EDITOR_DID_MOUNT = "KEY_EDITOR_DID_MOUNT";
Expand All @@ -96,6 +101,7 @@ public class GutenbergEditorFragment extends EditorFragmentAbstract implements
public static final String ARG_STORY_BLOCK_UPDATED_CONTENT = "story_block_updated_content";
public static final String ARG_STORY_BLOCK_EXTERNALLY_EDITED_ORIGINAL_HASH = "story_block_original_hash";
public static final String ARG_FAILED_MEDIAS = "arg_failed_medias";
public static final String ARG_FEATURED_IMAGE_ID = "featured_image_id";

private static final int CAPTURE_PHOTO_PERMISSION_REQUEST_CODE = 101;
private static final int CAPTURE_VIDEO_PERMISSION_REQUEST_CODE = 102;
Expand All @@ -109,6 +115,8 @@ public class GutenbergEditorFragment extends EditorFragmentAbstract implements

private static final int UNSUPPORTED_BLOCK_REQUEST_CODE = 1001;

private static final String TAG_REPLACE_FEATURED_DIALOG = "REPLACE_FEATURED_DIALOG";

private boolean mHtmlModeEnabled;

private Handler mInvalidateOptionsHandler;
Expand Down Expand Up @@ -198,6 +206,7 @@ public void onCreate(Bundle savedInstanceState) {
mExternallyEditedBlockOriginalHash = savedInstanceState.getString(
ARG_STORY_BLOCK_EXTERNALLY_EDITED_ORIGINAL_HASH);
mFailedMediaIds = (HashSet<String>) savedInstanceState.getSerializable(ARG_FAILED_MEDIAS);
mFeaturedImageId = savedInstanceState.getLong(ARG_FEATURED_IMAGE_ID);
}
}

Expand Down Expand Up @@ -785,26 +794,18 @@ public void onClick(DialogInterface dialog, int id) {
dialog.show();
}

private void showFeaturedImageConfirmationDialog(final int mediaId) {
AlertDialog.Builder builder = new MaterialAlertDialogBuilder(getActivity());
builder.setTitle(R.string.replace_current_title);
builder.setMessage(R.string.replace_current_description);
builder.setPositiveButton(R.string.replace_current_confirmation,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
setFeaturedImage(mediaId);
}
});

builder.setNegativeButton(R.string.replace_current_cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
public void showFeaturedImageConfirmationDialog(final int mediaId) {
GutenbergDialogFragment dialog = new GutenbergDialogFragment();
dialog.initialize(
TAG_REPLACE_FEATURED_DIALOG,
getString(R.string.replace_current_title),
getString(R.string.replace_current_description),
getString(R.string.replace_current_confirmation),
getString(R.string.replace_current_cancel),
mediaId
);

AlertDialog dialog = builder.create();
dialog.show();
dialog.show(getChildFragmentManager(), TAG_REPLACE_FEATURED_DIALOG);
}

private void setFeaturedImage(int mediaId) {
Expand Down Expand Up @@ -928,6 +929,7 @@ public void onSaveInstanceState(Bundle outState) {
outState.putBoolean(KEY_EDITOR_DID_MOUNT, mEditorDidMount);
outState.putString(ARG_STORY_BLOCK_EXTERNALLY_EDITED_ORIGINAL_HASH, mExternallyEditedBlockOriginalHash);
outState.putSerializable(ARG_FAILED_MEDIAS, mFailedMediaIds);
outState.putLong(ARG_FEATURED_IMAGE_ID, mFeaturedImageId);
}

@Override
Expand Down Expand Up @@ -1380,4 +1382,22 @@ public void onEditorThemeUpdated(Bundle editorTheme) {
public void showNotice(String message) {
getGutenbergContainerFragment().showNotice(message);
}

@Override
public void onGutenbergDialogPositiveClicked(@NotNull String instanceTag, int mediaId) {
switch (instanceTag) {
case TAG_REPLACE_FEATURED_DIALOG:
setFeaturedImage(mediaId);
break;
}
}

@Override
public void onGutenbergDialogNegativeClicked(@NotNull String instanceTag) {
switch (instanceTag) {
case TAG_REPLACE_FEATURED_DIALOG:
// Dismiss dialog with no action.
break;
}
}
}