mirror of https://github.com/tasks/tasks
Use dagger for astrid activities
parent
5a86d89cb5
commit
80b484e2ad
@ -1,16 +0,0 @@
|
||||
package org.tasks;
|
||||
|
||||
import dagger.ObjectGraph;
|
||||
|
||||
public class Injector {
|
||||
|
||||
ObjectGraph objectGraph;
|
||||
|
||||
public Injector() {
|
||||
objectGraph = ObjectGraph.create(new TasksModule());
|
||||
}
|
||||
|
||||
public void inject(Object caller) {
|
||||
objectGraph.inject(caller);
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package org.tasks;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import com.todoroo.astrid.service.AstridDependencyInjector;
|
||||
|
||||
import org.tasks.injection.Injector;
|
||||
|
||||
public class Tasks extends Application implements Injector {
|
||||
|
||||
Injector injector;
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
injector = AstridDependencyInjector.getInjector();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inject(Object caller, Object... modules) {
|
||||
injector.inject(caller, modules);
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package org.tasks.injection;
|
||||
|
||||
import com.todoroo.astrid.activity.ShareLinkActivity;
|
||||
import com.todoroo.astrid.activity.TaskEditActivity;
|
||||
import com.todoroo.astrid.activity.TaskListActivity;
|
||||
|
||||
import dagger.Module;
|
||||
|
||||
@Module(library = true,
|
||||
injects = {
|
||||
TaskListActivity.class,
|
||||
TaskEditActivity.class,
|
||||
ShareLinkActivity.class
|
||||
})
|
||||
public class ActivityModule {
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package org.tasks.injection;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
|
||||
public class InjectingActionBarActivity extends ActionBarActivity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
((Injector) getApplication()).inject(this, new ActivityModule());
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package org.tasks.injection;
|
||||
|
||||
public interface Injector {
|
||||
|
||||
public void inject(Object caller, Object... modules);
|
||||
|
||||
}
|
Loading…
Reference in New Issue