Use dagger for astrid activities

pull/143/head
Alex Baker 11 years ago
parent 5a86d89cb5
commit 80b484e2ad

@ -71,7 +71,6 @@ android.applicationVariants.all { variant ->
dependencies {
provided group: 'com.squareup.dagger', name: 'dagger-compiler', version: '1.2.1'
compile group: 'com.android.support', name: 'support-v4', version: '19.1.+'
compile group: 'com.android.support', name: 'appcompat-v7', version: '19.1.+'
compile 'net.simonvt.menudrawer:menudrawer:3.0.4@aar'

@ -85,6 +85,7 @@
android:label="@string/app_name"
android:theme="@style/Tasks"
android:allowBackup="true"
android:name=".Tasks"
android:hardwareAccelerated="false"
android:manageSpaceActivity="com.todoroo.astrid.core.OldTaskPreferences">

@ -13,13 +13,11 @@ import android.speech.SpeechRecognizer;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.WindowManager.BadTokenException;
import android.widget.EditText;
import android.widget.Toast;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.DialogUtilities;
@ -34,7 +32,6 @@ import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.service.AstridDependencyInjector;
import com.todoroo.astrid.service.StartupService;
import com.todoroo.astrid.subtasks.SubtasksHelper;
import com.todoroo.astrid.ui.DateChangedAlerts;
@ -43,6 +40,9 @@ import com.todoroo.astrid.voice.RecognizerApi.RecognizerApiListener;
import com.todoroo.astrid.voice.VoiceRecognizer;
import org.tasks.R;
import org.tasks.injection.InjectingActionBarActivity;
import javax.inject.Inject;
/**
* This wrapper activity contains all the glue-code to handle the callbacks between the different
@ -55,7 +55,7 @@ import org.tasks.R;
* @author Arne
*
*/
public class AstridActivity extends ActionBarActivity
public class AstridActivity extends InjectingActionBarActivity
implements FilterListFragment.OnFilterItemClickedListener,
TaskListFragment.OnTaskListItemClickedListener,
RecognizerApiListener {
@ -69,7 +69,7 @@ public class AstridActivity extends ActionBarActivity
private final RepeatConfirmationReceiver repeatConfirmationReceiver = new RepeatConfirmationReceiver();
@Autowired private TaskDao taskDao;
@Inject TaskDao taskDao;
public FilterListFragment getFilterListFragment() {
return (FilterListFragment) getSupportFragmentManager()
@ -94,7 +94,6 @@ public class AstridActivity extends ActionBarActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
AstridDependencyInjector.inject(this);
super.onCreate(savedInstanceState);
ContextManager.setContext(this);

@ -6,13 +6,13 @@ package com.todoroo.astrid.activity;
import android.content.Intent;
import android.os.Bundle;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.service.TaskService;
import com.todoroo.astrid.tags.TagService;
import com.todoroo.astrid.ui.QuickAddBar;
import javax.inject.Inject;
/**
* @author joshuagross
*
@ -20,20 +20,14 @@ import com.todoroo.astrid.ui.QuickAddBar;
*/
public final class ShareLinkActivity extends TaskListActivity {
@Autowired private TaskService taskService;
@Autowired private TagService tagService;
@Inject TaskService taskService;
@Inject TagService tagService;
private String subject;
private boolean handled;
private static final String TOKEN_LINK_HANDLED = "linkHandled"; //$NON-NLS-1$
public ShareLinkActivity () {
super();
DependencyInjectionService.getInstance().inject(this);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

@ -23,8 +23,6 @@ import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.FrameLayout;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.sql.QueryTemplate;
import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.astrid.actfm.CommentsFragment;
@ -54,9 +52,11 @@ import net.simonvt.menudrawer.MenuDrawer;
import org.tasks.R;
import javax.inject.Inject;
public class TaskListActivity extends AstridActivity implements OnPageChangeListener {
@Autowired TagDataDao tagDataDao;
@Inject TagDataDao tagDataDao;
MenuDrawer menuDrawer;

@ -24,12 +24,15 @@ import com.todoroo.astrid.gtasks.sync.GtasksSyncService;
import com.todoroo.astrid.tags.TagService;
import org.tasks.Broadcaster;
import org.tasks.Injector;
import org.tasks.TasksModule;
import org.tasks.filters.FilterCounter;
import org.tasks.injection.Injector;
import org.tasks.scheduling.RefreshScheduler;
import javax.inject.Inject;
import dagger.ObjectGraph;
/**
* Astrid application dependency injector loads classes in Astrid with the
* appropriate instantiated objects necessary for their operation. For
@ -46,6 +49,8 @@ public class AstridDependencyInjector extends AbstractDependencyInjector {
*/
private static AstridDependencyInjector instance = null;
private Injector injector;
@Inject Database database;
@Inject MetadataDao metadataDao;
@Inject TagDataDao tagDataDao;
@ -76,7 +81,17 @@ public class AstridDependencyInjector extends AbstractDependencyInjector {
*/
@Override
protected void addInjectables() {
new Injector().inject(this);
injector = new Injector() {
ObjectGraph objectGraph = ObjectGraph.create(new TasksModule());
@Override
public void inject(Object caller, Object... modules) {
objectGraph
.plus(modules)
.inject(caller);
}
};
injector.inject(this);
// com.todoroo.astrid.dao
injectables.put("database", database);
@ -144,4 +159,9 @@ public class AstridDependencyInjector extends AbstractDependencyInjector {
instance = null;
initialize();
}
public static Injector getInjector() {
initialize();
return instance.injector;
}
}

@ -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…
Cancel
Save