From 1804e00568345fd26625e209c1d92355367ad26d Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Fri, 12 Aug 2016 12:20:36 -0500 Subject: [PATCH] Clean up dagger scopes --- .../java/org/tasks/analytics/Tracker.java | 4 ++-- .../tasks/injection/ActivityComponent.java | 4 +--- .../tasks/injection/ApplicationComponent.java | 4 +--- .../java/org/tasks/injection/TestModule.java | 6 ++---- .../org/tasks/injection/TestComponent.java | 4 +--- .../org/tasks/injection/TestComponent.java | 4 +--- .../org/tasks/injection/TestComponent.java | 4 +--- .../tasks/injection/ActivityComponent.java | 4 +--- .../tasks/injection/ApplicationComponent.java | 4 +--- .../astrid/gtasks/GtasksPreferences.java | 4 +--- .../astrid/gtasks/GtasksTaskListUpdater.java | 5 +++-- .../astrid/gtasks/api/GtasksInvoker.java | 5 ++--- .../astrid/gtasks/sync/GtasksSyncService.java | 4 ++-- .../java/org/tasks/FlavorSetup.java | 9 +-------- .../java/org/tasks/analytics/Tracker.java | 4 ++-- .../org/tasks/billing/InventoryHelper.java | 4 ++-- .../org/tasks/billing/PurchaseHelper.java | 4 ++-- .../tasks/injection/ActivityComponent.java | 4 +--- .../tasks/injection/ApplicationComponent.java | 4 +--- .../todoroo/astrid/alarms/AlarmService.java | 4 ++-- .../java/com/todoroo/astrid/dao/Database.java | 4 ++-- .../com/todoroo/astrid/dao/MetadataDao.java | 5 +++-- .../com/todoroo/astrid/dao/TagDataDao.java | 6 +++--- .../java/com/todoroo/astrid/dao/TaskDao.java | 4 ++-- .../astrid/gcal/CalendarReminderActivity.java | 2 -- .../todoroo/astrid/gtasks/GtasksMetadata.java | 2 -- .../astrid/reminders/ReminderService.java | 4 ++-- .../todoroo/astrid/service/TaskService.java | 4 ++-- .../com/todoroo/astrid/tags/TagService.java | 5 +++-- src/main/java/org/tasks/Broadcaster.java | 2 -- src/main/java/org/tasks/Tasks.java | 14 -------------- .../org/tasks/activities/CameraActivity.java | 6 ++---- .../org/tasks/injection/ActivityModule.java | 17 +++++++++++------ .../org/tasks/injection/ActivityScope.java | 11 +++++++++++ .../tasks/injection/ApplicationModule.java | 9 ++++----- .../org/tasks/injection/ApplicationScope.java | 11 +++++++++++ .../injection/BaseApplicationComponent.java | 4 ---- .../injection/ContentProviderComponent.java | 4 +--- .../tasks/injection/DialogFragmentModule.java | 13 ------------- .../org/tasks/injection/FragmentModule.java | 7 ------- .../org/tasks/location/GeofenceService.java | 2 -- .../notifications/NotificationManager.java | 2 -- .../tasks/preferences/ResourceResolver.java | 19 +------------------ .../tasks/receivers/TeslaUnreadReceiver.java | 4 ++-- .../java/org/tasks/sync/SyncExecutor.java | 4 ++-- 45 files changed, 92 insertions(+), 162 deletions(-) create mode 100644 src/main/java/org/tasks/injection/ActivityScope.java create mode 100644 src/main/java/org/tasks/injection/ApplicationScope.java diff --git a/src/amazon/java/org/tasks/analytics/Tracker.java b/src/amazon/java/org/tasks/analytics/Tracker.java index 85c19b75b..60aacb904 100644 --- a/src/amazon/java/org/tasks/analytics/Tracker.java +++ b/src/amazon/java/org/tasks/analytics/Tracker.java @@ -11,14 +11,14 @@ import com.google.common.base.Strings; import org.tasks.BuildConfig; import org.tasks.R; +import org.tasks.injection.ApplicationScope; import org.tasks.injection.ForApplication; import javax.inject.Inject; -import javax.inject.Singleton; import timber.log.Timber; -@Singleton +@ApplicationScope public class Tracker { private final GoogleAnalytics analytics; diff --git a/src/amazon/java/org/tasks/injection/ActivityComponent.java b/src/amazon/java/org/tasks/injection/ActivityComponent.java index ee20c966e..fa9f42ebe 100644 --- a/src/amazon/java/org/tasks/injection/ActivityComponent.java +++ b/src/amazon/java/org/tasks/injection/ActivityComponent.java @@ -1,10 +1,8 @@ package org.tasks.injection; -import javax.inject.Singleton; - import dagger.Subcomponent; -@Singleton +@ActivityScope @Subcomponent(modules = ActivityModule.class) public interface ActivityComponent extends BaseActivityComponent { diff --git a/src/amazon/java/org/tasks/injection/ApplicationComponent.java b/src/amazon/java/org/tasks/injection/ApplicationComponent.java index 8abff6051..2ccd6482d 100644 --- a/src/amazon/java/org/tasks/injection/ApplicationComponent.java +++ b/src/amazon/java/org/tasks/injection/ApplicationComponent.java @@ -1,10 +1,8 @@ package org.tasks.injection; -import javax.inject.Singleton; - import dagger.Component; -@Singleton +@ApplicationScope @Component(modules = ApplicationModule.class) public interface ApplicationComponent extends BaseApplicationComponent { } diff --git a/src/androidTest/java/org/tasks/injection/TestModule.java b/src/androidTest/java/org/tasks/injection/TestModule.java index 2bbe6a012..813d6a89e 100644 --- a/src/androidTest/java/org/tasks/injection/TestModule.java +++ b/src/androidTest/java/org/tasks/injection/TestModule.java @@ -6,8 +6,6 @@ import com.todoroo.astrid.dao.Database; import org.tasks.analytics.Tracker; -import javax.inject.Singleton; - import dagger.Module; import dagger.Provides; @@ -21,7 +19,7 @@ public class TestModule { this.context = context; } - @Singleton + @ApplicationScope @Provides public Database getDatabase() { return new Database(context, mock(Tracker.class)) { @@ -32,7 +30,7 @@ public class TestModule { }; } - @Singleton + @ApplicationScope @Provides @ForApplication public Context getContext() { diff --git a/src/androidTestAmazon/java/org/tasks/injection/TestComponent.java b/src/androidTestAmazon/java/org/tasks/injection/TestComponent.java index 873e51366..a73b5cd2f 100644 --- a/src/androidTestAmazon/java/org/tasks/injection/TestComponent.java +++ b/src/androidTestAmazon/java/org/tasks/injection/TestComponent.java @@ -1,10 +1,8 @@ package org.tasks.injection; -import javax.inject.Singleton; - import dagger.Component; -@Singleton +@ApplicationScope @Component(modules = TestModule.class) public interface TestComponent extends BaseTestComponent { } diff --git a/src/androidTestGeneric/java/org/tasks/injection/TestComponent.java b/src/androidTestGeneric/java/org/tasks/injection/TestComponent.java index 873e51366..a73b5cd2f 100644 --- a/src/androidTestGeneric/java/org/tasks/injection/TestComponent.java +++ b/src/androidTestGeneric/java/org/tasks/injection/TestComponent.java @@ -1,10 +1,8 @@ package org.tasks.injection; -import javax.inject.Singleton; - import dagger.Component; -@Singleton +@ApplicationScope @Component(modules = TestModule.class) public interface TestComponent extends BaseTestComponent { } diff --git a/src/androidTestGoogleplay/java/org/tasks/injection/TestComponent.java b/src/androidTestGoogleplay/java/org/tasks/injection/TestComponent.java index b274bc1c4..61cf061f5 100644 --- a/src/androidTestGoogleplay/java/org/tasks/injection/TestComponent.java +++ b/src/androidTestGoogleplay/java/org/tasks/injection/TestComponent.java @@ -6,11 +6,9 @@ import com.todoroo.astrid.gtasks.GtasksMetadataServiceTest; import com.todoroo.astrid.gtasks.GtasksTaskListUpdaterTest; import com.todoroo.astrid.gtasks.GtasksTaskMovingTest; -import javax.inject.Singleton; - import dagger.Component; -@Singleton +@ApplicationScope @Component(modules = TestModule.class) public interface TestComponent extends BaseTestComponent { diff --git a/src/generic/java/org/tasks/injection/ActivityComponent.java b/src/generic/java/org/tasks/injection/ActivityComponent.java index ee20c966e..fa9f42ebe 100644 --- a/src/generic/java/org/tasks/injection/ActivityComponent.java +++ b/src/generic/java/org/tasks/injection/ActivityComponent.java @@ -1,10 +1,8 @@ package org.tasks.injection; -import javax.inject.Singleton; - import dagger.Subcomponent; -@Singleton +@ActivityScope @Subcomponent(modules = ActivityModule.class) public interface ActivityComponent extends BaseActivityComponent { diff --git a/src/generic/java/org/tasks/injection/ApplicationComponent.java b/src/generic/java/org/tasks/injection/ApplicationComponent.java index 8abff6051..2ccd6482d 100644 --- a/src/generic/java/org/tasks/injection/ApplicationComponent.java +++ b/src/generic/java/org/tasks/injection/ApplicationComponent.java @@ -1,10 +1,8 @@ package org.tasks.injection; -import javax.inject.Singleton; - import dagger.Component; -@Singleton +@ApplicationScope @Component(modules = ApplicationModule.class) public interface ApplicationComponent extends BaseApplicationComponent { } diff --git a/src/googleplay/java/com/todoroo/astrid/gtasks/GtasksPreferences.java b/src/googleplay/java/com/todoroo/astrid/gtasks/GtasksPreferences.java index 7de496820..0416c83a8 100644 --- a/src/googleplay/java/com/todoroo/astrid/gtasks/GtasksPreferences.java +++ b/src/googleplay/java/com/todoroo/astrid/gtasks/GtasksPreferences.java @@ -5,7 +5,6 @@ */ package com.todoroo.astrid.gtasks; -import android.app.Activity; import android.content.DialogInterface; import android.content.Intent; import android.content.pm.PackageManager; @@ -44,7 +43,6 @@ public class GtasksPreferences extends InjectingPreferenceActivity implements Go @Inject GtasksListService gtasksListService; @Inject Tracker tracker; @Inject SyncAdapterHelper syncAdapterHelper; - @Inject Activity activity; @Inject PlayServicesAvailability playServicesAvailability; @Inject DialogBuilder dialogBuilder; @Inject MetadataDao metadataDao; @@ -62,7 +60,7 @@ public class GtasksPreferences extends InjectingPreferenceActivity implements Go public boolean onPreferenceChange(Preference preference, Object newValue) { if ((boolean) newValue) { if (!playServicesAvailability.refreshAndCheck()) { - playServicesAvailability.resolve(activity); + playServicesAvailability.resolve(GtasksPreferences.this); } else if (permissionRequestor.requestAccountPermissions()) { requestLogin(); } diff --git a/src/googleplay/java/com/todoroo/astrid/gtasks/GtasksTaskListUpdater.java b/src/googleplay/java/com/todoroo/astrid/gtasks/GtasksTaskListUpdater.java index 04382b02c..79ff4dd77 100644 --- a/src/googleplay/java/com/todoroo/astrid/gtasks/GtasksTaskListUpdater.java +++ b/src/googleplay/java/com/todoroo/astrid/gtasks/GtasksTaskListUpdater.java @@ -19,6 +19,8 @@ import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.Task; import com.todoroo.astrid.gtasks.sync.GtasksSyncService; +import org.tasks.injection.ApplicationScope; + import java.util.HashMap; import java.util.HashSet; import java.util.Set; @@ -26,11 +28,10 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; import javax.inject.Inject; -import javax.inject.Singleton; import timber.log.Timber; -@Singleton +@ApplicationScope public class GtasksTaskListUpdater extends OrderedMetadataListUpdater { /** map of task -> parent task */ diff --git a/src/googleplay/java/com/todoroo/astrid/gtasks/api/GtasksInvoker.java b/src/googleplay/java/com/todoroo/astrid/gtasks/api/GtasksInvoker.java index 3e395aa77..d8c39f34b 100644 --- a/src/googleplay/java/com/todoroo/astrid/gtasks/api/GtasksInvoker.java +++ b/src/googleplay/java/com/todoroo/astrid/gtasks/api/GtasksInvoker.java @@ -16,17 +16,16 @@ import com.google.api.services.tasks.model.TaskList; import com.google.api.services.tasks.model.TaskLists; import com.todoroo.astrid.gtasks.GtasksPreferenceService; -import org.tasks.AccountManager; import org.tasks.BuildConfig; import org.tasks.analytics.Tracker; import org.tasks.gtasks.GoogleTasksUnsuccessfulResponseHandler; +import org.tasks.injection.ApplicationScope; import org.tasks.injection.ForApplication; import java.io.IOException; import java.util.Collections; import javax.inject.Inject; -import javax.inject.Singleton; import timber.log.Timber; @@ -36,7 +35,7 @@ import timber.log.Timber; * * @author Sam Bosley */ -@Singleton +@ApplicationScope public class GtasksInvoker { private final Context context; diff --git a/src/googleplay/java/com/todoroo/astrid/gtasks/sync/GtasksSyncService.java b/src/googleplay/java/com/todoroo/astrid/gtasks/sync/GtasksSyncService.java index 8cb0f324c..68b59a7b6 100644 --- a/src/googleplay/java/com/todoroo/astrid/gtasks/sync/GtasksSyncService.java +++ b/src/googleplay/java/com/todoroo/astrid/gtasks/sync/GtasksSyncService.java @@ -26,6 +26,7 @@ import com.todoroo.astrid.gtasks.api.GtasksInvoker; import com.todoroo.astrid.gtasks.api.MoveRequest; import org.tasks.gtasks.SyncAdapterHelper; +import org.tasks.injection.ApplicationScope; import java.io.IOException; import java.util.concurrent.LinkedBlockingQueue; @@ -34,11 +35,10 @@ import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicReference; import javax.inject.Inject; -import javax.inject.Singleton; import timber.log.Timber; -@Singleton +@ApplicationScope public class GtasksSyncService { private final MetadataDao metadataDao; diff --git a/src/googleplay/java/org/tasks/FlavorSetup.java b/src/googleplay/java/org/tasks/FlavorSetup.java index e0c33ab75..9b6f546ee 100644 --- a/src/googleplay/java/org/tasks/FlavorSetup.java +++ b/src/googleplay/java/org/tasks/FlavorSetup.java @@ -1,13 +1,10 @@ package org.tasks; import com.todoroo.astrid.gtasks.GtasksPreferenceService; -import com.todoroo.astrid.gtasks.GtasksTaskListUpdater; import org.tasks.billing.InventoryHelper; -import org.tasks.billing.PurchaseHelper; import org.tasks.gtasks.PlayServicesAvailability; import org.tasks.gtasks.SyncAdapterHelper; -import org.tasks.sync.SyncExecutor; import javax.inject.Inject; @@ -19,11 +16,7 @@ public class FlavorSetup { private final PlayServicesAvailability playServicesAvailability; @Inject - public FlavorSetup(GtasksPreferenceService gtasksPreferenceService, - @SuppressWarnings("UnusedParameters") GtasksTaskListUpdater gtasksTaskListUpdater, - @SuppressWarnings("UnusedParameters") PurchaseHelper purchaseHelper, - @SuppressWarnings("UnusedParameters") SyncExecutor syncExecutor, - InventoryHelper inventoryHelper, + public FlavorSetup(GtasksPreferenceService gtasksPreferenceService, InventoryHelper inventoryHelper, SyncAdapterHelper syncAdapterHelper, PlayServicesAvailability playServicesAvailability) { this.gtasksPreferenceService = gtasksPreferenceService; this.inventoryHelper = inventoryHelper; diff --git a/src/googleplay/java/org/tasks/analytics/Tracker.java b/src/googleplay/java/org/tasks/analytics/Tracker.java index 6bdc0abfd..8c0a965d7 100644 --- a/src/googleplay/java/org/tasks/analytics/Tracker.java +++ b/src/googleplay/java/org/tasks/analytics/Tracker.java @@ -12,14 +12,14 @@ import com.google.common.base.Strings; import org.tasks.BuildConfig; import org.tasks.R; +import org.tasks.injection.ApplicationScope; import org.tasks.injection.ForApplication; import javax.inject.Inject; -import javax.inject.Singleton; import timber.log.Timber; -@Singleton +@ApplicationScope public class Tracker { private final GoogleAnalytics analytics; diff --git a/src/googleplay/java/org/tasks/billing/InventoryHelper.java b/src/googleplay/java/org/tasks/billing/InventoryHelper.java index 7b1792ebc..69f507719 100644 --- a/src/googleplay/java/org/tasks/billing/InventoryHelper.java +++ b/src/googleplay/java/org/tasks/billing/InventoryHelper.java @@ -11,6 +11,7 @@ import com.android.vending.billing.Purchase; import org.tasks.Broadcaster; import org.tasks.R; +import org.tasks.injection.ApplicationScope; import org.tasks.injection.ForApplication; import org.tasks.preferences.Preferences; @@ -18,11 +19,10 @@ import java.util.concurrent.Executor; import javax.inject.Inject; import javax.inject.Named; -import javax.inject.Singleton; import timber.log.Timber; -@Singleton +@ApplicationScope public class InventoryHelper implements IabBroadcastReceiver.IabBroadcastListener { private final Context context; diff --git a/src/googleplay/java/org/tasks/billing/PurchaseHelper.java b/src/googleplay/java/org/tasks/billing/PurchaseHelper.java index a348d72e4..0bab1351a 100644 --- a/src/googleplay/java/org/tasks/billing/PurchaseHelper.java +++ b/src/googleplay/java/org/tasks/billing/PurchaseHelper.java @@ -16,6 +16,7 @@ import org.tasks.BuildConfig; import org.tasks.R; import org.tasks.analytics.Tracker; import org.tasks.dialogs.DialogBuilder; +import org.tasks.injection.ApplicationScope; import org.tasks.injection.ForApplication; import org.tasks.preferences.Preferences; @@ -25,13 +26,12 @@ import java.util.concurrent.Executor; import javax.inject.Inject; import javax.inject.Named; -import javax.inject.Singleton; import timber.log.Timber; import static com.todoroo.andlib.utility.AndroidUtilities.isAppInstalled; -@Singleton +@ApplicationScope public class PurchaseHelper implements IabHelper.OnIabSetupFinishedListener { private final Context context; diff --git a/src/googleplay/java/org/tasks/injection/ActivityComponent.java b/src/googleplay/java/org/tasks/injection/ActivityComponent.java index f4a29a438..65a1000bb 100644 --- a/src/googleplay/java/org/tasks/injection/ActivityComponent.java +++ b/src/googleplay/java/org/tasks/injection/ActivityComponent.java @@ -6,11 +6,9 @@ import com.todoroo.astrid.gtasks.auth.GtasksLoginActivity; import org.tasks.dashclock.DashClockSettings; import org.tasks.locale.ui.activity.TaskerSettingsActivity; -import javax.inject.Singleton; - import dagger.Subcomponent; -@Singleton +@ActivityScope @Subcomponent(modules = ActivityModule.class) public interface ActivityComponent extends BaseActivityComponent { diff --git a/src/googleplay/java/org/tasks/injection/ApplicationComponent.java b/src/googleplay/java/org/tasks/injection/ApplicationComponent.java index 67139d230..d153226c3 100644 --- a/src/googleplay/java/org/tasks/injection/ApplicationComponent.java +++ b/src/googleplay/java/org/tasks/injection/ApplicationComponent.java @@ -1,10 +1,8 @@ package org.tasks.injection; -import javax.inject.Singleton; - import dagger.Component; -@Singleton +@ApplicationScope @Component(modules = ApplicationModule.class) public interface ApplicationComponent extends BaseApplicationComponent { SyncAdapterComponent plus(SyncAdapterModule syncAdapterModule); diff --git a/src/main/java/com/todoroo/astrid/alarms/AlarmService.java b/src/main/java/com/todoroo/astrid/alarms/AlarmService.java index 3235f145f..d95c4a67a 100644 --- a/src/main/java/com/todoroo/astrid/alarms/AlarmService.java +++ b/src/main/java/com/todoroo/astrid/alarms/AlarmService.java @@ -24,6 +24,7 @@ import com.todoroo.astrid.data.Task; import com.todoroo.astrid.reminders.ReminderService; import com.todoroo.astrid.service.SynchronizeMetadataCallback; +import org.tasks.injection.ApplicationScope; import org.tasks.injection.ForApplication; import org.tasks.receivers.TaskNotificationReceiver; import org.tasks.scheduling.AlarmManager; @@ -35,7 +36,6 @@ import java.util.Map; import java.util.Set; import javax.inject.Inject; -import javax.inject.Singleton; /** * Provides operations for working with alerts @@ -43,7 +43,7 @@ import javax.inject.Singleton; * @author Tim Su * */ -@Singleton +@ApplicationScope public class AlarmService { private static final long NO_ALARM = Long.MAX_VALUE; diff --git a/src/main/java/com/todoroo/astrid/dao/Database.java b/src/main/java/com/todoroo/astrid/dao/Database.java index fb7f7e176..a119f2d4a 100644 --- a/src/main/java/com/todoroo/astrid/dao/Database.java +++ b/src/main/java/com/todoroo/astrid/dao/Database.java @@ -30,10 +30,10 @@ import com.todoroo.astrid.provider.Astrid2TaskProvider; import com.todoroo.astrid.provider.Astrid3ContentProvider; import org.tasks.analytics.Tracker; +import org.tasks.injection.ApplicationScope; import org.tasks.injection.ForApplication; import javax.inject.Inject; -import javax.inject.Singleton; import timber.log.Timber; @@ -43,7 +43,7 @@ import timber.log.Timber; * @author Tim Su * */ -@Singleton +@ApplicationScope public class Database { private static final int VERSION = 36; diff --git a/src/main/java/com/todoroo/astrid/dao/MetadataDao.java b/src/main/java/com/todoroo/astrid/dao/MetadataDao.java index c9ba78d48..5569a0f97 100644 --- a/src/main/java/com/todoroo/astrid/dao/MetadataDao.java +++ b/src/main/java/com/todoroo/astrid/dao/MetadataDao.java @@ -15,10 +15,11 @@ import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.Task; +import org.tasks.injection.ApplicationScope; + import java.util.List; import javax.inject.Inject; -import javax.inject.Singleton; /** * Data Access layer for {@link Metadata}-related operations. @@ -26,7 +27,7 @@ import javax.inject.Singleton; * @author Tim Su * */ -@Singleton +@ApplicationScope public class MetadataDao { private final DatabaseDao dao; diff --git a/src/main/java/com/todoroo/astrid/dao/TagDataDao.java b/src/main/java/com/todoroo/astrid/dao/TagDataDao.java index 3ee40e2f0..0e4d5f5e7 100644 --- a/src/main/java/com/todoroo/astrid/dao/TagDataDao.java +++ b/src/main/java/com/todoroo/astrid/dao/TagDataDao.java @@ -6,7 +6,6 @@ package com.todoroo.astrid.dao; import com.todoroo.andlib.data.Callback; -import com.todoroo.andlib.data.DatabaseDao; import com.todoroo.andlib.data.Property; import com.todoroo.andlib.sql.Criterion; import com.todoroo.andlib.sql.Functions; @@ -15,15 +14,16 @@ import com.todoroo.andlib.sql.Query; import com.todoroo.astrid.data.RemoteModel; import com.todoroo.astrid.data.TagData; +import org.tasks.injection.ApplicationScope; + import javax.inject.Inject; -import javax.inject.Singleton; /** * Data Access layer for {@link TagData}-related operations. * * @author Tim Su */ -@Singleton +@ApplicationScope public class TagDataDao { private final RemoteModelDao dao; diff --git a/src/main/java/com/todoroo/astrid/dao/TaskDao.java b/src/main/java/com/todoroo/astrid/dao/TaskDao.java index bcbfa74f3..d2fbcd706 100644 --- a/src/main/java/com/todoroo/astrid/dao/TaskDao.java +++ b/src/main/java/com/todoroo/astrid/dao/TaskDao.java @@ -26,6 +26,7 @@ import com.todoroo.astrid.reminders.ReminderService; import org.tasks.Broadcaster; import org.tasks.R; +import org.tasks.injection.ApplicationScope; import org.tasks.location.GeofenceService; import org.tasks.notifications.NotificationManager; import org.tasks.preferences.Preferences; @@ -33,7 +34,6 @@ import org.tasks.preferences.Preferences; import java.util.List; import javax.inject.Inject; -import javax.inject.Singleton; import timber.log.Timber; @@ -43,7 +43,7 @@ import timber.log.Timber; * @author Tim Su * */ -@Singleton +@ApplicationScope public class TaskDao { public static final String TRANS_SUPPRESS_REFRESH = "suppress-refresh"; diff --git a/src/main/java/com/todoroo/astrid/gcal/CalendarReminderActivity.java b/src/main/java/com/todoroo/astrid/gcal/CalendarReminderActivity.java index f3b272725..d7646c608 100644 --- a/src/main/java/com/todoroo/astrid/gcal/CalendarReminderActivity.java +++ b/src/main/java/com/todoroo/astrid/gcal/CalendarReminderActivity.java @@ -18,7 +18,6 @@ import org.tasks.injection.ActivityComponent; import org.tasks.injection.ThemedInjectingAppCompatActivity; import org.tasks.preferences.BasicPreferences; import org.tasks.preferences.Preferences; -import org.tasks.preferences.ResourceResolver; import org.tasks.scheduling.AlarmManager; import org.tasks.scheduling.CalendarNotificationIntentService; import org.tasks.themes.ThemeAccent; @@ -39,7 +38,6 @@ public class CalendarReminderActivity extends ThemedInjectingAppCompatActivity { private static final int IGNORE_PROMPT_COUNT = 3; @Inject Preferences preferences; - @Inject ResourceResolver resourceResolver; @Inject DialogBuilder dialogBuilder; @Inject AlarmManager alarmManager; @Inject ThemeAccent themeAccent; diff --git a/src/main/java/com/todoroo/astrid/gtasks/GtasksMetadata.java b/src/main/java/com/todoroo/astrid/gtasks/GtasksMetadata.java index 6aaa725c7..87b31cc15 100644 --- a/src/main/java/com/todoroo/astrid/gtasks/GtasksMetadata.java +++ b/src/main/java/com/todoroo/astrid/gtasks/GtasksMetadata.java @@ -13,14 +13,12 @@ import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.astrid.data.Metadata; import javax.inject.Inject; -import javax.inject.Singleton; /** * Metadata entries for a GTasks Task * @author Tim Su * */ -@Singleton public class GtasksMetadata { /** metadata key */ diff --git a/src/main/java/com/todoroo/astrid/reminders/ReminderService.java b/src/main/java/com/todoroo/astrid/reminders/ReminderService.java index a3c0b2c43..71006844b 100644 --- a/src/main/java/com/todoroo/astrid/reminders/ReminderService.java +++ b/src/main/java/com/todoroo/astrid/reminders/ReminderService.java @@ -19,6 +19,7 @@ import com.todoroo.astrid.dao.TaskDao.TaskCriteria; import com.todoroo.astrid.data.Task; import org.tasks.R; +import org.tasks.injection.ApplicationScope; import org.tasks.injection.ForApplication; import org.tasks.preferences.Preferences; import org.tasks.receivers.TaskNotificationReceiver; @@ -28,7 +29,6 @@ import org.tasks.time.DateTime; import java.util.Random; import javax.inject.Inject; -import javax.inject.Singleton; import timber.log.Timber; @@ -40,7 +40,7 @@ import static org.tasks.date.DateTimeUtils.newDateTime; * @author Tim Su * */ -@Singleton +@ApplicationScope public final class ReminderService { // --- constants diff --git a/src/main/java/com/todoroo/astrid/service/TaskService.java b/src/main/java/com/todoroo/astrid/service/TaskService.java index 1adfcf8a7..0d1e6c55d 100644 --- a/src/main/java/com/todoroo/astrid/service/TaskService.java +++ b/src/main/java/com/todoroo/astrid/service/TaskService.java @@ -27,13 +27,13 @@ import com.todoroo.astrid.tags.TaskToTagMetadata; import com.todoroo.astrid.utility.TitleParser; import org.tasks.Broadcaster; +import org.tasks.injection.ApplicationScope; import org.tasks.scheduling.RefreshScheduler; import java.util.ArrayList; import java.util.Map.Entry; import javax.inject.Inject; -import javax.inject.Singleton; import timber.log.Timber; @@ -44,7 +44,7 @@ import timber.log.Timber; * @author Tim Su * */ -@Singleton +@ApplicationScope public class TaskService { private final TagDataDao tagDataDao; diff --git a/src/main/java/com/todoroo/astrid/tags/TagService.java b/src/main/java/com/todoroo/astrid/tags/TagService.java index 5861b82b4..597738bce 100644 --- a/src/main/java/com/todoroo/astrid/tags/TagService.java +++ b/src/main/java/com/todoroo/astrid/tags/TagService.java @@ -23,11 +23,12 @@ import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.TagData; import com.todoroo.astrid.data.Task; +import org.tasks.injection.ApplicationScope; + import java.util.ArrayList; import java.util.List; import javax.inject.Inject; -import javax.inject.Singleton; import static com.google.common.collect.Lists.newArrayList; import static com.google.common.collect.Lists.transform; @@ -38,7 +39,7 @@ import static com.google.common.collect.Lists.transform; * @author Tim Su * */ -@Singleton +@ApplicationScope public final class TagService { private final MetadataDao metadataDao; diff --git a/src/main/java/org/tasks/Broadcaster.java b/src/main/java/org/tasks/Broadcaster.java index 5f542006c..2e2c785fe 100644 --- a/src/main/java/org/tasks/Broadcaster.java +++ b/src/main/java/org/tasks/Broadcaster.java @@ -12,9 +12,7 @@ import org.tasks.receivers.CompleteTaskReceiver; import org.tasks.receivers.FirstLaunchReceiver; import javax.inject.Inject; -import javax.inject.Singleton; -@Singleton public class Broadcaster { private final Context context; diff --git a/src/main/java/org/tasks/Tasks.java b/src/main/java/org/tasks/Tasks.java index 3adecb83c..a409a5110 100644 --- a/src/main/java/org/tasks/Tasks.java +++ b/src/main/java/org/tasks/Tasks.java @@ -1,12 +1,6 @@ package org.tasks; -import com.todoroo.astrid.dao.MetadataDao; -import com.todoroo.astrid.dao.StoreObjectDao; -import com.todoroo.astrid.dao.TagDataDao; -import com.todoroo.astrid.dao.TaskDao; import com.todoroo.astrid.service.StartupService; -import com.todoroo.astrid.service.TaskService; -import com.todoroo.astrid.tags.TagService; import org.tasks.analytics.Tracker; import org.tasks.injection.ApplicationComponent; @@ -17,17 +11,9 @@ import org.tasks.themes.ThemeCache; import javax.inject.Inject; -@SuppressWarnings("UnusedDeclaration") public class Tasks extends InjectingApplication { @Inject StartupService startupService; - @Inject TaskDao taskDao; - @Inject MetadataDao metadataDao; - @Inject TagDataDao tagDataDao; - @Inject StoreObjectDao storeObjectDao; - @Inject TaskService taskService; - @Inject TagService tagService; - @Inject Broadcaster broadcaster; @Inject Preferences preferences; @Inject Tracker tracker; @Inject FlavorSetup flavorSetup; diff --git a/src/main/java/org/tasks/activities/CameraActivity.java b/src/main/java/org/tasks/activities/CameraActivity.java index 40b93f81b..30c61cbff 100644 --- a/src/main/java/org/tasks/activities/CameraActivity.java +++ b/src/main/java/org/tasks/activities/CameraActivity.java @@ -1,6 +1,5 @@ package org.tasks.activities; -import android.app.Activity; import android.content.ClipData; import android.content.Intent; import android.net.Uri; @@ -31,7 +30,6 @@ public class CameraActivity extends InjectingAppCompatActivity { public static final String EXTRA_URI = "extra_uri"; @Inject Preferences preferences; - @Inject Activity activity; private File output; @@ -44,7 +42,7 @@ public class CameraActivity extends InjectingAppCompatActivity { } else { output = getFilename(".jpeg"); if (output == null) { - Toast.makeText(activity, R.string.external_storage_unavailable, Toast.LENGTH_LONG).show(); + Toast.makeText(this, R.string.external_storage_unavailable, Toast.LENGTH_LONG).show(); } else { final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); Uri uri = Uri.fromFile(output); @@ -54,7 +52,7 @@ public class CameraActivity extends InjectingAppCompatActivity { if (atLeastLollipop()) { intent.setClipData(ClipData.newRawUri(null, uri)); } - activity.startActivityForResult(intent, REQUEST_CODE_CAMERA); + startActivityForResult(intent, REQUEST_CODE_CAMERA); } } } diff --git a/src/main/java/org/tasks/injection/ActivityModule.java b/src/main/java/org/tasks/injection/ActivityModule.java index 8d24516dc..c0a948ba6 100644 --- a/src/main/java/org/tasks/injection/ActivityModule.java +++ b/src/main/java/org/tasks/injection/ActivityModule.java @@ -1,6 +1,7 @@ package org.tasks.injection; import android.app.Activity; +import android.content.Context; import org.tasks.R; import org.tasks.fragments.TaskEditControlSetFragmentManager; @@ -11,8 +12,6 @@ import org.tasks.themes.ThemeBase; import org.tasks.themes.ThemeCache; import org.tasks.themes.ThemeColor; -import javax.inject.Singleton; - import dagger.Module; import dagger.Provides; @@ -31,25 +30,31 @@ public class ActivityModule { } @Provides - @Singleton + @ForActivity + public Context getActivityContext() { + return activity; + } + + @Provides + @ActivityScope public ThemeBase getThemeBase(ThemeCache themeCache, Preferences preferences) { return themeCache.getThemeBase(preferences.getInt(R.string.p_theme, 0)); } @Provides - @Singleton + @ActivityScope public ThemeColor getThemeColor(ThemeCache themeCache, Preferences preferences) { return themeCache.getThemeColor(preferences.getInt(R.string.p_theme_color, 0)); } @Provides - @Singleton + @ActivityScope public ThemeAccent getThemeAccent(ThemeCache themeCache, Preferences preferences) { return themeCache.getThemeAccent(preferences.getInt(R.string.p_theme_accent, 1)); } @Provides - @Singleton + @ActivityScope public TaskEditControlSetFragmentManager getTaskEditControlSetFragmentManager(Preferences preferences, SyncAdapterHelper syncAdapterHelper) { return new TaskEditControlSetFragmentManager(activity, preferences, syncAdapterHelper); } diff --git a/src/main/java/org/tasks/injection/ActivityScope.java b/src/main/java/org/tasks/injection/ActivityScope.java new file mode 100644 index 000000000..45c149e64 --- /dev/null +++ b/src/main/java/org/tasks/injection/ActivityScope.java @@ -0,0 +1,11 @@ +package org.tasks.injection; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import javax.inject.Scope; + +@Scope +@Retention(RetentionPolicy.RUNTIME) +public @interface ActivityScope { +} diff --git a/src/main/java/org/tasks/injection/ApplicationModule.java b/src/main/java/org/tasks/injection/ApplicationModule.java index 971a0bc98..03cfbf457 100644 --- a/src/main/java/org/tasks/injection/ApplicationModule.java +++ b/src/main/java/org/tasks/injection/ApplicationModule.java @@ -12,7 +12,6 @@ import org.tasks.ui.WidgetCheckBoxes; import java.util.concurrent.Executor; import javax.inject.Named; -import javax.inject.Singleton; import dagger.Module; import dagger.Provides; @@ -40,26 +39,26 @@ public class ApplicationModule { } @Provides - @Singleton + @ApplicationScope @Named("iab-executor") public Executor getIabExecutor(Tracker tracker) { return new ErrorReportingSingleThreadExecutor("iab-executor", tracker); } @Provides - @Singleton + @ApplicationScope public CheckBoxes getCheckBoxes() { return newCheckBoxes(context); } @Provides - @Singleton + @ApplicationScope public WidgetCheckBoxes getWidgetCheckBoxes(CheckBoxes checkBoxes) { return newWidgetCheckBoxes(checkBoxes); } @Provides - @Singleton + @ApplicationScope public ThemeCache getThemeCache() { return new ThemeCache(context); } diff --git a/src/main/java/org/tasks/injection/ApplicationScope.java b/src/main/java/org/tasks/injection/ApplicationScope.java new file mode 100644 index 000000000..b6357cd85 --- /dev/null +++ b/src/main/java/org/tasks/injection/ApplicationScope.java @@ -0,0 +1,11 @@ +package org.tasks.injection; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import javax.inject.Scope; + +@Scope +@Retention(RetentionPolicy.RUNTIME) +public @interface ApplicationScope { +} \ No newline at end of file diff --git a/src/main/java/org/tasks/injection/BaseApplicationComponent.java b/src/main/java/org/tasks/injection/BaseApplicationComponent.java index 718581f6c..a956c687f 100644 --- a/src/main/java/org/tasks/injection/BaseApplicationComponent.java +++ b/src/main/java/org/tasks/injection/BaseApplicationComponent.java @@ -2,10 +2,6 @@ package org.tasks.injection; import org.tasks.Tasks; -import javax.inject.Singleton; - -import dagger.Component; - public interface BaseApplicationComponent { Tasks inject(Tasks tasks); diff --git a/src/main/java/org/tasks/injection/ContentProviderComponent.java b/src/main/java/org/tasks/injection/ContentProviderComponent.java index 576fc32ca..ced6a7464 100644 --- a/src/main/java/org/tasks/injection/ContentProviderComponent.java +++ b/src/main/java/org/tasks/injection/ContentProviderComponent.java @@ -4,11 +4,9 @@ import com.todoroo.astrid.provider.Astrid2TaskProvider; import com.todoroo.astrid.provider.Astrid3ContentProvider; import com.todoroo.astrid.provider.SqlContentProvider; -import javax.inject.Singleton; - import dagger.Component; -@Singleton +@ApplicationScope @Component(modules = { ApplicationModule.class, ContentProviderModule.class diff --git a/src/main/java/org/tasks/injection/DialogFragmentModule.java b/src/main/java/org/tasks/injection/DialogFragmentModule.java index a0c658579..7c2f8bf6b 100644 --- a/src/main/java/org/tasks/injection/DialogFragmentModule.java +++ b/src/main/java/org/tasks/injection/DialogFragmentModule.java @@ -1,7 +1,5 @@ package org.tasks.injection; -import android.app.Activity; -import android.content.Context; import android.support.v4.app.DialogFragment; import android.support.v4.app.Fragment; @@ -16,19 +14,8 @@ public class DialogFragmentModule { this.dialogFragment = dialogFragment; } - @Provides - public Activity getActivity() { - return dialogFragment.getActivity(); - } - @Provides public Fragment getFragment() { return dialogFragment; } - - @Provides - @ForActivity - public Context getContext() { - return dialogFragment.getActivity(); - } } diff --git a/src/main/java/org/tasks/injection/FragmentModule.java b/src/main/java/org/tasks/injection/FragmentModule.java index ce4a229ab..7456283fb 100644 --- a/src/main/java/org/tasks/injection/FragmentModule.java +++ b/src/main/java/org/tasks/injection/FragmentModule.java @@ -1,6 +1,5 @@ package org.tasks.injection; -import android.content.Context; import android.support.v4.app.Fragment; import dagger.Module; @@ -14,12 +13,6 @@ public class FragmentModule { this.fragment = fragment; } - @Provides - @ForActivity - public Context getContext() { - return fragment.getActivity(); - } - @Provides public Fragment getFragment() { return fragment; diff --git a/src/main/java/org/tasks/location/GeofenceService.java b/src/main/java/org/tasks/location/GeofenceService.java index 71dc02474..485b4b362 100644 --- a/src/main/java/org/tasks/location/GeofenceService.java +++ b/src/main/java/org/tasks/location/GeofenceService.java @@ -22,12 +22,10 @@ import java.util.Map; import java.util.Set; import javax.inject.Inject; -import javax.inject.Singleton; import static com.google.common.collect.Iterables.transform; import static com.google.common.collect.Lists.newArrayList; -@Singleton public class GeofenceService { private final MetadataDao metadataDao; diff --git a/src/main/java/org/tasks/notifications/NotificationManager.java b/src/main/java/org/tasks/notifications/NotificationManager.java index 898b4528d..fc5164c96 100644 --- a/src/main/java/org/tasks/notifications/NotificationManager.java +++ b/src/main/java/org/tasks/notifications/NotificationManager.java @@ -8,9 +8,7 @@ import org.tasks.injection.ForApplication; import org.tasks.preferences.Preferences; import javax.inject.Inject; -import javax.inject.Singleton; -@Singleton public class NotificationManager { private final android.app.NotificationManager notificationManager; diff --git a/src/main/java/org/tasks/preferences/ResourceResolver.java b/src/main/java/org/tasks/preferences/ResourceResolver.java index aaf330588..6b5a74b2f 100644 --- a/src/main/java/org/tasks/preferences/ResourceResolver.java +++ b/src/main/java/org/tasks/preferences/ResourceResolver.java @@ -1,28 +1,11 @@ package org.tasks.preferences; -import android.app.Activity; import android.content.Context; import android.util.TypedValue; -import javax.inject.Inject; -import javax.inject.Singleton; - -@Singleton -@Deprecated public class ResourceResolver { - private final Activity activity; - - @Inject - public ResourceResolver(Activity activity) { - this.activity = activity; - } - - public int getData(int attr) { - return getData(activity, attr); - } - - public static int getData(Context context, int attr) { + @Deprecated public static int getData(Context context, int attr) { TypedValue typedValue = new TypedValue(); context.getTheme().resolveAttribute(attr, typedValue, true); return typedValue.data; diff --git a/src/main/java/org/tasks/receivers/TeslaUnreadReceiver.java b/src/main/java/org/tasks/receivers/TeslaUnreadReceiver.java index a2f6dd470..a6931ae6e 100644 --- a/src/main/java/org/tasks/receivers/TeslaUnreadReceiver.java +++ b/src/main/java/org/tasks/receivers/TeslaUnreadReceiver.java @@ -13,17 +13,17 @@ import com.todoroo.astrid.dao.TaskDao; import org.tasks.Broadcaster; import org.tasks.BuildConfig; import org.tasks.analytics.Tracker; +import org.tasks.injection.ApplicationScope; import org.tasks.injection.BroadcastComponent; import org.tasks.injection.ForApplication; import org.tasks.injection.InjectingBroadcastReceiver; import org.tasks.preferences.DefaultFilterProvider; import javax.inject.Inject; -import javax.inject.Singleton; import timber.log.Timber; -@Singleton +@ApplicationScope public class TeslaUnreadReceiver extends InjectingBroadcastReceiver { private static final String TESLA_URI = "content://com.teslacoilsw.notifier/unread_count"; diff --git a/src/main/java/org/tasks/sync/SyncExecutor.java b/src/main/java/org/tasks/sync/SyncExecutor.java index 7f5776b86..b5df5389d 100644 --- a/src/main/java/org/tasks/sync/SyncExecutor.java +++ b/src/main/java/org/tasks/sync/SyncExecutor.java @@ -4,18 +4,18 @@ import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.todoroo.astrid.sync.SyncResultCallback; import org.tasks.analytics.Tracker; +import org.tasks.injection.ApplicationScope; import java.util.concurrent.ExecutorService; import java.util.concurrent.RejectedExecutionException; import javax.inject.Inject; -import javax.inject.Singleton; import timber.log.Timber; import static java.util.concurrent.Executors.newSingleThreadExecutor; -@Singleton +@ApplicationScope public class SyncExecutor { private final ExecutorService executor = newSingleThreadExecutor(