This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AndroidSampleApp extends Application implements HasActivityInjector { | |
@Inject | |
DispatchingAndroidInjector<Activity> activityDispatchingAndroidInjector; | |
@Override | |
public void onCreate() { | |
super.onCreate(); | |
//simplified | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Module | |
public class MainActivityModule { | |
@Provides | |
MainView provideMainView(MainActivity mainActivity){ | |
return mainActivity; | |
} | |
@Provides | |
MainPresenter provideMainPresenter(MainView mainView, ApiService apiService){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Subcomponent(modules = MainActivityModule.class) | |
public interface MainActivityComponent extends AndroidInjector<MainActivity>{ | |
@Subcomponent.Builder | |
abstract class Builder extends AndroidInjector.Builder<MainActivity>{} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Module(subcomponents = { | |
MainActivityComponent.class, | |
DetailActivityComponent.class}) | |
public class AppModule { | |
@Provides | |
@Singleton | |
Context provideContext(Application application) { | |
return application; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component(modules = { | |
AndroidInjectionModule.class, | |
AppModule.class, | |
ActivityBuilder.class}) | |
public interface AppComponent { | |
@Component.Builder | |
interface Builder { | |
@BindsInstance Builder application(Application application); | |
AppComponent build(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Module | |
public abstract class ActivityBuilder { | |
@Binds | |
@IntoMap | |
@ActivityKey(MainActivity.class) | |
abstract AndroidInjector.Factory<? extends Activity> bindMainActivity(MainActivityComponent.Builder builder); | |
@Binds | |
@IntoMap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JavaFile.builder("com.annotationsample", navigatorClass.build()) | |
.build() | |
.writeTo(filer); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TypeSpec.Builder navigatorClass = TypeSpec | |
.classBuilder("Navigator") | |
.addModifiers(Modifier.PUBLIC, Modifier.FINAL); | |
for (Map.Entry<String, String> element : activitiesWithPackage.entrySet()) { | |
String activityName = element.getKey(); | |
String packageName = element.getValue(); | |
ClassName activityClass = ClassName.get(packageName, activityName); | |
MethodSpec intentMethod = MethodSpec | |
.methodBuilder(METHOD_PREFIX + activityName) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for (Element element : roundEnvironment.getElementsAnnotatedWith(NewIntent.class)) { | |
if (element.getKind() != ElementKind.CLASS) { | |
messager.printMessage(Diagnostic.Kind.ERROR, "Can be applied to class."); | |
return true; | |
} | |
TypeElement typeElement = (TypeElement) element; | |
activitiesWithPackage.put( | |
typeElement.getSimpleName().toString(), |