use of dagger.ObjectGraph in project u2020 by JakeWharton.
the class OauthService method onCreate.
@Override
public void onCreate() {
super.onCreate();
ObjectGraph appGraph = Injector.obtain(getApplication());
appGraph.inject(this);
}
use of dagger.ObjectGraph in project u2020 by JakeWharton.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LayoutInflater inflater = getLayoutInflater();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// Remove the status bar color. The DrawerLayout is responsible for drawing it from now on.
setStatusBarColor(getWindow());
}
// Explicitly reference the application object since we don't want to match our own injector.
ObjectGraph appGraph = Injector.obtain(getApplication());
appGraph.inject(this);
activityGraph = appGraph.plus(new MainActivityModule(this));
ViewGroup container = viewContainer.forActivity(this);
inflater.inflate(R.layout.main_activity, container);
ButterKnife.bind(this, container);
drawerLayout.setStatusBarBackgroundColor(statusBarColor);
drawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
drawer.setNavigationItemSelectedListener(item -> {
switch(item.getItemId()) {
case R.id.nav_search:
Toast.makeText(MainActivity.this, "Search!", LENGTH_SHORT).show();
break;
case R.id.nav_trending:
Toast.makeText(MainActivity.this, "Trending!", LENGTH_SHORT).show();
break;
default:
throw new IllegalStateException("Unknown navigation item: " + item.getTitle());
}
drawerLayout.closeDrawers();
return true;
});
inflater.inflate(R.layout.trending_view, content);
}
use of dagger.ObjectGraph in project mortar by square.
the class ObjectGraphServiceTest method getActivityScopeWithOneModule.
@Test
public void getActivityScopeWithOneModule() {
MortarScope root = createRootScope(ObjectGraph.create(new AppleModule()));
String name = Bagel.class.getName();
MortarScope activityScope = root.buildChild().withService(SERVICE_NAME, create(root, new BagelModule())).build(name);
ObjectGraph objectGraph = getObjectGraph(activityScope);
assertThat(objectGraph.get(HasApple.class).string).isEqualTo(Apple.class.getName());
assertThat(objectGraph.get(HasBagel.class).string).isEqualTo(Bagel.class.getName());
try {
objectGraph.get(HasCarrot.class);
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
// pass
}
}
use of dagger.ObjectGraph in project mortar by square.
the class ObjectGraphServiceTest method requireGrandchildWithMoreModules.
@Test
public void requireGrandchildWithMoreModules() {
MortarScope root = createRootScope(ObjectGraph.create(new AppleModule()));
MortarScope activityScope = root.buildChild().withService(SERVICE_NAME, create(root, new BagelModule())).build("activity");
MortarScope child = activityScope.buildChild().withService(SERVICE_NAME, create(activityScope, new CarrotModule())).build("child");
MortarScope grandchild = child.buildChild().withService(SERVICE_NAME, create(child, new DogfoodModule(), new EggplanModule())).build("grandchild");
ObjectGraph objectGraph = getObjectGraph(grandchild);
assertThat(objectGraph.get(HasApple.class).string).isEqualTo(Apple.class.getName());
assertThat(objectGraph.get(HasBagel.class).string).isEqualTo(Bagel.class.getName());
assertThat(objectGraph.get(HasCarrot.class).string).isEqualTo(Carrot.class.getName());
assertThat(objectGraph.get(HasDogfood.class).string).isEqualTo(Dogfood.class.getName());
assertThat(objectGraph.get(HasEggplant.class).string).isEqualTo(Eggplant.class.getName());
try {
objectGraph.get(String.class);
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
// pass
}
}
use of dagger.ObjectGraph in project mortar by square.
the class ObjectGraphServiceTest method requireGrandchildWithNoModules.
@Test
public void requireGrandchildWithNoModules() {
MortarScope root = createRootScope(ObjectGraph.create(new AppleModule()));
MortarScope activityScope = root.buildChild().withService(SERVICE_NAME, create(root, new BagelModule())).build("activity");
MortarScope child = activityScope.buildChild().withService(SERVICE_NAME, create(activityScope, new CarrotModule())).build("child");
MortarScope grandchild = child.buildChild().build("grandchild");
ObjectGraph objectGraph = getObjectGraph(grandchild);
assertThat(objectGraph.get(HasApple.class).string).isEqualTo(Apple.class.getName());
assertThat(objectGraph.get(HasBagel.class).string).isEqualTo(Bagel.class.getName());
assertThat(objectGraph.get(HasCarrot.class).string).isEqualTo(Carrot.class.getName());
try {
objectGraph.get(String.class);
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
// pass
}
}
Aggregations