Add support for Fragment factories to Henson
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.
We are open to suggestions, as we couldn't find any way to extend dart & henson in a useful and elegant way.
Le lun. 7 nov. 2016 17:55, Buttink [email protected] a écrit :
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.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/f2prateek/dart/issues/135, or mute the thread https://github.com/notifications/unsubscribe-auth/ABv33f-PRWUbfkCIgaX6n_WeVortzdOCks5q71f-gaJpZM4Krcqt .
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 fragment@InjectExtraint arg1;@InjectExtraint 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 https://github.com/f2prateek/dart/issues/135#issuecomment-263287648, 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 [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@InjectExtraint arg1;@InjectExtraint 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 https://github.com/f2prateek/dart/issues/135#issuecomment-263287648, 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 https://github.com/f2prateek/dart/issues/135#issuecomment-299269840, or mute the thread https://github.com/notifications/unsubscribe-auth/ABv33Xy8aCNxGxqM48wRsxRUCE63IZVxks5r2hiIgaJpZM4Krcqt .