diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index ebbc4b938eb9..b03f000aaec9 100644 --- a/RELEASE-NOTES.txt +++ b/RELEASE-NOTES.txt @@ -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 ----- diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.java index 8eb3b555a0c8..380455c2ca6a 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.java @@ -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"); @@ -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 { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/editor/media/EditorMedia.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/editor/media/EditorMedia.kt index 4332f516783a..13d81127bc5a 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/editor/media/EditorMedia.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/editor/media/EditorMedia.kt @@ -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 = 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 diff --git a/build.gradle b/build.gradle index 8b40d2f03dca..6748767e4606 100644 --- a/build.gradle +++ b/build.gradle @@ -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' diff --git a/libs/editor/src/main/java/org/wordpress/android/editor/AztecEditorFragment.java b/libs/editor/src/main/java/org/wordpress/android/editor/AztecEditorFragment.java index 4c945a3feced..836c3e67a011 100644 --- a/libs/editor/src/main/java/org/wordpress/android/editor/AztecEditorFragment.java +++ b/libs/editor/src/main/java/org/wordpress/android/editor/AztecEditorFragment.java @@ -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 diff --git a/libs/editor/src/main/java/org/wordpress/android/editor/EditorMediaUploadListener.java b/libs/editor/src/main/java/org/wordpress/android/editor/EditorMediaUploadListener.java index ce90ac13eaf7..298c9f0d9160 100644 --- a/libs/editor/src/main/java/org/wordpress/android/editor/EditorMediaUploadListener.java +++ b/libs/editor/src/main/java/org/wordpress/android/editor/EditorMediaUploadListener.java @@ -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); } diff --git a/libs/editor/src/main/java/org/wordpress/android/editor/gutenberg/GutenbergContainerFragment.java b/libs/editor/src/main/java/org/wordpress/android/editor/gutenberg/GutenbergContainerFragment.java index e22a413c465b..ec062f54e37e 100644 --- a/libs/editor/src/main/java/org/wordpress/android/editor/gutenberg/GutenbergContainerFragment.java +++ b/libs/editor/src/main/java/org/wordpress/android/editor/gutenberg/GutenbergContainerFragment.java @@ -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()); } diff --git a/libs/editor/src/main/java/org/wordpress/android/editor/gutenberg/GutenbergEditorFragment.java b/libs/editor/src/main/java/org/wordpress/android/editor/gutenberg/GutenbergEditorFragment.java index 438ff12889ee..f924be546cf5 100644 --- a/libs/editor/src/main/java/org/wordpress/android/editor/gutenberg/GutenbergEditorFragment.java +++ b/libs/editor/src/main/java/org/wordpress/android/editor/gutenberg/GutenbergEditorFragment.java @@ -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); } @@ -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) { }