-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add discrete onMediaUploadPaused handler to media uploads when offline #19884
Add discrete onMediaUploadPaused handler to media uploads when offline #19884
Conversation
|
||
@Override | ||
public void onMediaUploadPaused(final String localMediaId) { | ||
getGutenbergContainerFragment().mediaFileUploadPaused(Integer.valueOf(localMediaId)); | ||
mFailedMediaIds.add(localMediaId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really wish to add these localMediaIds to mFailedMediaIds
, but it is necessary to automatically restart media uploads:
Lines 1591 to 1596 in 234db29
public void onConnectionStatusChange(boolean isConnected) { | |
getGutenbergContainerFragment().onConnectionStatusChange(isConnected); | |
if (BuildConfig.DEBUG && isConnected && hasFailedMediaUploads()) { | |
mEditorFragmentListener.onMediaRetryAll(mFailedMediaIds); | |
} | |
} |
Semantically, this should probably be called mFailedOrPausedMediaIds
(including related artifacts
like hasFailedMediaUploads
-> hasFailedOrPausedMediaUploads
). The concept of failed uploads could be rethought of entirely with the introduction of MEDIA_UPLOAD_STATE_PAUSED
. That feels well outside the scope of this change, as it has quite a large surface area. If there is a more elegant way to restart media uploads without adding these to mFailedMediaIds
, I am open to it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree a refactor is likely beneficial but unnecessary at this time.
That said, I do not believe overloading mFailedMediaIds
to include "paused" media is all that cryptic or misleading, particularly if we only consider media to be "paused" if it also contains an error, as I noted in a separate comment.
📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
|
📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like your proposed changes. I plan to checkout the branch locally and implement some of my suggested changes. I am still interested in your responses to my suggestions, though.
@@ -3678,6 +3678,11 @@ public void onMediaUploaded(OnMediaUploaded event) { | |||
return; | |||
} | |||
|
|||
if (!NetworkUtils.isNetworkAvailable(this)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I worry that if we do not check for an error as well, we might erroneously mark successfully uploaded media as paused. WDYT?
fun onMediaUploadPaused(listener: EditorMediaUploadListener, media: MediaModel) = launch { | ||
listener.onMediaUploadPaused(media.id.toString()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I imagine we should still track an event of EDITOR_UPLOAD_MEDIA_FAILED
for paused media, or implement a new event. WDYT?
@@ -9,4 +9,5 @@ public interface EditorMediaUploadListener { | |||
void onMediaUploadProgress(String localId, float progress); | |||
void onMediaUploadFailed(String localId, String errorType); | |||
void onGalleryMediaUploadSucceeded(long galleryId, long remoteId, int remaining); | |||
void onMediaUploadPaused(String toString); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an odd parameter name, presumably a typo.
void onMediaUploadPaused(String toString); | |
void onMediaUploadPaused(String localId); |
public void onMediaUploadPaused(final String localMediaId) { | ||
mUploadingMediaProgressMax.remove(localMediaId); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like avoiding a need to pass the error type and entangle the paused and error methods, but I worry about modify Aztec. We likely need to test Aztec to avoid regressions.
Additionally, I note this method lacks an @Override
annotation that surround methods possess. We should likely follow the existing code pattern.
Lastly, how confident are we that we only need to remove the localMediaId
? Do we need the guard clause or other logic from the sibling failed method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding onMediaUploadPaused
to Aztec was done quickly to get around some build errors from Android Studio. I also am not keen on modifying Aztec. I'll do some further testing to see if this is actually needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding is that it is necessary, as both Aztec and Gutenberg share a common interface to which they must adhere. For Aztec, the latest implementation of this merely passes the invocation onto the existing failed method. So, the regression risk should be fairly low. It is likely still worth testing the Aztec editor via editing classic posts in the app.
WordPress-Android/libs/editor/src/main/java/org/wordpress/android/editor/AztecEditorFragment.java
Lines 1434 to 1438 in b97dbec
@Override | |
public void onMediaUploadPaused(final String localMediaId) { | |
// Aztec does not leverage the paused media state, only the Gutenberg editor | |
onMediaUploadFailed(localMediaId); | |
} |
@@ -1488,14 +1488,14 @@ public void onMediaUploadProgress(final String localMediaId, final float progres | |||
|
|||
@Override | |||
public void onMediaUploadFailed(final String localMediaId, String errorType) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this approach, we no longer require the errorType
parameter and should remove it.
public void onMediaUploadFailed(final String localMediaId, String errorType) { | |
public void onMediaUploadFailed(final String localMediaId) { |
|
||
@Override | ||
public void onMediaUploadPaused(final String localMediaId) { | ||
getGutenbergContainerFragment().mediaFileUploadPaused(Integer.valueOf(localMediaId)); | ||
mFailedMediaIds.add(localMediaId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree a refactor is likely beneficial but unnecessary at this time.
That said, I do not believe overloading mFailedMediaIds
to include "paused" media is all that cryptic or misleading, particularly if we only consider media to be "paused" if it also contains an error, as I noted in a separate comment.
Ensure the implementation adheres to the relevant interface.
With the addition of a discrete paused method, we no longer utilize this parameter in the failed method.
We do not plan to add paused media support to the Aztec editor. Therefore, it likely makes more sense for the `onMediaUploadPaused` implementation to merely invoke the existing `onMediaUploadFailed` method.
Without checking for an error, there may be a possibility that successfully uploaded media is marked as "paused."
Even though we communicate a nuanced paused state to the user, we likely need to continue tracking this event as a failure, or consider adding a discrete pause analytic event.
Based upon existing code, we should consider completed uploads lacking remote URLs to be failures. Therefore, we should apply the new pause state to this context.
Generated by 🚫 dangerJS |
if (TextUtils.isEmpty(event.media.getUrl()) && !NetworkUtils.isNetworkAvailable(this)) { | ||
MediaError error = new MediaError(MediaErrorType.GENERIC_ERROR); | ||
mEditorMedia.onMediaUploadPaused(mEditorMediaUploadListener, event.media, error); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noting that I added the paused media implementation here. Based upon the existing code, it appears that completed media should be considered failed if it possesses a null remote URL.
Generated by 🚫 Danger |
2a5075d
into
feat/update-image-block-upload-visuals
Augments the work in #19878 to pause media upload when internet connection is unavailable.
This PR introduces a discrete
onMediaUploadPaused
handler to separate concerns and avoid invokingmediaFileUploadPaused
from withinonMediaUploadFailed
.To Test:
Regression Notes
Potential unintended areas of impact
What I did to test those areas of impact (or what existing automated tests I relied on)
What automated tests I added (or what prevented me from doing so)
PR Submission Checklist:
RELEASE-NOTES.txt
if necessary.UI Changes Testing Checklist: