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 transport information for OnClickWrappers? #24

Closed
Zordid opened this issue Feb 10, 2014 · 6 comments
Closed

How to transport information for OnClickWrappers? #24

Zordid opened this issue Feb 10, 2014 · 6 comments

Comments

@Zordid
Copy link

Zordid commented Feb 10, 2014

Hi John!
Well, now I see how you want to "restore" OnClickListeners for Buttons in Toasts - using the Wrapper classes and a tag. But your example case is too simple: how should I transport information to my potentially restored OnClickListener between orientation changes? In your demo it is clear that the "potentially destructive action" which gives a toast with a button cannot use any context data, like what should restored when the button is clicked!
...that is one reason why I do not like the restoring of toasts at all!
In my use cases, I create an OnClickListener class that inherently "knows" which data is to be worked on, just because I use inner classes. That cannot be done using your model at all. What is needed is a way to maybe also give a bundle to the Wrapper for each use of the toast - and that will have to be restored on orientation change as well...
See what I mean?
Thanks!
Olaf

@JohnPersano
Copy link
Owner

Olaf,
Excellent idea! I worked out a solution and tested it briefly, here's how it will work.

I added a second setOnClickWrapper() method in which I have added a Parcelable parameter. This new parameter will be used as follows:

Bundle bundle = new Bundle();
bundle.putInt("test", someNumber);

superActivityToast.setOnClickWrapper(onClickWrapper, bundle);

I made an interface class which is basically another OnClickListener class except that it spits out the Parcelable object along with a View. The new onClick() method will be as follows:

@OverRide
public void onClick(View view, Parcelable token) {

Bundle bundle = (Bundle) token;
int test = bundle.getInt("test");

Log.i(TAG, String.vaueOf(test); 

}

So the new OnClickListener will support a Parcelable object that will be saved on orientation change and can be accessed via the onClick() method. What do you think of that solution?

Keep the suggestions coming!

  • John

@Zordid
Copy link
Author

Zordid commented Feb 10, 2014

John, that is exactly what I had in mind, prefect. :)
Great working these things out together!
I think finally, I can get used to persisting toasts! ;)

@JohnPersano
Copy link
Owner

Excellent, let me polish it up and test it over the next few days and I'll push it to the master branch.

Thanks for the suggestion!

  • John

@JohnPersano
Copy link
Owner

Olaf,

I pushed the commit to the develop branch. The ExampleUndoBar class has also been updated. Check it out when you get a chance and let me know if that's the best way to do it.

Thanks,

  • John

@Zordid
Copy link
Author

Zordid commented Feb 16, 2014

Hey John, I just checked the new changes - works as expected and I like
it! :-)
Cheers,
Olaf

@JohnPersano
Copy link
Owner

This has been addressed in the develop branch. Thanks!

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