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 public keys to FrBuilder class #71

Open
Kolyall opened this issue Sep 16, 2016 · 4 comments
Open

Add public keys to FrBuilder class #71

Kolyall opened this issue Sep 16, 2016 · 4 comments

Comments

@Kolyall
Copy link

Kolyall commented Sep 16, 2016

for exampe if your Fragment is :

@FragmentWithArgs
public class Body extends Fragment {
    @Arg String request;
    @Arg Integer value;

then create in Builder class this:

public final class BodyBuilder {
    public static final String ARG_REQUEST = "request";
    public static final String ARG_VALUE = "value";
  private final Bundle mArguments = new Bundle();

  public BodyBuilder(...) {

    mArguments.putString(ARG_REQUEST, request);

    mArguments.putInt(ARG_VALUE, userPointsValue);
  }

@sockeqwe
Copy link
Owner

What's the benefit?

@Kolyall
Copy link
Author

Kolyall commented Sep 16, 2016

for example
you have FirstActivity :

class FirstActivity extends Activity{
@Override
    protected void onCreate(Bundle savedInstanceState) {
     Intent intent = new Intent(this, SecondActivity.class)  
 intent.putExtra(BodyBuilder.ARG_REQUEST,"a string");
 intent.putExtra(BodyBuilder.ARG_VALUE,111);
startActivity(intent );
}
}

your SecondActivity:

class SecondActivity extends Activity{
@Override
    protected void onCreate(Bundle savedInstanceState) {
     Intent data = getIntent();
String request=  data.getStringExtra(BodyBuilder.ARG_REQUEST);
Integer value =  data.getIntExtra(BodyBuilder.ARG_VALUE);
setFragment(request, value);
}
}

OR
you have FirstActivity :

class FirstActivity extends Activity{
@Override
    protected void onCreate(Bundle savedInstanceState) {
     Intent intent = new Intent(this, SecondActivity.class)  
 Bundle fragmentArgs = new Bundle();
            fragmentArgs.putString(BodyBuilder.ARG_REQUEST,"a string");
            fragmentArgs.putInt(BodyBuilder.ARG_VALUE,111);
            intent.putExtra("dataForFragment",fragmentArgs);
startActivity(intent );
}
}

your SecondActivity:

class SecondActivity extends Activity{
@Override
    protected void onCreate(Bundle savedInstanceState) {
     Bundle dataBundle = getIntent().getBundleExtra("dataForFragment");
 Body body = BodyBuilder.newBody(dataBundle);

}
}

@sockeqwe
Copy link
Owner

I consider creating bundle for the arguments by your own as bad practice, because by instantiating it by yourself you can't be sure that all required arguments are in the bundle.

Maybe it's worth to thinking about adding a Builder.toBundle() method and a new Builder(Bundle) constructor, but again, I think you loose a lot of typesafety and checks that are provided by the builder ...

@Kolyall
Copy link
Author

Kolyall commented Sep 16, 2016

I just wanted to merge your lib with this one for activity:
https://github.com/emilsjolander/IntentBuilder

by using some like this:

@IntentBuilder
public class SecondActivity extends Activity {
    @Extra Bundle dataBundle;
    @Extra Bundle dataBundle2;
protected void onCreate(Bundle savedInstanceState) {

      Body body = BodyBuilder.newBody(dataBundle);
      Body2 body2 = Body2Builder.newBody2(dataBundle2);
}

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