-
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
Serialization part 1: implement kotlinx-serializable, use serialized AddedViews #414
Serialization part 1: implement kotlinx-serializable, use serialized AddedViews #414
Conversation
You can test the changes on this Pull Request by downloading the APK here. |
… to hold serializable data for Views
…g marked Transient (wrong Transient annotation being imported)
…e-created from AddedViewInfo
…ws (font size, color, text)
…rom story slide switching)
stories/src/main/java/com/wordpress/stories/compose/ComposeLoopFrameActivity.kt
Outdated
Show resolved
Hide resolved
colorCodeTextView: Int, | ||
textTypeface: Typeface? = null, | ||
fontSizeSp: Float = 18f, | ||
isViewReadd: Boolean = false |
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.
should this be isViewReady
? Not sure. Just checking :)
isViewReadd: Boolean = false | |
isViewReady: Boolean = false |
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.
it's intended - is this view being re-add
ed.
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.
Okay understood. I get it now. Do you think it could be renamed to isViewBeingReadded
? LMK. because at first glance I thought it was a typo 😅
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.
sure thing! done in 3713a9b :)
photoeditor/src/main/java/com/automattic/photoeditor/views/added/AddedView.kt
Outdated
Show resolved
Hide resolved
stories/src/main/java/com/wordpress/stories/compose/frame/FrameSaveManager.kt
Show resolved
Hide resolved
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.
I left a few comments @mzorz but overall this is amazingly done! I have learned so much from reviewing this PR. I will be doing a second pass and running some tests soon!
stories/src/main/java/com/wordpress/stories/compose/story/StorySerializerUtils.kt
Outdated
Show resolved
Hide resolved
photoeditor/src/main/java/com/automattic/photoeditor/views/added/AddedViewList.kt
Outdated
Show resolved
Hide resolved
photoeditor/src/main/java/com/automattic/photoeditor/views/added/AddedView.kt
Outdated
Show resolved
Hide resolved
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 I left a few minor comments but this is good to go LGTM 🚢
Addressed your comments, thanks a lot for these suggestions @jd-alexander 🙇 - ready for another go 👍 |
I was a bit worried about this in case those int values worked like string resources, which IIRC shouldn't be relied on for something like serialization since they are not necessarily the same from build to build, and was going to suggest we store the color value in hexadecimal form. However, after going down an unironically fun rabbithole, it looks like we're okay. It turns out that's just how Integer.toHexString(-490240) // "fff88500"
// And to go back
"fff88500".toLong(16).toInt() // -490240 Apparently there are a few different ways Android might represent the number with some color space changes as of Android O, but I tried pre-Android O and the representation seems to be the same. The risk then would be that someone updates their version of Android and the representation changes (so the serialized version we stored doesn't match what is expected), but that seems a bit far-fetched since everything seems to work in recent Android versions. And if we did run into a weird issue here we can add some extra logic to handle that exceptional representation. So none of this is important, just sharing 😀 It's also something for me to think about when I add typeface support, since that may be a case where we need to store our own identifier instead of the integer resource value Android will probably be using to represent a typeface. |
I'm still planning to give the code a functional test as well, but something on my mind from looking things over: what support does |
Applied the gist and gave this a try, working well! I'll try out part 2 and the WPAndroid changes next week. I did notice that sometimes added views jump around slightly if the last action on them is a resize before they're reloaded: https://cloudup.com/cE-45g0j-zB But it's not a big deal. |
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 @mzorz I did the second pass. Good work. LGTM 🚢
Thanks for your reviews @aforcier @jd-alexander 🙇 @aforcier loved your investigation re: representation of some values there :), I think you have a point that these constants may change if you update the OS, and even more we'll have to come up with a more robust representation that can remain objective throughout devices / OS versions / platforms in the future for sure if we want to share the serialized data. Agreed on the typeface support, we'd certainly want to have that under control so better come up with our own way to identify the one being used 👍 Also saw the video with the small glitch with added view positioning, thanks for noting it 👍 |
Re: this #414 (comment)
Good question @aforcier 💯 I haven't seen "native" support for versioning in [...] Looking a bit further it seems we can choose the format in which things are stored, these are already supported:
Also some others can be installed (status for some is experimental):
Did some digging over these few formats, seems to throw the notion that versioning handling is (unsurprisingly) controversial:
The only one that we know supports versioning by the format itself is, well, XML, but it kind of defeats the purpose as we'd need to deal with the other complexities it brings. So basically I think we'll need to rollout our own versioning scheme, the simplest path forward may be at least to have a flavor of Let me know your thoughts @aforcier 👍 |
Really nice exploration @mzorz! I agree with your conclusion, let's rollout our own scheme, starting the the bare minimum. A |
Good! tracked here #452 |
First part in the path to close #393 and related.
This PR implements Kotlinx's serialization plugin so we can save / inflate current state of things for a given Story that is in memory in the StoryRepository, which is generally work in progress for the time being.
This will also set the base work for supporting Story projects in the future.
This PR provides a means for
AddedViews
to be serialized and then recreated fromAddedViewInfo
serialized class, which contains properties that are useful to re-place the same views on a given Story slide each time (scale, rotation, translation, and text information such as text, calculated fontSize, and color).Example:
Some notes on this:
Why this is important
What this effectively means is, we can now keep the state for AddedViews (emoji, text) and be able to re-create them on the fly from this serialized format 🎉 👍
Notes
https://github.com/Kotlin/kotlinx.serialization
that we might want to use, but it needs Kotlin Version 1.3.70 (we're still on 1.3.61 on WPAndroid) and it is incompatible with the previous version. FWIW, our stuff still works on version v.0.14.0 of the library so, sticking to that one for now.https://github.com/Kotlin/kotlinx.serialization/releases/tag/v0.14.0
To test
Here's a video of the app with this gist applied, showing the AddedViews get re-created correctly when tapping on different frames/slides on the frame selector, in https://cloudup.com/cIO-aA3b7ek
ToDo