Skip to content

Instantly share code, notes, and snippets.

View dlemures's full-sized avatar

Daniel Molinero dlemures

View GitHub Profile
@dlemures
dlemures / ktp.kt
Last active July 2, 2019 21:57
KTP
// Root
class FooActivity {
val bar: Bar by Inject()
fun onCreate(state) {
KTP.openScope("Scope Name")
.installModule(MyModule())
.inject(this);
}
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Dart.inject(this, intent.getExtras());
}
public class SmoothieMakerTest {
@Rule public EasyMockRule mocks = new EasyMockRule(this);
@TestSubject private SmoothieMaker smoothieMakerUnderTest = new SmoothieMaker();
@Mock private Blender mockBlender;
@Mock private Freezer mockFreezer;
@After
public void tearDown() throws Exception {
ToothPick.reset();
@Inject Lazy<SmoothieMaker> smoothieMaker;
smoothieMaker.get().makeSmoothie();
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;
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;
public SmoothieShop() {
Scope scope = Toothpick.openScope("SmoothieShop");
Toothpick.inject(this, scope);
...
}
...
class SmoothieMaker {
@Inject Blender blender;
@Inject Freezer freezer;
...
}
Intent intent = Henson.with(context)
.gotoDetailActivity()
.itemId(selectedItem.id)
.shouldShowMap(true)
.build();
startActivity(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);
...
}