Skip to content

Conversation

mzorz
Copy link
Contributor

@mzorz mzorz commented May 26, 2020

Builds on top of #11987

This PR implements the needed changes to listen to a StorySaveResult and then triggering the UploadService to upload the composed images.

For this, a new class is introduced, called StoryMediaSaveUploadBridge that is both a LifecycleObserver and a EditorMediaListener, which carries with this responsibility.

How it works

First, the StoryComposerActivity is now creating a backing Post, which will contain the story content in the format of a Gallery.

The post is instantiated and kept empty, given we won't populate its content until later when we know the media Ids for each of the saved story frames.

The StoryMediaSaveUploadBridge is registered as a LifeycleObserver of the Application class, and subscribes to EventBus StorySaveResult events in its onCreate() observer override.
When all of a Story's frames are successfully saved to disk (which is the responsibility of FrameSaveManager and FrameSaveService in the stories library), this class will then:

  • add each of the saved images as Media items to the WP Media Store (which will then be uploaded to the site). When these are created, we obtain a local mediaId for each (this is simply the id in the MediaStore).
  • the Post that was earlier created contains just a gallery shortcode for now (until we implement the actual Gutenberg story block) to demonstrate the functionality for alpha, and we use a placeholder with the localids, for example
[gallery type="slideshow" ids="placeholderLocalId3,placeholderLocalId4,placeholderLocalId5"]
  • the UploadService takes care of uploading the media. Once these have been uploaded, we obtain the remote MediaId (the actual mediaId field in FluxC's MediaStore) and the post content is updated by replacing the placeholders with each remoteId correspondingly, for example:
[gallery type="slideshow" ids="190,191,192"]
  • once media is finished uploading, the UploadService also takes care of uploading the corresponding Post.

  • in the case the user decides to abandon the Story creation screen without pubslishing, the backing Post will be discarded. Any frames saved to that point will remain as media in their device (not media in the WP libraries, just on their device as raw image / video files)

Error handling

  • if an error occurs while saving, the UploadService is never triggered. The Story won't be uploaded (and no new media will be created on the site's Media Library) until all of the frames are saved successfullly
  • once the Post is ready to upload and it's enqueued to upoload, the UploadService takes care of everything else (retrying, offline support etc) as per with any other regular Post.

Videos

Videos are not supported yet, given the Gallery only supports images. There's no code in this PR or in the stories library in general to prevent this, given it'd be just adding unnecessary work. If you add a video to a Story, and it gets saved correctly, etc. it will be uploaded to the site and added to the Gallery, but it won't show in the resulting Post.

To test:

  • create a story (only add text to your frames, not emoji for now)
  • tap PUBLISH
  • observe it gets saved, and then it gets uploaded
  • once it's published you'll be able to see it on the web. Tap on the published snackbar "VIEW" button if you'd like.

PR submission checklist:

  • I have considered adding unit tests where possible.
  • 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.

mzorz added 2 commits May 26, 2020 12:02
…ress class so we can trigger the UploadService from there
… payload to the FrameSaveService and get it back when a SaveResult is ready
@peril-wordpress-mobile
Copy link

peril-wordpress-mobile bot commented May 26, 2020

You can trigger optional UI/connected tests for these changes by visiting CircleCI here.

@peril-wordpress-mobile
Copy link

peril-wordpress-mobile bot commented May 26, 2020

You can test the changes on this Pull Request by downloading the APK here.

mzorz added 3 commits May 26, 2020 18:26
…ch of the StoryFrameItem composed frame files
…files and add them as Media and insert them into a Post, then upload
@mzorz mzorz added this to the 15.2 milestone May 28, 2020
Base automatically changed from feature/wp-stories-part6-mediapicker-wpmedia2 to feature/wp-stories-base June 19, 2020 13:30