Skip to content

Instantly share code, notes, and snippets.

View lukaspili's full-sized avatar

Lukasz Piliszczuk lukaspili

View GitHub Profile
/*global define*/
define([
'underscore',
'backbone',
'models/client'
], function (_, Backbone, ClientModel) {
'use strict';
var ClientCollection = Backbone.Collection.extend({
@Module
public class ApiModule {
private User user;
public ApiModule(User user) {
this.user = user;
}
@Provides
public class DemortarApp extends Application {
private DataAccessComponent component;
public static DemortarApp getDemortarApp(Context context) {
return (DemortarApp) context.getApplicationContext();
}
@Override
public void onCreate() {
public class SimpleActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
DataAccessComponent component = DemortarApp.getDemortarApp(this)
.getComponent();
Api api = component.api();
public class SimpleActivity extends Activity {
@Inject
Api api;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
DemortarApp.getDemortarApp(this).getComponent().inject(this);
@Component(modules = {ApiModule.class, DatabaseModule.class})
@Singleton
public interface DataAccessComponent {
Api api();
Database database();
void inject(SimpleActivity simpleActivity);
}
@Singleton
public class ApiManager {
@Inject
Api api;
@Inject
public ApiManager() {
}
public class SimpleActivity extends Activity {
@Inject
Api api;
@Inject
ApiManager apiManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
@lukaspili
lukaspili / LoginScreen.java
Last active August 29, 2015 14:16
Dagger 2 / Mortar / Flow
@Layout(R.layout.view_login)
@WithComponent(LoginScreen.Component.class)
public class LoginScreen extends Path {
@dagger.Component(dependencies = RootActivity.Component.class)
@PerScreenScope(Component.class)
public static interface Component extends RootActivity.Component {
void inject(LoginView view);
}
public class App extends Application {
private MortarScope mortarScope;
private Component component;
@Override
public Object getSystemService(String name) {
return mortarScope.hasService(name) ? mortarScope.getService(name) : super.getSystemService(name);
}