Skip to content
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

Conversation

derekblank
Copy link
Contributor

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 invoking mediaFileUploadPaused from within onMediaUploadFailed.

To Test:


Regression Notes

  1. Potential unintended areas of impact

  2. What I did to test those areas of impact (or what existing automated tests I relied on)

  3. What automated tests I added (or what prevented me from doing so)


PR Submission Checklist:

  • I have completed the Regression Notes.
  • I have considered adding accessibility improvements for my changes.
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

UI Changes Testing Checklist:

  • Portrait and landscape orientations.
  • Light and dark modes.
  • Fonts: Larger, smaller and bold text.
  • High contrast.
  • Talkback.
  • Languages with large words or with letters/accents not frequently used in English.
  • Right-to-left languages. (Even if translation isn’t complete, formatting should still respect the right-to-left layout)
  • Large and small screen sizes. (Tablet and smaller phones)
  • Multi-tasking: Split screen and Pop-up view. (Android 10 or higher)

@derekblank derekblank requested a review from dcalhoun January 4, 2024 06:31

@Override
public void onMediaUploadPaused(final String localMediaId) {
getGutenbergContainerFragment().mediaFileUploadPaused(Integer.valueOf(localMediaId));
mFailedMediaIds.add(localMediaId);
Copy link
Contributor Author

@derekblank derekblank Jan 4, 2024

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:

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.

Copy link
Member

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.

@derekblank derekblank added the Gutenberg Editing and display of Gutenberg blocks. label Jan 4, 2024
@derekblank derekblank marked this pull request as ready for review January 4, 2024 06:41
@wpmobilebot
Copy link
Contributor

Jetpack📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack Jetpack
FlavorJalapeno
Build TypeDebug
Versionpr19884-b22021a
Commitb22021a
Direct Downloadjetpack-prototype-build-pr19884-b22021a.apk
Note: Google Login is not supported on these builds.

@wpmobilebot
Copy link
Contributor

WordPress📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress WordPress
FlavorJalapeno
Build TypeDebug
Versionpr19884-b22021a
Commitb22021a
Direct Downloadwordpress-prototype-build-pr19884-b22021a.apk
Note: Google Login is not supported on these builds.

Copy link
Member

@dcalhoun dcalhoun left a 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)) {
Copy link
Member

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?

Comment on lines 301 to 303
fun onMediaUploadPaused(listener: EditorMediaUploadListener, media: MediaModel) = launch {
listener.onMediaUploadPaused(media.id.toString())
}
Copy link
Member

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);
Copy link
Member

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.

Suggested change
void onMediaUploadPaused(String toString);
void onMediaUploadPaused(String localId);

Comment on lines 1434 to 1436
public void onMediaUploadPaused(final String localMediaId) {
mUploadingMediaProgressMax.remove(localMediaId);
}
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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.

@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) {
Copy link
Member

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.

Suggested change
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);
Copy link
Member

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.
@peril-wordpress-mobile
Copy link

Warnings
⚠️ PR is not assigned to a milestone.

Generated by 🚫 dangerJS

Comment on lines +3704 to +3706
if (TextUtils.isEmpty(event.media.getUrl()) && !NetworkUtils.isNetworkAvailable(this)) {
MediaError error = new MediaError(MediaErrorType.GENERIC_ERROR);
mEditorMedia.onMediaUploadPaused(mEditorMediaUploadListener, event.media, error);
Copy link
Member

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.

@wpmobilebot
Copy link
Contributor

1 Warning
⚠️ PR is not assigned to a milestone.

Generated by 🚫 Danger

@dcalhoun dcalhoun merged commit 2a5075d into feat/update-image-block-upload-visuals Jan 4, 2024
12 of 20 checks passed
@dcalhoun dcalhoun deleted the feat/update-image-block-upload-visuals__discrete-paused-state branch January 4, 2024 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Gutenberg Editing and display of Gutenberg blocks.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants