Skip to content
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

getCurrentViewStateAsSerializable() returns soft copy (dynamic mutable state) #15

Open
lenhuy2106 opened this issue Jul 8, 2017 · 1 comment

Comments

@lenhuy2106
Copy link

Hello RiccardoMoro!

FreeDrawSerializableState#getCurrentViewStateAsSerializable()

returns

new FreeDrawSerializableState(mCanceledPaths, mPaths, getPaintColor(),
                getPaintAlpha(), getPaintWidth(), getResizeBehaviour(),
                mLastDimensionW, mLastDimensionH);

with mCanceledPaths, mPaths as pointers to respective arraylists, such that changes are represented both on the original and the copy.
If thats not intended behaviour, i would suggest returning hard copies.

Thanks for the hard work! Much love.
Huy

@lenhuy2106
Copy link
Author

lenhuy2106 commented Jul 8, 2017

I see there are lots of nested references.

Anyways, here's a hacky way to do it with gson-serialization:

    FreeDrawSerializableState copy(FreeDrawSerializableState state) {
        Gson gson = new Gson();
        return gson.fromJson(gson.toJson(state), FreeDrawSerializableState.class);
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant