Skip to content

Commit

Permalink
Merge pull request #19878 from wordpress-mobile/feat/update-image-blo…
Browse files Browse the repository at this point in the history
…ck-upload-visuals

feat: Pause media upload when internet connection unavailable
  • Loading branch information
dcalhoun authored Jan 10, 2024
2 parents 482f339 + e3ad26b commit d1ff96e
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 4 deletions.
2 changes: 1 addition & 1 deletion RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

24.1
-----

* [**] Image block media uploads display a custom error message when there is no internet connection [https://github.com/wordpress-mobile/WordPress-Android/pull/19878]

24.0
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3682,6 +3682,11 @@ public void onMediaUploaded(OnMediaUploaded event) {
return;
}

if (event.isError() && !NetworkUtils.isNetworkAvailable(this)) {
mEditorMedia.onMediaUploadPaused(mEditorMediaUploadListener, event.media, event.error);
return;
}

// event for unknown media, ignoring
if (event.media == null) {
AppLog.w(AppLog.T.MEDIA, "Media event carries null media object, not recognized");
Expand All @@ -3700,7 +3705,10 @@ public void onMediaUploaded(OnMediaUploaded event) {
mEditorMedia.onMediaUploadError(mEditorMediaUploadListener, event.media, event.error);
} else if (event.completed) {
// if the remote url on completed is null, we consider this upload wasn't successful
if (TextUtils.isEmpty(event.media.getUrl())) {
if (TextUtils.isEmpty(event.media.getUrl()) && !NetworkUtils.isNetworkAvailable(this)) {
MediaError error = new MediaError(MediaErrorType.GENERIC_ERROR);
mEditorMedia.onMediaUploadPaused(mEditorMediaUploadListener, event.media, error);
} else if (TextUtils.isEmpty(event.media.getUrl())) {
MediaError error = new MediaError(MediaErrorType.GENERIC_ERROR);
mEditorMedia.onMediaUploadError(mEditorMediaUploadListener, event.media, error);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,18 @@ class EditorMedia @Inject constructor(
listener.onMediaUploadFailed(media.id.toString())
}

fun onMediaUploadPaused(listener: EditorMediaUploadListener, media: MediaModel, error: MediaError) = launch {
val properties: Map<String, Any?> = withContext(bgDispatcher) {
analyticsUtilsWrapper
.getMediaProperties(media.isVideo, null, media.filePath)
.also {
it["error_type"] = error.type.name
}
}
analyticsTrackerWrapper.track(EDITOR_UPLOAD_MEDIA_FAILED, properties)
listener.onMediaUploadPaused(media.id.toString())
}

sealed class AddMediaToPostUiState(
val editorOverlayVisibility: Boolean,
val progressDialogUiState: ProgressDialogUiState
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ext {
automatticRestVersion = '1.0.8'
automatticStoriesVersion = '2.4.0'
automatticTracksVersion = '3.3.0'
gutenbergMobileVersion = 'v1.110.0'
gutenbergMobileVersion = 'v1.111.0-alpha1'
wordPressAztecVersion = 'v1.9.0'
wordPressFluxCVersion = '2.61.0'
wordPressLoginVersion = '1.10.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1431,6 +1431,12 @@ public void onMediaUploadFailed(final String localMediaId) {
mUploadingMediaProgressMax.remove(localMediaId);
}

@Override
public void onMediaUploadPaused(final String localMediaId) {
// Aztec does not leverage the paused media state, only the Gutenberg editor
onMediaUploadFailed(localMediaId);
}

@Override
public void onVideoInfoRequested(final AztecAttributes attrs) {
// VideoPress special case here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ public interface EditorMediaUploadListener {
void onMediaUploadProgress(String localId, float progress);
void onMediaUploadFailed(String localId);
void onGalleryMediaUploadSucceeded(long galleryId, long remoteId, int remaining);
void onMediaUploadPaused(String localId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ public void mediaFileUploadFailed(final int mediaId) {
mWPAndroidGlueCode.mediaFileUploadFailed(mediaId);
}

public void mediaFileUploadPaused(final int mediaId) {
mWPAndroidGlueCode.mediaFileUploadPaused(mediaId);
}

public void mediaFileUploadSucceeded(final int mediaId, final String mediaUrl, final int serverMediaId) {
mWPAndroidGlueCode.mediaFileUploadSucceeded(mediaId, mediaUrl, serverMediaId, new WritableNativeMap());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,11 @@ private void updateFailedMediaState() {
for (String mediaId : mFailedMediaIds) {
// upload progress should work on numeric mediaIds only
if (!TextUtils.isEmpty(mediaId) && TextUtils.isDigitsOnly(mediaId)) {
getGutenbergContainerFragment().mediaFileUploadFailed(Integer.valueOf(mediaId));
if (NetworkUtils.isNetworkAvailable(getActivity())) {
getGutenbergContainerFragment().mediaFileUploadFailed(Integer.valueOf(mediaId));
} else {
getGutenbergContainerFragment().mediaFileUploadPaused(Integer.valueOf(mediaId));
}
} else {
getGutenbergContainerFragment().mediaFileSaveFailed(mediaId);
}
Expand Down Expand Up @@ -1496,6 +1500,13 @@ public void onMediaUploadFailed(final String localMediaId) {
mUploadingMediaProgressMax.remove(localMediaId);
}

@Override
public void onMediaUploadPaused(final String localMediaId) {
getGutenbergContainerFragment().mediaFileUploadPaused(Integer.valueOf(localMediaId));
mFailedMediaIds.add(localMediaId);
mUploadingMediaProgressMax.remove(localMediaId);
}

@Override
public void onGalleryMediaUploadSucceeded(final long galleryId, long remoteMediaId, int remaining) {
}
Expand Down

0 comments on commit d1ff96e

Please sign in to comment.