Use dagger for remaining injectables

pull/143/head
Alex Baker 11 years ago
parent 8ed650446f
commit a29edd31e7

@ -8,8 +8,6 @@ package com.todoroo.astrid.gtasks;
import com.google.api.services.tasks.model.TaskList; import com.google.api.services.tasks.model.TaskList;
import com.google.api.services.tasks.model.TaskLists; import com.google.api.services.tasks.model.TaskLists;
import com.todoroo.andlib.data.TodorooCursor; import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.sql.Query; import com.todoroo.andlib.sql.Query;
import com.todoroo.astrid.dao.StoreObjectDao; import com.todoroo.astrid.dao.StoreObjectDao;
import com.todoroo.astrid.dao.StoreObjectDao.StoreObjectCriteria; import com.todoroo.astrid.dao.StoreObjectDao.StoreObjectCriteria;
@ -18,17 +16,22 @@ import com.todoroo.astrid.data.StoreObject;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import javax.inject.Inject;
import javax.inject.Singleton;
@Singleton
public class GtasksListService { public class GtasksListService {
public static final String LIST_NOT_FOUND = null; public static final String LIST_NOT_FOUND = null;
public static final StoreObject LIST_NOT_FOUND_OBJECT = null; public static final StoreObject LIST_NOT_FOUND_OBJECT = null;
@Autowired private StoreObjectDao storeObjectDao; private final StoreObjectDao storeObjectDao;
private StoreObject[] lists = null; private StoreObject[] lists = null;
public GtasksListService() { @Inject
DependencyInjectionService.getInstance().inject(this); public GtasksListService(StoreObjectDao storeObjectDao) {
this.storeObjectDao = storeObjectDao;
} }
private void readLists() { private void readLists() {

@ -9,15 +9,15 @@ import android.text.TextUtils;
import com.todoroo.andlib.data.AbstractModel; import com.todoroo.andlib.data.AbstractModel;
import com.todoroo.andlib.data.TodorooCursor; import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.sql.Criterion; import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Field; import com.todoroo.andlib.sql.Field;
import com.todoroo.andlib.sql.Functions; import com.todoroo.andlib.sql.Functions;
import com.todoroo.andlib.sql.Order; import com.todoroo.andlib.sql.Order;
import com.todoroo.andlib.sql.Query; import com.todoroo.andlib.sql.Query;
import com.todoroo.astrid.core.PluginServices; import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.dao.MetadataDao;
import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria; import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.StoreObject; import com.todoroo.astrid.data.StoreObject;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
@ -31,19 +31,24 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import javax.inject.Inject;
import javax.inject.Singleton;
/** /**
* Service for working with GTasks metadata * Service for working with GTasks metadata
* *
* @author Tim Su <tim@todoroo.com> * @author Tim Su <tim@todoroo.com>
* *
*/ */
@Singleton
public final class GtasksMetadataService extends SyncMetadataService<GtasksTaskContainer> { public final class GtasksMetadataService extends SyncMetadataService<GtasksTaskContainer> {
@Autowired private GtasksPreferenceService gtasksPreferenceService; private final GtasksPreferenceService gtasksPreferenceService;
public GtasksMetadataService() { @Inject
super(); public GtasksMetadataService(GtasksPreferenceService gtasksPreferenceService, TaskDao taskDao, MetadataDao metadataDao) {
DependencyInjectionService.getInstance().inject(this); super(taskDao, metadataDao);
this.gtasksPreferenceService = gtasksPreferenceService;
} }
public Criterion getLocalMatchCriteria(GtasksTaskContainer remoteTask) { public Criterion getLocalMatchCriteria(GtasksTaskContainer remoteTask) {

@ -9,17 +9,25 @@ import com.todoroo.astrid.sync.SyncProviderUtilities;
import org.tasks.R; import org.tasks.R;
import javax.inject.Inject;
import javax.inject.Singleton;
/** /**
* Methods for working with GTasks preferences * Methods for working with GTasks preferences
* *
* @author timsu * @author timsu
* *
*/ */
@Singleton
public class GtasksPreferenceService extends SyncProviderUtilities { public class GtasksPreferenceService extends SyncProviderUtilities {
/** add-on identifier */ /** add-on identifier */
public static final String IDENTIFIER = "gtasks"; //$NON-NLS-1$ public static final String IDENTIFIER = "gtasks"; //$NON-NLS-1$
@Inject
public GtasksPreferenceService() {
}
@Override @Override
public String getIdentifier() { public String getIdentifier() {
return IDENTIFIER; return IDENTIFIER;

@ -11,7 +11,6 @@ import android.util.Log;
import com.todoroo.andlib.data.Property.IntegerProperty; import com.todoroo.andlib.data.Property.IntegerProperty;
import com.todoroo.andlib.data.Property.LongProperty; import com.todoroo.andlib.data.Property.LongProperty;
import com.todoroo.andlib.data.TodorooCursor; import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.sql.Criterion; import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Functions; import com.todoroo.andlib.sql.Functions;
import com.todoroo.andlib.sql.Order; import com.todoroo.andlib.sql.Order;
@ -29,6 +28,10 @@ import java.util.HashSet;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import javax.inject.Inject;
import javax.inject.Singleton;
@Singleton
public class GtasksTaskListUpdater extends OrderedMetadataListUpdater<StoreObject> { public class GtasksTaskListUpdater extends OrderedMetadataListUpdater<StoreObject> {
/** map of task -> parent task */ /** map of task -> parent task */
@ -40,13 +43,17 @@ public class GtasksTaskListUpdater extends OrderedMetadataListUpdater<StoreObjec
final HashMap<Long, String> localToRemoteIdMap = final HashMap<Long, String> localToRemoteIdMap =
new HashMap<>(); new HashMap<>();
@Autowired private GtasksListService gtasksListService; private final GtasksListService gtasksListService;
@Autowired private GtasksMetadataService gtasksMetadataService; private final GtasksMetadataService gtasksMetadataService;
@Autowired private GtasksSyncService gtasksSyncService; private final GtasksSyncService gtasksSyncService;
@Autowired private MetadataDao metadataDao; private final MetadataDao metadataDao;
public GtasksTaskListUpdater() { @Inject
super(); public GtasksTaskListUpdater(GtasksListService gtasksListService, GtasksMetadataService gtasksMetadataService, GtasksSyncService gtasksSyncService, MetadataDao metadataDao) {
this.gtasksListService = gtasksListService;
this.gtasksMetadataService = gtasksMetadataService;
this.gtasksSyncService = gtasksSyncService;
this.metadataDao = metadataDao;
} }
// --- overrides // --- overrides

@ -11,8 +11,6 @@ import android.util.Log;
import com.todoroo.andlib.data.DatabaseDao.ModelUpdateListener; import com.todoroo.andlib.data.DatabaseDao.ModelUpdateListener;
import com.todoroo.andlib.data.Property; import com.todoroo.andlib.data.Property;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.Preferences; import com.todoroo.andlib.utility.Preferences;
@ -35,17 +33,27 @@ import java.io.IOException;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.Semaphore; import java.util.concurrent.Semaphore;
import javax.inject.Inject;
import javax.inject.Singleton;
@Singleton
public class GtasksSyncService { public class GtasksSyncService {
private static final String DEFAULT_LIST = "@default"; //$NON-NLS-1$ private static final String DEFAULT_LIST = "@default"; //$NON-NLS-1$
@Autowired MetadataService metadataService;
@Autowired MetadataDao metadataDao; private final MetadataService metadataService;
@Autowired GtasksMetadataService gtasksMetadataService; private final MetadataDao metadataDao;
@Autowired TaskDao taskDao; private final GtasksMetadataService gtasksMetadataService;
@Autowired GtasksPreferenceService gtasksPreferenceService; private final TaskDao taskDao;
private final GtasksPreferenceService gtasksPreferenceService;
public GtasksSyncService() {
DependencyInjectionService.getInstance().inject(this); @Inject
public GtasksSyncService(MetadataService metadataService, MetadataDao metadataDao, GtasksMetadataService gtasksMetadataService, TaskDao taskDao, GtasksPreferenceService gtasksPreferenceService) {
this.metadataService = metadataService;
this.metadataDao = metadataDao;
this.gtasksMetadataService = gtasksMetadataService;
this.taskDao = taskDao;
this.gtasksPreferenceService = gtasksPreferenceService;
} }
private final LinkedBlockingQueue<SyncOnSaveOperation> operationQueue = new LinkedBlockingQueue<>(); private final LinkedBlockingQueue<SyncOnSaveOperation> operationQueue = new LinkedBlockingQueue<>();

@ -63,6 +63,12 @@ public class AstridDependencyInjector extends AbstractDependencyInjector {
@Inject RefreshScheduler refreshScheduler; @Inject RefreshScheduler refreshScheduler;
@Inject TaskService taskService; @Inject TaskService taskService;
@Inject TagService tagService; @Inject TagService tagService;
@Inject UpgradeService upgradeService;
@Inject GtasksPreferenceService gtasksPreferenceService;
@Inject GtasksListService gtasksListService;
@Inject GtasksMetadataService gtasksMetadataService;
@Inject GtasksSyncService gtasksSyncService;
@Inject GtasksTaskListUpdater gtasksTaskListUpdater;
/** /**
* Initialize list of injectables. Special care must used when * Initialize list of injectables. Special care must used when
@ -87,15 +93,15 @@ public class AstridDependencyInjector extends AbstractDependencyInjector {
injectables.put("taskService", taskService); injectables.put("taskService", taskService);
injectables.put("metadataService", metadataService); injectables.put("metadataService", metadataService);
injectables.put("tagDataService", tagDataService); injectables.put("tagDataService", tagDataService);
injectables.put("upgradeService", UpgradeService.class); injectables.put("upgradeService", upgradeService);
injectables.put("syncService", syncV2Service); injectables.put("syncService", syncV2Service);
// com.todoroo.astrid.gtasks // com.todoroo.astrid.gtasks
injectables.put("gtasksPreferenceService", GtasksPreferenceService.class); injectables.put("gtasksPreferenceService", gtasksPreferenceService);
injectables.put("gtasksListService", GtasksListService.class); injectables.put("gtasksListService", gtasksListService);
injectables.put("gtasksMetadataService", GtasksMetadataService.class); injectables.put("gtasksMetadataService", gtasksMetadataService);
injectables.put("gtasksTaskListUpdater", GtasksTaskListUpdater.class); injectables.put("gtasksTaskListUpdater", gtasksTaskListUpdater);
injectables.put("gtasksSyncService", GtasksSyncService.class); injectables.put("gtasksSyncService", gtasksSyncService);
// com.todoroo.astrid.tags // com.todoroo.astrid.tags
injectables.put("tagService", tagService); injectables.put("tagService", tagService);

@ -11,8 +11,6 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.utility.DialogUtilities; import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.andlib.utility.Preferences; import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.activity.AstridActivity; import com.todoroo.astrid.activity.AstridActivity;
@ -21,11 +19,19 @@ import com.todoroo.astrid.utility.AstridPreferences;
import org.tasks.R; import org.tasks.R;
import javax.inject.Inject;
import javax.inject.Singleton;
@Singleton
public final class UpgradeService { public final class UpgradeService {
public static final int V4_6_5 = 306; public static final int V4_6_5 = 306;
public static final int V3_0_0 = 136; public static final int V3_0_0 = 136;
@Inject
public UpgradeService() {
}
/** /**
* Perform upgrade from one version to the next. Needs to be called * Perform upgrade from one version to the next. Needs to be called
* on the UI thread so it can display a progress bar and then * on the UI thread so it can display a progress bar and then
@ -44,7 +50,6 @@ public final class UpgradeService {
} }
public static class UpgradeActivity extends Activity { public static class UpgradeActivity extends Activity {
@Autowired private TaskService taskService;
private ProgressDialog dialog; private ProgressDialog dialog;
public static final String TOKEN_FROM_VERSION = "from_version"; //$NON-NLS-1$ public static final String TOKEN_FROM_VERSION = "from_version"; //$NON-NLS-1$
@ -54,7 +59,6 @@ public final class UpgradeService {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
DependencyInjectionService.getInstance().inject(this);
from = getIntent().getIntExtra(TOKEN_FROM_VERSION, -1); from = getIntent().getIntExtra(TOKEN_FROM_VERSION, -1);
if (from > 0) { if (from > 0) {
dialog = DialogUtilities.progressDialog(this, dialog = DialogUtilities.progressDialog(this,

@ -7,7 +7,6 @@ package com.todoroo.astrid.subtasks;
import com.todoroo.andlib.data.Property.IntegerProperty; import com.todoroo.andlib.data.Property.IntegerProperty;
import com.todoroo.andlib.data.Property.LongProperty; import com.todoroo.andlib.data.Property.LongProperty;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.astrid.core.PluginServices; import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
@ -20,10 +19,6 @@ import java.util.concurrent.atomic.AtomicReference;
abstract public class OrderedMetadataListUpdater<LIST> { abstract public class OrderedMetadataListUpdater<LIST> {
public OrderedMetadataListUpdater() {
DependencyInjectionService.getInstance().inject(this);
}
public interface OrderedListIterator { public interface OrderedListIterator {
public void processTask(long taskId, Metadata metadata); public void processTask(long taskId, Metadata metadata);
} }

@ -7,8 +7,6 @@ package com.todoroo.astrid.utility;
import com.todoroo.andlib.data.Property; import com.todoroo.andlib.data.Property;
import com.todoroo.andlib.data.TodorooCursor; import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.sql.Criterion; import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Order; import com.todoroo.andlib.sql.Order;
import com.todoroo.andlib.sql.Query; import com.todoroo.andlib.sql.Query;
@ -25,10 +23,8 @@ import java.util.ArrayList;
abstract public class SyncMetadataService<TYPE extends SyncContainer> { abstract public class SyncMetadataService<TYPE extends SyncContainer> {
// --- instance variables protected final TaskDao taskDao;
protected final MetadataDao metadataDao;
@Autowired protected TaskDao taskDao;
@Autowired protected MetadataDao metadataDao;
// --- abstract methods // --- abstract methods
@ -46,8 +42,9 @@ abstract public class SyncMetadataService<TYPE extends SyncContainer> {
// --- implementation // --- implementation
public SyncMetadataService() { public SyncMetadataService(TaskDao taskDao, MetadataDao metadataDao) {
DependencyInjectionService.getInstance().inject(this); this.taskDao = taskDao;
this.metadataDao = metadataDao;
} }
/** /**

Loading…
Cancel
Save