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

Add support for Fragment factories to Henson #135

Open
dmstocking opened this issue Nov 7, 2016 · 8 comments
Open

Add support for Fragment factories to Henson #135

dmstocking opened this issue Nov 7, 2016 · 8 comments

Comments

@dmstocking
Copy link

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.

@stephanenicolas
Copy link
Collaborator

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
#135, or mute the thread
https://github.com/notifications/unsubscribe-auth/ABv33f-PRWUbfkCIgaX6n_WeVortzdOCks5q71f-gaJpZM4Krcqt
.

@joharei
Copy link

joharei commented Nov 28, 2016

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();

@stephanenicolas
Copy link
Collaborator

stephanenicolas commented Nov 28, 2016 via email

@stephanenicolas
Copy link
Collaborator

stephanenicolas commented Nov 28, 2016 via email

@joharei
Copy link

joharei commented Nov 28, 2016

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.

@talenguyen
Copy link

talenguyen commented Mar 7, 2017

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;
    }
  }

@Rainer-Lang
Copy link

Any update on this?

@stephanenicolas
Copy link
Collaborator

stephanenicolas commented May 5, 2017 via email

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

5 participants