Skip to content

Commit

Permalink
Use primitive type if field type is boxed.
Browse files Browse the repository at this point in the history
  • Loading branch information
yatatsu committed Jan 4, 2017
1 parent f50fa7f commit 4268798
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ static String getOperationName(TypeName target, Elements elements, Types types)
if (fieldTypes.containsKey(target)) {
return fieldTypes.get(target);
}
if (target.isBoxedPrimitive()) {
TypeName unboxed = target.unbox();
if (fieldTypes.containsKey(unboxed)) {
return fieldTypes.get(unboxed);
}
}

// Array
TypeMirror parcelable = elements.getTypeElement("android.os.Parcelable").asType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import java.lang.Boolean;
import java.lang.CharSequence;
import java.lang.Integer;
import java.lang.String;
import java.util.ArrayList;

Expand Down Expand Up @@ -50,6 +52,12 @@ public static void bind(ExampleActivity target, Bundle source) {
ParcelableConverter exampleData2Converter = new ParcelableConverter();
target.setExampleData2( (ExampleData) exampleData2Converter.original( source.getParcelable("exampleData2") ) );
}
if (source.containsKey("integerField")) {
target.integerField = (Integer) source.getInt("integerField");
}
if (source.containsKey("booleanField")) {
target.booleanField = (Boolean) source.getBoolean("booleanField");
}
}

public static void pack(ExampleActivity source, Bundle args) {
Expand Down Expand Up @@ -77,6 +85,12 @@ public static void pack(ExampleActivity source, Bundle args) {
ParcelableConverter exampleData2Converter = new ParcelableConverter();
args.putParcelable("exampleData2", exampleData2Converter.convert(source.getExampleData2()) );
}
if (source.integerField != null) {
args.putInt("integerField", source.integerField);
}
if (source.booleanField != null) {
args.putBoolean("booleanField", source.booleanField);
}
}

public static final class IntentBuilder {
Expand Down Expand Up @@ -130,6 +144,20 @@ public ExampleActivityAutoBundle.IntentBuilder exampleData2(ExampleData exampleD
return this;
}

public ExampleActivityAutoBundle.IntentBuilder integerField(Integer integerField) {
if (integerField != null) {
args.putInt("integerField", integerField);
}
return this;
}

public ExampleActivityAutoBundle.IntentBuilder booleanField(Boolean booleanField) {
if (booleanField != null) {
args.putBoolean("booleanField", booleanField);
}
return this;
}

public Intent build(Context context) {
Intent intent = new Intent(context, ExampleActivity.class);
intent.putExtras(args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ public class ExampleActivity extends AppCompatActivity {
@AutoBundleField(required = false, converter = ParcelableConverter.class)
ExampleData exampleData2;

@AutoBundleField(required = false)
Integer integerField;

@AutoBundleField(required = false)
Boolean booleanField;

String getName() {
return name;
}
Expand Down

0 comments on commit 4268798

Please sign in to comment.