Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
abe9c8d
added onRetryUploadForMediaClicked interface for GB
mzorz Jan 30, 2019
dce0f96
Update gutenberg-mobile submodule
marecar3 Jan 30, 2019
19ada7e
Updated gutenberg mobile submodule
marecar3 Jan 30, 2019
ec2c954
Update gutenberg mobile submodule
marecar3 Jan 30, 2019
b915c55
Updated gutenberg mobile submodule
marecar3 Jan 30, 2019
3946153
added Retry dialog and implemented single retry for Gutenberg
mzorz Jan 30, 2019
502cbf9
added onMediaRetryAllClicked interface and implementation for Gutenberg
mzorz Jan 30, 2019
b621734
reset url of media block to null when user chooses to remove a failed…
mzorz Jan 30, 2019
68d6b5c
added analytics tracking call for retry
mzorz Jan 30, 2019
dbf848b
method rename
mzorz Jan 30, 2019
a81bb64
using new glue code clearMediaFileUrl to remove data from failed imag…
mzorz Jan 31, 2019
2da1280
added media clearing code when user chooses to remove failed media fr…
mzorz Jan 31, 2019
fb4a620
fixed var name
mzorz Jan 31, 2019
75607cb
added cancel in-progress upload handling for Gutenberg
mzorz Jan 31, 2019
ef182a3
fixed lint warning
mzorz Jan 31, 2019
6e7db68
Merge branch 'develop' into gb/retry-failed-upload
marecar3 Jan 31, 2019
037a6c1
Updated gutenberg-mobile submodule
marecar3 Jan 31, 2019
4c2d92d
make sure to tell Gutenberg which media is failed upon re-entering th…
mzorz Jan 31, 2019
3f6143c
only try to signal Gutenberg to paint the failed overlay once we know…
mzorz Jan 31, 2019
cb631f0
Merge branch 'gb/retry-failed-upload' of https://github.com/wordpress…
mzorz Jan 31, 2019
1360db6
updated gb hash
mzorz Jan 31, 2019
ccfe884
renamed var name
mzorz Jan 31, 2019
b7c626a
removed commented code
mzorz Jan 31, 2019
a7f92c2
updated UploadService to only try to process the Post with Aztec if A…
mzorz Jan 31, 2019
3a9c4cb
Updated gutenberg mobile submodule
marecar3 Jan 31, 2019
532e8fa
Updated gutenberg mobile submodule
marecar3 Jan 31, 2019
69676f2
make sure not to try processing Gutenberg posts with Aztec
mzorz Jan 31, 2019
668e4d8
Merge branch 'gb/retry-failed-upload' of https://github.com/wordpress…
mzorz Jan 31, 2019
7a1d98c
Updated gutenberg mobile submodule
marecar3 Jan 31, 2019
f086c5d
updated gb-mobile hash
mzorz Jan 31, 2019
159b412
make sure to check content of post to see if processable with Aztec o…
mzorz Jan 31, 2019
c588a20
Merge branch 'gb/retry-failed-upload' of https://github.com/wordpress…
mzorz Jan 31, 2019
8102432
Updated gutenberg mobile submodule
marecar3 Jan 31, 2019
fd55945
updated gutenberg-mobile hash
mzorz Feb 1, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3231,6 +3231,27 @@ private void requestTemporaryPermissions(DragEvent dragEvent) {
requestDragAndDropPermissions(dragEvent);
}

@Override
public void onMediaRetryAllClicked(Set<String> failedMediaIds) {
UploadService.cancelFinalNotification(this, mPost);
UploadService.cancelFinalNotificationForMedia(this, mSite);

ArrayList<MediaModel> failedMediaList = new ArrayList<>();
for (String mediaId : failedMediaIds) {
failedMediaList.add(mMediaStore.getMediaWithLocalId(Integer.valueOf(mediaId)));
}

if (!failedMediaList.isEmpty()) {
for (MediaModel mediaModel : failedMediaList) {
mediaModel.setUploadState(MediaUploadState.QUEUED);
mDispatcher.dispatch(MediaActionBuilder.newUpdateMediaAction(mediaModel));
}
startUploadService(failedMediaList);
}

AnalyticsTracker.track(Stat.EDITOR_UPLOAD_MEDIA_RETRIED);
}

@Override
public boolean onMediaRetryClicked(final String mediaId) {
if (TextUtils.isEmpty(mediaId)) {
Expand Down Expand Up @@ -3300,10 +3321,25 @@ public void onMediaUploadCancelClicked(String localMediaId) {
@Override
public void onMediaDeleted(String localMediaId) {
if (!TextUtils.isEmpty(localMediaId)) {
mAztecBackspaceDeletedMediaItemIds.add(localMediaId);
UploadService.setDeletedMediaItemIds(mAztecBackspaceDeletedMediaItemIds);
// passing false here as we need to keep the media item in case the user wants to undo
cancelMediaUpload(StringUtils.stringToInt(localMediaId), false);
if (mShowAztecEditor) {
mAztecBackspaceDeletedMediaItemIds.add(localMediaId);
UploadService.setDeletedMediaItemIds(mAztecBackspaceDeletedMediaItemIds);
// passing false here as we need to keep the media item in case the user wants to undo
cancelMediaUpload(StringUtils.stringToInt(localMediaId), false);
} else if (mShowGutenbergEditor) {
MediaModel mediaModel = mMediaStore.getMediaWithLocalId(StringUtils.stringToInt(localMediaId));
if (mediaModel == null) {
return;
}

// also make sure it's not being uploaded anywhere else (maybe on some other Post,
// simultaneously)
if (mediaModel.getUploadState() != null
&& MediaUtils.isLocalFile(mediaModel.getUploadState().toLowerCase(Locale.ROOT))
&& !UploadService.isPendingOrInProgressMediaUpload(mediaModel)) {
mDispatcher.dispatch(MediaActionBuilder.newRemoveMediaAction(mediaModel));
}
}
}
}

Expand Down Expand Up @@ -3482,6 +3518,18 @@ public void onJavaScriptAlert(String url, String message) {
}
});
}

// probably here is best for Gutenberg to start interacting with
if (mShowGutenbergEditor && mEditorFragment instanceof GutenbergEditorFragment) {
List<MediaModel> failedMedia = mMediaStore.getMediaForPostWithState(mPost, MediaUploadState.FAILED);
if (failedMedia != null && !failedMedia.isEmpty()) {
HashSet<Integer> mediaIds = new HashSet<>();
for (MediaModel media : failedMedia) {
mediaIds.add(media.getId());
}
((GutenbergEditorFragment) mEditorFragment).resetUploadingMediaToFailed(mediaIds);
}
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,16 @@ private void unpackPostIntent(@NonNull Intent intent) {
}

if (intent.getBooleanExtra(KEY_SHOULD_RETRY, false)) {
if (AppPrefs.isAztecEditorEnabled()) {
if (AppPrefs.isAztecEditorEnabled() || AppPrefs.isGutenbergEditorEnabled()) {
if (!NetworkUtils.isNetworkAvailable(this)) {
rebuildNotificationError(post, getString(R.string.no_network_message));
return;
}
aztecRetryUpload(post);
boolean postHasGutenbergBlocks = PostUtils.contentContainsGutenbergBlocks(post.getContent());
boolean processWithAztec =
AppPrefs.isAztecEditorEnabled() && !AppPrefs.isGutenbergEditorEnabled()
&& !postHasGutenbergBlocks;
retryUpload(post, processWithAztec);
} else {
ToastUtils.showToast(this, R.string.retry_needs_aztec);
}
Expand Down Expand Up @@ -706,7 +710,7 @@ private void rebuildNotificationError(PostModel post, String errorMessage) {
errorMessage, 0);
}

private void registerFailedMediaForThisPost(PostModel post) {
private void aztecRegisterFailedMediaForThisPost(PostModel post) {
// there could be failed media in the post, that has not been registered in the UploadStore because
// the media was being uploaded separately (i.e. the user included media, started uploading within
// the editor, and such media failed _before_ exiting the eidtor, thus the registration never happened.
Expand Down Expand Up @@ -740,10 +744,12 @@ private void registerFailedMediaForThisPost(PostModel post) {
}
}

private void aztecRetryUpload(PostModel post) {
private void retryUpload(PostModel post, boolean processWithAztec) {
AnalyticsTracker.track(AnalyticsTracker.Stat.NOTIFICATION_UPLOAD_POST_ERROR_RETRY);

registerFailedMediaForThisPost(post);
if (processWithAztec) {
aztecRegisterFailedMediaForThisPost(post);
}

Set<MediaModel> failedMedia = mUploadStore.getFailedMediaForPost(post);
ArrayList<MediaModel> mediaToRetry = new ArrayList<>(failedMedia);
Expand All @@ -755,11 +761,13 @@ private void aztecRetryUpload(PostModel post) {
mDispatcher.dispatch(MediaActionBuilder.newUpdateMediaAction(media));
}

// do the same within the Post content itself
String postContentWithRestartedUploads =
AztecEditorFragment.restartFailedMediaToUploading(this, post.getContent());
post.setContent(postContentWithRestartedUploads);
mDispatcher.dispatch(PostActionBuilder.newUpdatePostAction(post));
if (processWithAztec) {
// do the same within the Post content itself
String postContentWithRestartedUploads =
AztecEditorFragment.restartFailedMediaToUploading(this, post.getContent());
post.setContent(postContentWithRestartedUploads);
mDispatcher.dispatch(PostActionBuilder.newUpdatePostAction(post));
}

// no retry uploading the media items
for (MediaModel media : mediaToRetry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.wordpress.android.util.helpers.MediaFile;

import java.util.ArrayList;
import java.util.Set;

public class MockEditorActivity extends AppCompatActivity implements EditorFragmentListener,
EditorDragAndDropListener {
Expand Down Expand Up @@ -57,6 +58,10 @@ public boolean onMediaRetryClicked(String mediaId) {
return true;
}

@Override
public void onMediaRetryAllClicked(Set<String> mediaIdSet) {
}

@Override
public void onMediaUploadCancelClicked(String mediaId) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;

public abstract class EditorFragmentAbstract extends Fragment {
public abstract void setTitle(CharSequence text);
Expand Down Expand Up @@ -182,6 +183,7 @@ public interface EditorFragmentListener {
void onAddPhotoClicked();
void onCapturePhotoClicked();
boolean onMediaRetryClicked(String mediaId);
void onMediaRetryAllClicked(Set<String> mediaIdSet);
void onMediaUploadCancelClicked(String mediaId);
void onMediaDeleted(String mediaId);
void onUndoMediaCheck(String undoedContent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@
import android.app.Activity;
import android.arch.lifecycle.LiveData;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.Spanned;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
Expand Down Expand Up @@ -124,10 +128,19 @@ public void onUploadMediaButtonClicked() {
public void onCapturePhotoButtonClicked() {
checkAndRequestCameraAndStoragePermissions();
}

@Override public void onRetryUploadForMediaClicked(int mediaId) {
showRetryMediaUploadDialog(mediaId);
}

@Override public void onCancelUploadForMediaClicked(int mediaId) {
showCancelMediaUploadDialog(mediaId);
}
},
new OnReattachQueryListener() {
@Override
public void onQueryCurrentProgressForUploadingMedia() {
updateFailedMediaState();
updateMediaProgress();
}
},
Expand Down Expand Up @@ -170,20 +183,108 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
}
}

public void resetUploadingMediaToFailed(Set<Integer> failedMediaIds) {
// get all media failed for this post, and represent it on tje UI
if (failedMediaIds != null && !failedMediaIds.isEmpty()) {
for (Integer mediaId : failedMediaIds) {
// and keep track of failed ids around
mFailedMediaIds.add(String.valueOf(mediaId));
}
}
}

private void updateFailedMediaState() {
for (String mediaId : mFailedMediaIds) {
mWPAndroidGlueCode.mediaFileUploadFailed(Integer.valueOf(mediaId));
}
}

private void updateMediaProgress() {
for (String mediaId : mUploadingMediaProgressMax.keySet()) {
mWPAndroidGlueCode.mediaFileUploadProgress(Integer.valueOf(mediaId),
mUploadingMediaProgressMax.get(mediaId));
}
}

private void checkAndRequestCameraAndStoragePermissions() {
if (PermissionUtils.checkAndRequestCameraAndStoragePermissions(this,
CAPTURE_PHOTO_PERMISSION_REQUEST_CODE)) {
mEditorFragmentListener.onCapturePhotoClicked();
}
}

private void showCancelMediaUploadDialog(final int localMediaId) {
// Display 'cancel upload' dialog
AlertDialog.Builder builder = new AlertDialog.Builder(
new ContextThemeWrapper(getActivity(), R.style.Calypso_Dialog_Alert));
builder.setTitle(getString(R.string.stop_upload_dialog_title));
builder.setPositiveButton(R.string.stop_upload_dialog_button_yes,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
if (mUploadingMediaProgressMax.containsKey(String.valueOf(localMediaId))) {
mEditorFragmentListener.onMediaUploadCancelClicked(String.valueOf(localMediaId));
// remove from editor
mEditorFragmentListener.onMediaDeleted(String.valueOf(localMediaId));
mWPAndroidGlueCode.clearMediaFileURL(localMediaId);
mUploadingMediaProgressMax.remove(localMediaId);
} else {
ToastUtils.showToast(getActivity(), R.string.upload_finished_toast).show();
}
dialog.dismiss();
}
});

builder.setNegativeButton(R.string.stop_upload_dialog_button_no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});

AlertDialog dialog = builder.create();
dialog.show();
}

private void showRetryMediaUploadDialog(final int mediaId) {
// Display 'retry upload' dialog
AlertDialog.Builder builder = new AlertDialog.Builder(
new ContextThemeWrapper(getActivity(), R.style.Calypso_Dialog_Alert));
builder.setTitle(getString(R.string.retry_failed_upload_title));
builder.setPositiveButton(R.string.retry_failed_upload_yes,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
boolean successfullyRetried = true;
if (mFailedMediaIds.contains(String.valueOf(mediaId))) {
successfullyRetried = mEditorFragmentListener.onMediaRetryClicked(String.valueOf(mediaId));
}
if (successfullyRetried) {
mFailedMediaIds.remove(String.valueOf(mediaId));
mUploadingMediaProgressMax.put(String.valueOf(mediaId), 0f);
mWPAndroidGlueCode.mediaFileUploadProgress(mediaId,
mUploadingMediaProgressMax.get(String.valueOf(mediaId)));
}
}
});

builder.setNeutralButton(R.string.retry_failed_upload_retry_all, new OnClickListener() {
@Override public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
mEditorFragmentListener.onMediaRetryAllClicked(mFailedMediaIds);
}
});

builder.setNegativeButton(R.string.retry_failed_upload_remove, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
mEditorFragmentListener.onMediaDeleted(String.valueOf(mediaId));
mWPAndroidGlueCode.clearMediaFileURL(mediaId);
}
});

AlertDialog dialog = builder.create();
dialog.show();
}

@Override
public void onPause() {
super.onPause();
Expand Down
6 changes: 6 additions & 0 deletions libs/editor/WordPressEditor/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,10 @@
<string name="stop_upload_dialog_button_yes">Yes</string>
<string name="stop_upload_dialog_button_no">No</string>

<string name="retry_failed_upload_title">Retry uploading?</string>
<string name="retry_failed_upload_yes">Retry</string>
<string name="retry_failed_upload_remove">Remove</string>
<string name="retry_failed_upload_retry_all">Retry all</string>


</resources>