Skip to content

Instantly share code, notes, and snippets.

View dlemures's full-sized avatar

Daniel Molinero dlemures

View GitHub Profile
@dlemures
dlemures / DetailActivityV1.java
Last active May 5, 2016 19:04
DealActivity V1 for Henson article
public class DetailActivity extends Activity {
public static final String EXTRA_ITEM_ID = "extra.item_id";
public static final String EXTRA_SHOW_MAP = "extra.show_map";
private String itemId;
private boolean shouldShowMap;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@dlemures
dlemures / IntentCreationV1.java
Last active May 5, 2016 19:04
Intent creation V1 for Henson article
Intent intent = new Intent(context, DetailActivity.class);
intent.putExtra(EXTRA_ITEM_ID, selectedItem.id);
intent.putExtra(EXTRA_SHOW_MAP, true);
startActivity(intent);
public class IntentFactory {
public Intent newDetailActivityIntent(Context context, String itemId, boolean showMap) {
Intent intent = new Intent(context, DetailActivity.class);
intent.putExtra(EXTRA_ITEM_ID, itemId);
intent.putExtra(EXTRA_SHOW_MAP, showMap);
return intent;
}
...
}
public class DetailActivity extends Activity {
@InjectExtra String itemId;
@Nullable @InjectExtra boolean shouldShowMap;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Dart.inject(this);
...
}
Intent intent = Henson.with(context)
.gotoDetailActivity()
.itemId(selectedItem.id)
.shouldShowMap(true)
.build();
startActivity(intent);
class SmoothieMaker {
@Inject Blender blender;
@Inject Freezer freezer;
...
}
class SmoothieShop {
@Inject SmoothieMaker smoothieMaker1;
@Inject SmoothieMaker smoothieMaker2;
public SmoothieShop() {
Scope scope = Toothpick.openScope("SmoothieShop");
Toothpick.inject(this, scope);
...
}
...
bind(Blender.class).to(JarBlender.class); // Blender -> JarBlender
bind(Freezer.class).to(new Freezer()); // Freezer -> Freezer instance
public class SmoothieShopModule extends Module {
public SmoothieShopModule() {
bind(Blender.class).to(JarBlender.class); // Blender -> JarBlender
bind(Freezer.class).to(new Freezer()); // Freezer -> Freezer instance
}
}
class SmoothieShop {
@Inject SmoothieMaker smoothieMaker1;
@Inject SmoothieMaker smoothieMaker2;
@Inject Lazy<SmoothieMaker> smoothieMaker;
smoothieMaker.get().makeSmoothie();