-
Notifications
You must be signed in to change notification settings - Fork 89
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
Add support for Fragment factories to Henson #135
Comments
We are open to suggestions, as we couldn't find any way to extend dart & Le lun. 7 nov. 2016 17:55, Buttink [email protected] a écrit :
|
This can be done using the existing factory. Maybe it could be more elegant, but it's not so bad: // In the fragment
@InjectExtra
int arg1;
@InjectExtra
int arg2;
...
@Override
public void onAttach(Context context) {
super.onAttach(context);
Dart.inject(this, getActivity());
} // In the starting activity
getIntent().putExtras(Henson.with(this)
.gotoMyFragment()
.arg1(arg1)
.arg2(arg2)
.build());
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.container, new MyFragment())
.commit(); |
This leaves quite a few question : how to generate an intent for multiple
fragments ? How to know which activity contains which fragment ? How to
deal with fragments that may or may nit be there ?
Le lun. 28 nov. 2016 06:40, Johan Reitan <[email protected]> a
écrit :
… This can be done using the existing factory. Maybe it could be more
elegant, but it's not so bad:
// In the ***@***.*** ***@***.*** arg2;
...
@Overridepublic void onAttach(Context context) {
super.onAttach(context);
Dart.inject(this, getActivity());
}
// In the starting activity
getIntent().putExtras(Henson.with(this)
.gotoMyFragment()
.arg1(arg1)
.arg2(arg2)
.build());
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.container, new MyFragment())
.commit();
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#135 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABv33RZLR1wPfIYPcYCVrp0i5JZWRlaWks5rCuf1gaJpZM4Krcqt>
.
|
And how do you use the intent you have built ?
Le lun. 28 nov. 2016 07:35, Stéphane NICOLAS <[email protected]> a
écrit :
… This leaves quite a few question : how to generate an intent for multiple
fragments ? How to know which activity contains which fragment ? How to
deal with fragments that may or may nit be there ?
Le lun. 28 nov. 2016 06:40, Johan Reitan ***@***.***> a
écrit :
This can be done using the existing factory. Maybe it could be more
elegant, but it's not so bad:
// In the ***@***.*** ***@***.*** arg2;
...
@Overridepublic void onAttach(Context context) {
super.onAttach(context);
Dart.inject(this, getActivity());
}
// In the starting activity
getIntent().putExtras(Henson.with(this)
.gotoMyFragment()
.arg1(arg1)
.arg2(arg2)
.build());
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.container, new MyFragment())
.commit();
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#135 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABv33RZLR1wPfIYPcYCVrp0i5JZWRlaWks5rCuf1gaJpZM4Krcqt>
.
|
In the simplest cases, this works, but you're right, this is dangerous if I had several fragments. If multiple fragments have extras with the same name, this wouldn't work, since I'm putting the extras in the activity's intent. |
Henson support Intent builder. But, for Fragment we need Bundle instead. So, I think it need to improve for Fragment. I tested in version 2.0.2 and saw that builder for Fragment look so weird. public CategoryListFragment$$IntentBuilder(Context context) {
intent = new Intent(context, CategoryListFragment.class); // Intent for fragment?
}
public CategoryListFragment$$IntentBuilder.AllSet parentId(String parentId) {
bundler.put("parentId", parentId);
return new CategoryListFragment$$IntentBuilder.AllSet();
}
public class AllSet {
public Intent build() {
intent.putExtras(bundler.get());
return intent;
}
} |
Any update on this? |
We are very open to PRs about this. As I said, we never found a good &
useful way to do it.
2017-05-04 20:27 GMT+02:00 Rainer-Lang <[email protected]>:
… Any update on this?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#135 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABv33Xy8aCNxGxqM48wRsxRUCE63IZVxks5r2hiIgaJpZM4Krcqt>
.
|
I love removing boilerplate and having better code and Henson is really nice for Activites, but for Fragments you are still left making your own .create() static method or a factory. Henson supporting fragments would make errors like mismatching bundle strings a non issue and reduce all this code just to create the activity.
The text was updated successfully, but these errors were encountered: