Skip to content

Instantly share code, notes, and snippets.

@babedev
Last active January 5, 2017 08:51
Show Gist options
  • Save babedev/f4d63b789881580cc3c03cf1b0e64491 to your computer and use it in GitHub Desktop.
Save babedev/f4d63b789881580cc3c03cf1b0e64491 to your computer and use it in GitHub Desktop.
private void generateActivity() throws IOException {
MethodSpec onCreate = MethodSpec.methodBuilder("onCreate")
.addAnnotation(Override.class)
.addModifiers(Modifier.PUBLIC)
.returns(void.class)
.addParameter(Bundle.class, "savedInstanceState")
.addComment("TODO setContentView()")
.addStatement("mPresenter = new $T()", getPresenterType())
.addStatement("mPresenter.attachView(this)")
.build();
TypeSpec mvpActivity = TypeSpec.classBuilder(featureName + "Activity")
.superclass(Activity.class)
.addSuperinterface(getViewType())
.addField(getPresenterType(), "mPresenter", Modifier.PRIVATE)
.addMethod(onCreate)
.build();
JavaFile javaFile = JavaFile.builder(packageName + "." + featureName.toLowerCase(), mvpActivity)
.build();
File file = new File("app/src/main/java");
javaFile.writeTo(file);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment