Skip to content

Instantly share code, notes, and snippets.

Avatar

Lukasz Piliszczuk lukaspili

View GitHub Profile
View App.java
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);
}
@lukaspili
lukaspili / LoginScreen.java
Last active Aug 29, 2015
Dagger 2 / Mortar / Flow
View LoginScreen.java
@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);
}
View gist:51c0b0e9286879c02e4e
public class SimpleActivity extends Activity {
@Inject
Api api;
@Inject
ApiManager apiManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
View gist:11bacf7ceb98da1e3f42
@Singleton
public class ApiManager {
@Inject
Api api;
@Inject
public ApiManager() {
}
View gist:5c90f405ce7ad5ab024f
@Component(modules = {ApiModule.class, DatabaseModule.class})
@Singleton
public interface DataAccessComponent {
Api api();
Database database();
void inject(SimpleActivity simpleActivity);
}
View gist:482399eb977c9c9a3a85
public class SimpleActivity extends Activity {
@Inject
Api api;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
DemortarApp.getDemortarApp(this).getComponent().inject(this);
View gist:b48f2c5614577d04f52b
public class SimpleActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
DataAccessComponent component = DemortarApp.getDemortarApp(this)
.getComponent();
Api api = component.api();
View gist:348fd86a47a3df7cc55e
public class DemortarApp extends Application {
private DataAccessComponent component;
public static DemortarApp getDemortarApp(Context context) {
return (DemortarApp) context.getApplicationContext();
}
@Override
public void onCreate() {
View gist:09a3a20a75f5a01936d0
@Module
public class ApiModule {
private User user;
public ApiModule(User user) {
this.user = user;
}
@Provides
View collection.js
/*global define*/
define([
'underscore',
'backbone',
'models/client'
], function (_, Backbone, ClientModel) {
'use strict';
var ClientCollection = Backbone.Collection.extend({