Feature/fluxc media upload service multiple uploads reattach progress#5780
Conversation
…updates (reattach)
…y if content available
…to feature/fluxc-media-upload-service-multiple-uploads-reattach-progress
…nt or after view created for new posts - also clearing failed media ids from local array
…Content() then updating it in onMediaUploadProgress()
…gress when exiting it
…to feature/fluxc-media-upload-service-multiple-uploads-reattach-progress
…, to make upload progress visibility show accordingly
…, and passing the new post contents as a return value in the static method implementation in AztecEditorFragment
…g the list so we are sure to re-load posts once media are uploaded there
|
|
||
| public interface EditorMediaUploadListener { | ||
| void onMediaUploadSucceeded(String localId, MediaFile mediaFile); | ||
| void onMediaUploadSucceeded(String localId, EditorFragmentAbstract.MediaType mediaType, MediaFile mediaFile); |
There was a problem hiding this comment.
Adding an extra param here for the MediaType seems redundant since we're already getting that from the MediaFile, which we're also sending.
Could we make getEditorMimeType() a (static) method of EditorFragmentAbstract instead, and use that from AztecEditorFragment and from EditPostActivity? Then we can drop this parameter (we'll still need it in onMediaUploadFailed below though, I guess).
There was a problem hiding this comment.
(and thank you! nice improvement there)
| removeMediaFromPendingList(media); | ||
| } | ||
|
|
||
| private EditorFragmentAbstract.MediaType getEditorMimeType(boolean isVideo) { |
There was a problem hiding this comment.
Seems a bit weird to keep calling getEditorMimeType(mediaFile.getVideo() - it seems more natural to me to have getEditorMimeType(mediaFile), since that's what we're really doing (getting the media type of the media file).
|
I tested a variant of TEST B (background upload):
*The picture appears in the Here is the log: |
|
Confirming what @daniloercoli is seeing - though only if I enable 'Don't keep activities'. (You're using the visual editor in that screenshot btw @daniloercoli - this branch doesn't have async support for the visual editor, only Aztec.) |
| onUploadSuccess(event.media); | ||
| } | ||
| else { | ||
| AppLog.w(AppLog.T.MEDIA, "EDITPOSTACTIVITY: " + event.media.getId() + " - " + event.progress); |
There was a problem hiding this comment.
This shouldn't be a warning-level log. Also, is this log really necessary? We already generate quite a bit of logging per upload, with this there are three logs per tick:
05-05 08:27:02.034 31057-12701/org.wordpress.android.beta D/WordPress-API: Dispatching action: MediaAction-UPLOADED_MEDIA
05-05 08:27:02.082 31057-31057/org.wordpress.android.beta W/WordPress-MEDIA: EDITPOSTACTIVITY: 65 - 0.9653928
05-05 08:27:02.093 31057-31057/org.wordpress.android.beta D/WordPress-MEDIA: 65 - progressing 0.9653928
If they're helpful while working on async we could keep them but keep track that we should reduce them later - these logs make it into helpshift reports, and I think there's a size limit that can prevent earlier useful logs from being preserved.
There was a problem hiding this comment.
Thank you! was just added to guide my own work, ditched it in 0cd3bc9
Right! I'm using the old visual editor. |
That's weird. My devices are experiencing some weird issues today due to activities that are not kept. Also, I don't have I think we should move much of the code outside the activity, since adding images to the editor could consume a lot of memory, (not counting when the user has enabled the Note: I would encourage to not test the app on emulator or Nexus 6P ;) We should try to test media related improvements on less powerful devices. |
…ype from the EditorMediaUploadListener interface
|
@daniloercoli summarizing the findings from the issue you ran into and what Mario and I discussed:
At one point I misunderstood your steps, and looked at exiting the editor while media was uploading (rather than leaving the editor). Trying this again now I realize there is a bug there:
We should change @daniloercoli could you confirm that you don't have any issues in this branch if you use Aztec and exit the editor before backgrounding the app? |
Right! everything is working as expected when I use Aztec. |
| sleep(500); | ||
|
|
||
| ((EditorMediaUploadListener) mEditorFragment).onMediaUploadProgress(mediaId, count); | ||
| ((EditorMediaUploadListener) mEditorFragment).onMediaUploadProgress(mediaId, false, count); |
There was a problem hiding this comment.
Doesn't look like the false param should be here anymore (onMediaUploadProgress wasn't changed) - also in two more places in this class.
| for (Attributes attrs : content.getAllElementAttributes(uploadingPredicate)) { | ||
| String localMediaId = attrs.getValue("data-wpid"); | ||
| if (!TextUtils.isEmpty(localMediaId)) { | ||
| mUploadingMediaProgressMax.put(localMediaId, new Float(0)); |
There was a problem hiding this comment.
We can drop an unnecessary boxing here and make a tiny optimization by just using 0f instead of new Float(0) (also clears a lint warning).
| content.refreshText(); | ||
|
|
||
| mUploadingMedia.put(localMediaId, MediaType.IMAGE); | ||
| mUploadingMediaProgressMax.put(localMediaId, new Float(0)); |
There was a problem hiding this comment.
Same as above comment, can use 0f here.
| } | ||
| mFailedMediaIds.remove(localMediaId); | ||
| mUploadingMedia.put(localMediaId, mediaType); | ||
| mUploadingMediaProgressMax.put(localMediaId, new Float(0)); |
There was a problem hiding this comment.
Same as above comment, can use 0f here.
| content.refreshText(); | ||
|
|
||
| // first obtain the latest maximum | ||
| float maxProgressForLocalMediaId = mUploadingMediaProgressMax.get(localMediaId); |
There was a problem hiding this comment.
This can throw an NPE if the localMediaId doesn't exist in mUploadingMediaProgressMax (HashMap.get() will return a null Float, which will crash when unboxing into a float).
|
Alright @mzorz, did another full pass and went through all your cases. Left a few small comments for things I missed earlier - should be good to go after those are fixed 👍 |
…oad to avoid potential NPE thanks @aforcier
|
ok! ready again @aforcier 🙇 |
|
|
70483ab
into
feature/fluxc-media-upload-service-multiple-uploads

This PR makes the multiupload capabilities of the MediaUploadService reflect on the UI when going out of the Editor and back (and images in a Post are still being uploaded).
TEST A (plain old single file upload):
TEST B (background upload):
TEST C (background upload - reattach progress):
TEST D (multiple upload):
TEST E (background upload - multiple upload):
TEST F (background upload - multiple upload - reattach progress):
TEST G (multicancel):
Known Issues
(Planning to work on these on separate PRs)
Different working copies of PostModel
2.a) image A gets replaced with the remote one, and this gets saved into the DB
2.b) image B gets replaced with the remote one, and this gets saved into the DB
We end up having a post with image A local, and image B remote, because what was saved last is 2.b) with a copy of the post that had both local images only.
How to solve this?
We need a way to ensure that all images get saved / replacing the post content.
Fortunately, the service runs as long as there’s stuff enqueued for upload.
See #5858
Random issues / enhancements
The profiling is missing the stop calls(see #5860)if I start a draft and do nothing, get out of the editor, it gets saved (it probably shouldn’t, should delete the post entirely). (see Don't keep an empty draft #5861)Trashed post reappearing (snackbar / refresh race condition) #5862
cc @aforcier