Refactor 'showCancelMediaUploadDialog' to Prevent Dismissal on Screen Rotation#14810
Refactor 'showCancelMediaUploadDialog' to Prevent Dismissal on Screen Rotation#14810
Conversation
The 'id' param is currently bound to an Int type. This reflects the fact that it's currently only being used to generate one dialog, which passes a mediaId. Ideally, it should be possible to pass any piece of data to the class from Gutenberg. See this comment for more context: #14676 (comment) With the changes proposed in this commit, the 'id' param is refactored to make use of generics, so that it isn't bound to any specific type. It is also renamed to 'dataFromGutenberg', in an attempt to make its purpose clearer, which is to pass in any piece of data from the editor to the dialog.
|
You can trigger optional UI/connected tests for these changes by visiting CircleCI here. |
The dialog we're refactoring as part of this PR doesn't have a 'message' value. This value is currently required by default with the GutenbergDialogFragment that's going to be used. With this commit, GutenbergDialogFragment is changed so that it's possible to pass 'null' as a 'message'.
|
You can test the changes on this Pull Request by downloading the APK here. |
With this commit, the 'showCancelMediaUploadDialog()' function is refactored to call GutenbergDialogFragment. GutenbergDialogFragment is initialized using the dialog's tag, title, button text, and the 'localMediaId' being passed. The logic that fires when the 'yes' button is pressed has been separated out into a new function, 'cancelMediaUpload()'.
...ressEditor/src/main/java/org/wordpress/android/editor/gutenberg/GutenbergEditorFragment.java
Outdated
Show resolved
Hide resolved
When a user clicks the positive button, the cancelMediaUpload() should fire, as implemented in this commit.
The 'STATE_KEY_ID' is renamed to 'STATE_KEY_DATA_FROM_GUTENBERG' with this commit, to coincide with earlier name changes to the 'id' param.
|
👋 @planarvoid, as we previously talked a bit about this issue, I wondered if you might have some availability this week to review my first pass at fixing one of the dialogs? Let me know. :) |
Generated by 🚫 dangerJS |
|
@planarvoid, I requested you as a reviewer, but let me know if you won't be able to get to this week or next, and I can find someone else. :) |
| class GutenbergDialogFragment<T : Serializable?>() : AppCompatDialogFragment() { | ||
| private lateinit var mTag: String | ||
| private lateinit var mMessage: CharSequence | ||
| private var mMessage: CharSequence? = null |
There was a problem hiding this comment.
we shouldn't use the Hungarian notation in Kotlin 👍
| interface GutenbergDialogPositiveClickInterface { | ||
| fun onGutenbergDialogPositiveClicked(instanceTag: String, id: Int) | ||
| interface GutenbergDialogPositiveClickInterface<T> { | ||
| fun onGutenbergDialogPositiveClicked(instanceTag: String, dataFromGutenberg: Any?) |
There was a problem hiding this comment.
I assume the type of dataFromGutenberg should be T, not Any
|
Thanks for the PR! |
Thank you for your candid feedback, would you be able to help me understand the concern with how the fragment manager creates/restores fragments using this approach? What type of problems could it cause?
The data varies for each of the six dialogs in I can definitely research the other options you mentioned and will seek to gain a better understanding of why they're more suitable as part of that research.
To make sure I understand you correctly, are you suggesting that I create six separate dialog fragments for each of the dialogs declared in
Thank you for the context around the pattern I followed being an older approach. It's definitely tricky to distinguish between old and new approaches when looking for patterns as a junior exploring the codebase. In this case, the pattern I copied was from the BasicFragmentDialog class. Do you think it'd be worthwhile for me to create a PR to add a summary of what you mentioned around the preferable approach to the comments of that file? Thanks again in advance for your patience with my questions as I learn and sharing your knowledge here. 🙇♀️ |
|
thanks for the reply!
is not a safe cast. This is what Android Studio tells you: I think it will still work but I wouldn't do it. A check like this: will not work in Kotlin.
I think
What I meant is that you can have 6 children without any logic that would just inherit from the
I think we can add that. That's a good idea! Sadly we don't have enough time to deal with the technical debt so we keep the old files around as long as they are used somewhere. |
|
I'm going to go ahead to close this PR as it's not currently being worked on or a priority. |
Description
Partial fix for #14676
The
showCancelMediaUploadDialog, which is shown when tapping an image that's still in the process of uploading, is currently dismissed/lost with a screen rotation.This can lead to buggy behavior, as shown in the following screenshots, where the image will permanently look like it's still uploading, with any attempts to tap on it resulting in the dialog appearing again, even though the image has been uploaded to the site's media library:
This PR seeks to fix the above issue by refactoring the dialog so that it survives screen rotation. A custom dialog fragment,
GutenbergDialogFragment, is used to achieve this.GutenbergDialogFragment
A new
GutenbergDialogFragmentclass was introduced in #14503. This class is based on theBasicFragmentDialogclass, with some key differences being the removal of the thirdsetNeutralButton, an addition of a mediaId to the constructor, and the ability for the parent fragment to implement the positive/negative button interfaces.Part of the goal behind creating the new
GutenbergDialogFragmentclass was to allow for easier refactoring of the other dialogs listed in #14676, which are all currently lost/dismissed with a screen rotation. With that goal in mind, the mediaId param is refactored with this PR to utilize generics and accept any data type. Its message param has also been made optional, as not all dialogs declared inGutenbergEditorFragmentinclude a message.The aforementioned changes make it relatively straightforward to refactor
showCancelMediaUploadDialogto use the custom dialog fragment.Testing Steps
Regression Notes
The main unintended side effect of this PR would be for the dialog's existing "yes" or "no" flows to break.
I following the outlined testing steps, with various combinations of rotations and button pressing to see if I could create any problems or issues.
Automated tests didn't feel warranted given the size of this change.
PR submission checklist:
RELEASE-NOTES.txtif necessary.