-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Serializing Story in onSaveInstanceState, retrieving it in onCreate #435
Serializing Story in onSaveInstanceState, retrieving it in onCreate #435
Conversation
You can test the changes on this Pull Request by downloading the APK here. |
… so initializer gets run in StorySerializerUtils
…he screen with the selected frame when coming back from serialized state
… we can update the working area rect to adjust multitouchlistener workarea even after adding deserialized views
…edia picker, let onStoryFrameSelected do the handling
…ion, but cancelling them when adding images from the picker as its taken care of by updateBackgroundSurfaceUIWithStoryFrame
…he camera before the surface is ready
…VideoWithSurfaceSafeguard() to sync and wait for Surface to be ready before attempting camera live preview / video playing, and removed artificial wait time
…oach now and wait for the BackgroundSurfaceManagerReadyListener listener to trigger camera / video playing
stories/src/main/java/com/wordpress/stories/compose/story/StoryViewModel.kt
Show resolved
Hide resolved
…ays check TextureSurface availability from a single source of truth, ditched surfaceReady boolean class member which could hold non up-to-date information
Hi @mzorz quick question for |
This is interesting, I wonder whether I described the case I wanted to test after all! Let me look into it and get back here. Please continue with the other cases for now 🙏 |
This is happening on my Google Pixel 4 XL, Android 10 while testing Case C. When Reproduction steps:
Note: This can also be reproduced on the emulator as well 🙏 |
hey @jd-alexander re: this comment sorry for that, edited the PR description now with the following: EDIT: N/A, this PR doesn't contain code to address this situation in particular (we care for serializing / deserializing a Story, there's no code in here to keep the live preview state). I think I had my test cases listed on the side and then copied them as they were. 🙏 |
okay no problem 😄 |
Hey @mzorz not sure if I have ever shown you this or if there's an issue tracking it but noting here since it occurred during testing; the video becomes stretched at times when putting and bringing the app out of the foreground. Let me know what you think. The reproduction steps are just adding a video as a story frame and then doing the app in and out of the foreground to catch it. |
The upload icon is going to be removed shortly as per #442 given it's causing some other navigation issues. The only way to call the picker should be by tapping the + icon on the story slide selector once you have at least one image selected.
Here's a gif showing it works for me on a Pixel 3 emu (API 29), would love to see if it's the same for you 🙏 Please note though, this PR does not address anything such as media picker selection (also remember the picker is externally provided as well), but good to check for overall healthiness 👍 |
Interesting indeed 🤔 ; just to make sure I'm getting this correctly, can you verify these are the steps to make the bug occur?:
Is this what happened? EDIT: possibly related: #200 |
Thanks for the clarification on the #435 (comment) I followed the steps you provided and got the desired results. I also remember the discussion with Megs about removing the upload icon so thank you for pointing that out 🙏 |
So for #435 (comment) the steps did make the bug occur, for more context the video didn't continue to play stretched. It only happened for about a second and then it went back to normal so the issue is probably related. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for these changes @mzorz apart from the other unrelated bug I noticed, all the tests passed and the changes in the code here looks solid. I didn't find any issues. LGTM 🚢
Gave this a spin as well, it's working great! I also tried the same cases from the WPAndroid branch, and tested publishing immediately after the activity is re-created with no issues. Incidentally, I did notice that the upload-as-gallery fallback on non-alpha sites seems to be broken (posts are uploaded as empty drafts for me, no media no gallery block). I'll send you a note about that. |
Wanted to follow up on this - I think this is expected - the effect is that you see a "screenshot" of the Activity in the recents list, and it's zoomed in as you tap on it until it fills the screen, then the actual Activity goes through all the lifecycle methods for startup and starts running. On the Samsung J2 I have here I can even see some pixelation on that screenshot (which is performed at the system level), until the actual rendering takes control. |
Tracked on #450 |
Builds on top of #414
This PR aims at utilizing the kotlinx.serialization framework introduced in #414 to serialize/deserialize the WIP Story currently living in the StoryRepository when the Activity enters a paused state and gets its onSaveInstanceState lifecycle method called.
General
This PR basically serializes and saves the current Story state in
onSaveInstanceState()
, and inflates it back inonCreate()
whensavedInstanceState != null
, initializing and populating theComposeLoopFrameActivity
,BackgroundSurfaceManager
,StoryViewModel
, andStoryRepository
back from the previously serialized state.BackgroundSurfaceManager & related changes
When the Acivity is re-created, we need to wait for Surface initialization properly before we can draw video / camera live preview on it. For that we're now making use of the BackgroundSurfaceManagerReadyListener, and there are also some other related changes as followsL
isVideoPlayerVisible
for proper video handler fragment initialization)launchCameraPreviewWithSurfaceSafeguard()
andshowPlayVideoWithSurfaceSafeguard
(see1a70555 and later addition 436946a), if the a video player or live camera preview needs be started but surface is not ready yet, we just turn a flag and retrieve it once the surface is ready to play. This is also an improvement over the past mechanism where we had an artificial wait of 500ms to launch the players. It's now more tightly done (no needless wait if it's ready before 500ms) and proves to have a consistent behavior across devices and execution conditions.
Serializers
The serializers per se live in
StorySerializerUtils
, but there's not much there. Annotations and custom serializers have been added to the following classes:This last one's possible values
SaveSuccess
andSaveError
inherit from two classes (its parent class are naturallySaveResultReason
, and alsoParcelable
given we need that to include it in intent bundles and EventBus). As such, the serializer needs to be declared a Module that tells it which actual serializer to use when it finds an instance of a final class (see https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/polymorphism.md#basic-case). In particular this is also a sealed class, which would otherwise not need a custom module since version 0.14 (https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/polymorphism.md#sealed-classes) of the kotlinx-serializaiton plugin (given sealed classes are known of all its possible values at compile time), but given we're also making itParcelable
(and hence inherits from more than one class) we need to use thepolymorphic()
constructor for the serializer and pass each specialized serializer for each of the sealed class final types.Other
buildViewFromAddedViewInfo()
added in the previous PR we forgot to add the touch listener so added views that are reconstructed from metadata (AddedViewInfo) can also be handled with touch. (cac37be)To Test
CASE A: camera live preview1. on settings -> advanced -> developer option, setDon't keep activities
to ON2. tap the + icon3. observe the camera preview mode appears4. send the app to the background5. return to the app6. observe the camera live preview is shown correctly and you can capture a still image or a video.EDIT: N/A, this PR doesn't contain code to address this situation in particular (we care for serializing / deserializing a Story, there's no code in here to keep the live preview state)
CASE B: remember a Story with added views, with static image being selected
Don't keep activities
to ONCASE C: remember a Story with added views, with static image being selected, added from the Media Picker.
Don't keep activities
to ONYou should be able to do this as many times as you want.
CASE D: remember a Story and trigger video playing as soon as it's available
Don't keep activities
to ONCASE E: added views on video
CASE F: many items
CASE G: use WPAndroid