Skip to content

Instantly share code, notes, and snippets.

@edisonw
Last active January 8, 2016 19:17
Show Gist options
  • Save edisonw/22e7ab35b57954591063 to your computer and use it in GitHub Desktop.
Save edisonw/22e7ab35b57954591063 to your computer and use it in GitHub Desktop.
End result:
You will get to make a service request like this:
mAppDelegate.execute(UserActions.loginAction().facebookToken(token).username(username).build());
And have these classes generated for you:
UserActions,
LoginActionsFactory,
LoginActivityEventListener
Usage:
Tag the action:
@AggregatedAnnotation( //Generates UserActions class
baseClass = ActionKey.class,
valueType = BaseUserAction.class,
group = ActionKey.User) //"UserActions"
@EventProducer(events = {LoginActionResult.class}) //Tags this producer with the events they post.
@FactoryWithVariables( //Generates the Factory that makes the request.
baseClass = ActionRequestBuilder.class,
variables = {
@FactoryVariable(name = LoginAction.EXTRA_FACEBOOK_TOKEN, kind = String.class)
})
public class LoginAction extends BaseUserAction {
//Processing...
}
Tag the requester/listener:
@EventListener(producers = { //Creates LoginActivityEventListener that implements a list of events from the list of producers.
LoginAction.class
})
public class LoginActivity extends BaseActivity {
final LoginActivityEventListener mListener = new LoginActivityEventListener() {
@Override
public void onEventMainThread(LoginActionResult event) {
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addListener(mListener);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment