-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add a "Set as Featured Image" Button to Image Block #14503
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
Merged
Merged
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 4190066
Add OnSetFeaturedImageListener()
SiobhyB 86e6bb0
Add onSetFeaturedImageButtonClicked() function
SiobhyB 51be414
Add updateFeaturedImage() function
SiobhyB 4ab70b2
Add setFeaturedImage() and removeFeaturedImage() functions
SiobhyB 0dd7399
Create dialog in showFeaturedImageConfirmationDialog()
SiobhyB 29d2d0b
Send a notice depending on whether a featured image is set or removed
SiobhyB 7ee5029
Update reference to latest Gutenberg Mobile commit
SiobhyB 0f54607
added an update featured image use case.
jd-alexander 9d72f88
Created mechanisms to track when the gb featured image is picked
jd-alexander d3b8972
Integrated the new use case and approach to EditPost and Post Settings
jd-alexander ce3785e
Update remaining references to "IMAGE_PICKED" to "IMAGE_PICKED_POST_S…
SiobhyB c1278d6
Remove unused imports from EditPostSettingsFragment.java
SiobhyB dfc7be8
Merge branch 'develop' into gb/1011-set-featured-button
SiobhyB 08efc40
Remove removeFeaturedImage() function and consolidate into a single s…
SiobhyB 655bb60
Bump Gutenberg Mobile
SiobhyB cffaf48
Merge branch 'develop' into gb/1011-set-featured-button
SiobhyB 2e5b213
Refactor logic for around showFeaturedImageConfirmationDialog()
SiobhyB 71f8f36
Update build.gradle with latest Gutenberg Mobile reference
SiobhyB 34b78ce
Update build.gradle to reference latest commit from Gutenberg Mobile
SiobhyB 6ba7938
Merge branch 'develop' into gb/1011-set-featured-button
SiobhyB e0b301d
Merge branch 'develop' into gb/1011-set-featured-button
SiobhyB 74323e9
Merge branch 'develop' into gb/1011-set-featured-button
SiobhyB 754688a
Merge branch 'develop' into gb/1011-set-featured-button
SiobhyB 3ccdc1d
Merge branch 'develop' into gb/1011-set-featured-button
SiobhyB f4358c4
Update reference to latest Gutenberg Mobile commit
SiobhyB 6ba9fc2
Merge branch 'develop' into gb/1011-set-featured-button
SiobhyB d6d26ec
Merge branch 'gb/1011-set-featured-button' of github.com:wordpress-mo…
SiobhyB 621ce38
Update reference to latest Gutenberg Mobile commit
SiobhyB 57c3059
Bump Gutenberg Mobile reference
SiobhyB 1187bc1
Updated gutenberg-mobile ref.
jd-alexander 610348e
added inject annotation to the constructor of the use case.
jd-alexander 0cfaf4f
Updated gutenberg-mobile ref.
jd-alexander 617c5e2
removed comment about disabling Audio block since it is now on all sites
jd-alexander 672fd07
Merge branch 'gb/1011-set-featured-button' into gb/1011-set-featured-…
jd-alexander 70dff2c
formatted the use case.
jd-alexander d1e7eda
sync stories submodule.
jd-alexander fa76582
Create GutenbergDialogFragment.kt using BasicDialogFragment.kt as a t…
SiobhyB 41c25e0
Add mediaId to GutenbergDialogFragment's constructor
SiobhyB d772cbf
Edit "onNegativeClicked" and "onPositiveClicked" so that interface ca…
SiobhyB 193a41b
Implement BasicDialogPositiveClickInterface and BasicDialogNegativeCl…
SiobhyB 1a988c7
Refactor showFeaturedImageConfirmationDialog() to use new GutenbergDi…
SiobhyB 246334e
Add "org.jetbrains.annotations.NotNull" import
SiobhyB 8bb8837
Fill out "onPositiveClicked" function
SiobhyB f35cea5
Fill out onNegativeClicked() function
SiobhyB 3da4908
Rename instances of "BasicDialog" to "GutenbergDialog"
SiobhyB 983ff6c
Update reference to Gutenberg Mobile
SiobhyB cd572af
Rename "onPositiveClicked" and "onNegativeClicked"
SiobhyB f0ff0ba
Merge branch 'develop' into gb/1011-set-featured-button
SiobhyB 349fe90
Reformat code in GutenbergDialogFragment.kt
SiobhyB 010505f
Update build.grade with latest reference to Gutenberg Mobile
SiobhyB f57eeaf
Save "mFeaturedImageId" in savedInstanceState() and onSaveInstanceSta…
SiobhyB 3e18f04
Remove redundant comma
SiobhyB aa15b61
Add checks to ensure GutenbergDialogPositiveClickInterface and Gutenb…
SiobhyB 101970c
Don't allow "mPositiveButtonLabel" to be null
SiobhyB 24a0532
Add "lateinit" modifier to mPositiveButtonLabel
SiobhyB f7b81e9
Merge branch 'gb/1011-set-featured-button' into gb/1011-set-featured-…
SiobhyB 7348943
Add Tracks event that fires when a featured image is removed from the…
SiobhyB bf1942f
Refactor null-checks and casting in setPositiveButton() and setNegati…
SiobhyB fe93e0b
Refactor if/else statement in onSetFeaturedImageButtonClicked()
SiobhyB 33fd368
Remove call to sendToJSFeaturedImageId() from within setFeaturedImage()
SiobhyB 854dd6d
Remove unnecessary semi-colons
SiobhyB 62caa42
Refine string names
SiobhyB b4863bb
Merge branch 'develop' into gb/1011-set-featured-button
SiobhyB 6fd6fc0
Update string name being passed to showNotice() calls
SiobhyB 3751c08
Update comment to clarify reasoning behind "setFeaturedImageId" call
SiobhyB b4dc825
Reword "featured_image_replace_dialog_title" string
SiobhyB 9630c29
Introduce "MEDIA_ID_NO_FEATURED_IMAGE_SET" const
SiobhyB 7924341
Refactor onDismiss() in GutenbergDialogFragment
SiobhyB d41cd34
Bump reference to Gutenberg Mobile
SiobhyB ccb7292
Merge branch 'develop' into gb/1011-set-featured-button
SiobhyB 36b6e2e
Remove unecessary comment before 'setFeaturedImageId'
SiobhyB 1be6762
Fix 'exceeded max line length' ktlint error
SiobhyB c917a0c
Remove conditional surrounding 'GutenbergDialogOnDismissByOutsideTouc…
SiobhyB c0626bf
Update build.gradle reference to latest commit from Gutenberg Mobile
SiobhyB 2e07265
Merge branch 'develop' into gutenberg/audio-block-capability
jd-alexander 58c6d56
Merge branch 'develop' into gutenberg/audio-block-capability
jd-alexander 96faacf
renamed capability
jd-alexander 2fa9eb7
sync stories submodule hash.
jd-alexander 74a2251
updated gutenberg-mobile ref.
jd-alexander 2a1ef13
Bump Gutenberg Mobile reference
SiobhyB 105509e
Merge branch 'develop' into gb/1011-set-featured-button
SiobhyB a7dabab
Update Gutenberg Mobile ref
fluiddot bccaaa9
reformatted use case
jd-alexander e81d2c2
Merge pull request #14521 from wordpress-mobile/gb/1011-set-featured-…
jd-alexander 92816a9
Update Gutenberg Mobile ref
fluiddot d52f22c
Merge branch 'develop' into gb/1011-set-featured-button
SiobhyB fb3ba95
Import constant for use in EditPostActivity
SiobhyB 40310c3
Rename references to 'mediaId' to 'id'
SiobhyB 1eb55fa
Reword dialog's title for clarity.
SiobhyB c1f6842
Undo title case in notices for consistency
SiobhyB 8c5005f
Update to latest Gutenberg Mobile reference
SiobhyB db9e884
Merge branch 'develop' into gutenberg/audio-block-capability
fluiddot 54d9cf9
Update Gutenberg Mobile ref
fluiddot d7953d4
Update Gutenberg Mobile ref
fluiddot 2caa7c0
Bump Gutenberg Mobile reference
SiobhyB 3e2d759
Merge branch 'gutenberg/audio-block-capability' into gb/1011-set-feat…
fluiddot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
...essEditor/src/main/java/org/wordpress/android/editor/gutenberg/GutenbergDialogFragment.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
hypest marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.