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

How to pass List as Extra? #22

Closed
aartikov opened this issue Dec 27, 2016 · 5 comments
Closed

How to pass List as Extra? #22

aartikov opened this issue Dec 27, 2016 · 5 comments
Assignees
Milestone

Comments

@aartikov
Copy link

I want to pass List as Extra (MyType is Serializable). How can I do that?
I can use ArrayList instead of List, but I think that to use concreate implementation is not a good programming practice.

Could you please modify BundleWrapper, so it will support lists of serializable objects?

@FrantisekGazo
Copy link
Owner

Supporting just List would be tricky - e.g. if you initialized it with a custom implementation then you would expect to have it there after deserialization.

I could try to add a mechanism for custom serialization&deserialization of objects.

@FrantisekGazo FrantisekGazo self-assigned this Dec 27, 2016
@FrantisekGazo FrantisekGazo added this to the v2.6.0 milestone Dec 28, 2016
@FrantisekGazo
Copy link
Owner

FrantisekGazo commented Dec 29, 2016

@aartikov v2.6.0-beta1 is out.

Now you can specify your own Bundler implementation for any object field.
e.g. @Extra(MyListBundler.class) List<String> mList;

Same goes for @Arg and @State.

You can try it and give me feedback 😉

@aartikov
Copy link
Author

Nice! It works.

This is my ListBundler:

public class ListBundler implements Bundler<List> {
	private static final String KEY = "key";

	@Override
	@SuppressWarnings("unchecked")
	public void save(@Nullable List value, @NonNull Bundle state) {
		if(value == null || value instanceof Serializable) {
			state.putSerializable(KEY, (Serializable) value);
		} else {
			state.putSerializable(KEY, new ArrayList(value));
		}
	}

	@Nullable
	@Override
	public List restore(@NonNull Bundle state) {
		return (List)state.getSerializable(KEY);
	}
}

@FrantisekGazo
Copy link
Owner

Ok, I'll just change the package name to blade.Bundler and if I don't find anything else I'll release it as 2.6.0

@FrantisekGazo
Copy link
Owner

version 2.6.0 released

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

2 participants