diff --git a/src/main/java/com/todoroo/andlib/service/ContextManager.java b/src/main/java/com/todoroo/andlib/service/ContextManager.java deleted file mode 100644 index 264f83d4a..000000000 --- a/src/main/java/com/todoroo/andlib/service/ContextManager.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * Copyright (c) 2012 Todoroo Inc - * - * See the file "LICENSE" for the full license governing this code. - */ -package com.todoroo.andlib.service; - -import android.app.Activity; -import android.content.Context; - -/** - * Singleton class to manage current application context - * b - * @author Tim Su - * - */ -@Deprecated -public final class ContextManager { - - /** - * Global application context - */ - private static Context context = null; - - /** - * Sets the global context - */ - public static void setContext(Context context) { - if(context == null || context.getApplicationContext() == null) { - return; - } - if(ContextManager.context != null && !(context instanceof Activity)) { - return; - } - ContextManager.context = context; - } - - /** - * Gets the global context - */ - public static Context getContext() { - return context; - } -} diff --git a/src/main/java/com/todoroo/andlib/utility/Preferences.java b/src/main/java/com/todoroo/andlib/utility/Preferences.java index 46b2aad2c..77752121b 100644 --- a/src/main/java/com/todoroo/andlib/utility/Preferences.java +++ b/src/main/java/com/todoroo/andlib/utility/Preferences.java @@ -9,8 +9,6 @@ import android.content.Context; import android.content.SharedPreferences; import android.preference.PreferenceManager; -import com.todoroo.andlib.service.ContextManager; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -49,8 +47,7 @@ public class Preferences { return preferences; } - public static boolean getBoolean(int keyResources, boolean defValue) { - Context context = ContextManager.getContext(); + public static boolean getBoolean(Context context, int keyResources, boolean defValue) { try { return getPrefs(context).getBoolean(context.getString(keyResources), defValue); } catch (ClassCastException e) { diff --git a/src/main/java/com/todoroo/astrid/actfm/ActFmGoogleAuthActivity.java b/src/main/java/com/todoroo/astrid/actfm/ActFmGoogleAuthActivity.java index 15ba37b18..13b97dbcb 100644 --- a/src/main/java/com/todoroo/astrid/actfm/ActFmGoogleAuthActivity.java +++ b/src/main/java/com/todoroo/astrid/actfm/ActFmGoogleAuthActivity.java @@ -22,7 +22,6 @@ import android.widget.TextView; import android.widget.Toast; import com.google.api.client.googleapis.extensions.android.accounts.GoogleAccountManager; -import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.utility.DialogUtilities; import org.slf4j.Logger; @@ -63,7 +62,6 @@ public class ActFmGoogleAuthActivity extends ListActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - ContextManager.setContext(this); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.gtasks_login_activity); diff --git a/src/main/java/com/todoroo/astrid/activity/AstridActivity.java b/src/main/java/com/todoroo/astrid/activity/AstridActivity.java index 2765d98e0..051682f30 100644 --- a/src/main/java/com/todoroo/astrid/activity/AstridActivity.java +++ b/src/main/java/com/todoroo/astrid/activity/AstridActivity.java @@ -15,7 +15,6 @@ import android.view.View; import android.view.WindowManager.BadTokenException; import com.todoroo.andlib.data.Property; -import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.api.Filter; @@ -33,7 +32,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.tasks.R; import org.tasks.injection.InjectingActionBarActivity; -import org.tasks.preferences.Preferences; import org.tasks.ui.NavigationDrawerFragment; import javax.inject.Inject; @@ -77,13 +75,12 @@ public class AstridActivity extends InjectingActionBarActivity @Inject TaskService taskService; @Inject StartupService startupService; @Inject GCalHelper gcalHelper; - @Inject Preferences preferences; @Inject DateChangedAlerts dateChangedAlerts; + @Inject SubtasksHelper subtasksHelper; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - ContextManager.setContext(this); startupService.onStartupApplication(this); } @@ -163,7 +160,7 @@ public class AstridActivity extends InjectingActionBarActivity public void setupTasklistFragmentWithFilter(Filter filter, Bundle extras) { Class customTaskList = null; - if (SubtasksHelper.shouldUseSubtasksFragmentForFilter(preferences, filter)) { + if (subtasksHelper.shouldUseSubtasksFragmentForFilter(filter)) { customTaskList = SubtasksHelper.subtasksClassForFilter(filter); } diff --git a/src/main/java/com/todoroo/astrid/activity/EditPreferences.java b/src/main/java/com/todoroo/astrid/activity/EditPreferences.java index 284b0e70d..159dea8cd 100644 --- a/src/main/java/com/todoroo/astrid/activity/EditPreferences.java +++ b/src/main/java/com/todoroo/astrid/activity/EditPreferences.java @@ -19,7 +19,6 @@ import android.preference.PreferenceScreen; import android.speech.tts.TextToSpeech; import android.text.TextUtils; -import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.data.TaskAttachment; @@ -94,7 +93,6 @@ public class EditPreferences extends TodorooPreferenceActivity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); startupService.onStartupApplication(this); - ContextManager.setContext(this); PreferenceScreen screen = getPreferenceScreen(); diff --git a/src/main/java/com/todoroo/astrid/activity/FilterShortcutActivity.java b/src/main/java/com/todoroo/astrid/activity/FilterShortcutActivity.java index fa733a0e9..855894484 100644 --- a/src/main/java/com/todoroo/astrid/activity/FilterShortcutActivity.java +++ b/src/main/java/com/todoroo/astrid/activity/FilterShortcutActivity.java @@ -5,6 +5,7 @@ */ package com.todoroo.astrid.activity; +import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; import android.os.Bundle; @@ -19,6 +20,7 @@ import com.todoroo.astrid.api.Filter; import org.tasks.R; import org.tasks.filters.FilterCounter; import org.tasks.filters.FilterProvider; +import org.tasks.injection.ForApplication; import org.tasks.injection.InjectingListActivity; import org.tasks.preferences.ActivityPreferences; import org.tasks.ui.NavigationDrawerFragment; @@ -30,6 +32,7 @@ public class FilterShortcutActivity extends InjectingListActivity { @Inject FilterCounter filterCounter; @Inject ActivityPreferences preferences; @Inject FilterProvider filterProvider; + @Inject @ForApplication Context context; private FilterAdapter adapter = null; @@ -62,7 +65,7 @@ public class FilterShortcutActivity extends InjectingListActivity { DialogUtilities.okDialog(FilterShortcutActivity.this, getString(R.string.FLA_no_filter_selected), null); return; } - Intent shortcutIntent = ShortcutActivity.createIntent(filter); + Intent shortcutIntent = ShortcutActivity.createIntent(context, filter); Bitmap bitmap = NavigationDrawerFragment.superImposeListIcon(FilterShortcutActivity.this); Intent intent = new Intent(); diff --git a/src/main/java/com/todoroo/astrid/activity/ShortcutActivity.java b/src/main/java/com/todoroo/astrid/activity/ShortcutActivity.java index dcdf7d633..92b870e04 100644 --- a/src/main/java/com/todoroo/astrid/activity/ShortcutActivity.java +++ b/src/main/java/com/todoroo/astrid/activity/ShortcutActivity.java @@ -8,10 +8,10 @@ package com.todoroo.astrid.activity; import android.app.Activity; import android.content.ComponentName; import android.content.ContentValues; +import android.content.Context; import android.content.Intent; import android.os.Bundle; -import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.sql.QueryTemplate; import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.astrid.api.Filter; @@ -73,7 +73,6 @@ public class ShortcutActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - ContextManager.setContext(this); launchTaskList(getIntent()); } @@ -168,9 +167,8 @@ public class ShortcutActivity extends Activity { finish(); } - public static Intent createIntent(Filter filter) { - Intent shortcutIntent = new Intent(ContextManager.getContext(), - ShortcutActivity.class); + public static Intent createIntent(Context context, Filter filter) { + Intent shortcutIntent = new Intent(context, ShortcutActivity.class); if(filter instanceof FilterWithCustomIntent) { FilterWithCustomIntent customFilter = ((FilterWithCustomIntent)filter); diff --git a/src/main/java/com/todoroo/astrid/activity/TaskListFragment.java b/src/main/java/com/todoroo/astrid/activity/TaskListFragment.java index 1802696fc..ff6e64cb8 100644 --- a/src/main/java/com/todoroo/astrid/activity/TaskListFragment.java +++ b/src/main/java/com/todoroo/astrid/activity/TaskListFragment.java @@ -356,10 +356,10 @@ public class TaskListFragment extends InjectingListFragment implements OnSortSel filter = BuiltInFilterExposer.getMyTasksFilter(resources); } filter.setFilterQueryOverride(null); - isInbox = BuiltInFilterExposer.isInbox(filter); + isInbox = BuiltInFilterExposer.isInbox(context, filter); isTodayFilter = false; if (!isInbox) { - isTodayFilter = BuiltInFilterExposer.isTodayFilter(filter); + isTodayFilter = BuiltInFilterExposer.isTodayFilter(context, filter); } initializeTaskListMetadata(); @@ -627,7 +627,7 @@ public class TaskListFragment extends InjectingListFragment implements OnSortSel protected TaskAdapter createTaskAdapter(TodorooCursor cursor) { - return new TaskAdapter(preferences, taskAttachmentDao, taskService, this, cursor, sqlQueryTemplate, + return new TaskAdapter(context, preferences, taskAttachmentDao, taskService, this, cursor, sqlQueryTemplate, new OnCompletedTaskListener() { @Override public void onCompletedTask(Task item, boolean newState) { diff --git a/src/main/java/com/todoroo/astrid/adapter/TaskAdapter.java b/src/main/java/com/todoroo/astrid/adapter/TaskAdapter.java index 6a74ad556..cfbdc50de 100644 --- a/src/main/java/com/todoroo/astrid/adapter/TaskAdapter.java +++ b/src/main/java/com/todoroo/astrid/adapter/TaskAdapter.java @@ -35,8 +35,6 @@ import com.todoroo.andlib.data.Property.IntegerProperty; import com.todoroo.andlib.data.Property.LongProperty; import com.todoroo.andlib.data.Property.StringProperty; import com.todoroo.andlib.data.TodorooCursor; -import com.todoroo.andlib.service.ContextManager; -import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.Pair; import com.todoroo.astrid.activity.TaskListFragment; @@ -173,13 +171,13 @@ public class TaskAdapter extends CursorAdapter implements Filterable { private final Map taskActionLoader = Collections.synchronizedMap(new HashMap()); - public TaskAdapter(ActivityPreferences preferences, TaskAttachmentDao taskAttachmentDao, TaskService taskService, TaskListFragment fragment, + public TaskAdapter(Context context, ActivityPreferences preferences, TaskAttachmentDao taskAttachmentDao, TaskService taskService, TaskListFragment fragment, Cursor c, AtomicReference query, OnCompletedTaskListener onCompletedTaskListener) { - super(ContextManager.getContext(), c, false); + super(context, c, false); this.preferences = preferences; this.taskAttachmentDao = taskAttachmentDao; this.taskService = taskService; - this.context = ContextManager.getContext(); + this.context = context; this.query = query; this.fragment = fragment; this.resources = fragment.getResources(); diff --git a/src/main/java/com/todoroo/astrid/alarms/AlarmTaskRepeatListener.java b/src/main/java/com/todoroo/astrid/alarms/AlarmTaskRepeatListener.java index 6c057092c..9a053d4d6 100644 --- a/src/main/java/com/todoroo/astrid/alarms/AlarmTaskRepeatListener.java +++ b/src/main/java/com/todoroo/astrid/alarms/AlarmTaskRepeatListener.java @@ -9,7 +9,6 @@ import android.content.Context; import android.content.Intent; import com.todoroo.andlib.data.Callback; -import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.data.Metadata; @@ -29,7 +28,6 @@ public class AlarmTaskRepeatListener extends InjectingBroadcastReceiver { public void onReceive(Context context, Intent intent) { super.onReceive(context, intent); - ContextManager.setContext(context); long taskId = intent.getLongExtra(AstridApiConstants.EXTRAS_TASK_ID, -1); if(taskId == -1) { return; diff --git a/src/main/java/com/todoroo/astrid/api/Filter.java b/src/main/java/com/todoroo/astrid/api/Filter.java index 1ea7e977f..4f2175466 100644 --- a/src/main/java/com/todoroo/astrid/api/Filter.java +++ b/src/main/java/com/todoroo/astrid/api/Filter.java @@ -220,6 +220,10 @@ public class Filter extends FilterListItem { } }; + public boolean isTagFilter() { + return false; + } + @Override public String toString() { return title; diff --git a/src/main/java/com/todoroo/astrid/api/FilterWithCustomIntent.java b/src/main/java/com/todoroo/astrid/api/FilterWithCustomIntent.java index 3ba910822..5b24301ef 100644 --- a/src/main/java/com/todoroo/astrid/api/FilterWithCustomIntent.java +++ b/src/main/java/com/todoroo/astrid/api/FilterWithCustomIntent.java @@ -14,6 +14,8 @@ import android.os.Parcel; import android.os.Parcelable; import com.todoroo.andlib.sql.QueryTemplate; +import com.todoroo.astrid.actfm.TagViewFragment; +import com.todoroo.astrid.subtasks.SubtasksTagListFragment; public class FilterWithCustomIntent extends Filter { @@ -104,4 +106,11 @@ public class FilterWithCustomIntent extends Filter { }; + @Override + public boolean isTagFilter() { + String className = customTaskList.getClassName(); + // Need to check this subclass because some shortcuts/widgets may have been saved with it + return TagViewFragment.class.getName().equals(className) + || SubtasksTagListFragment.class.getName().equals(className); + } } diff --git a/src/main/java/com/todoroo/astrid/core/BuiltInFilterExposer.java b/src/main/java/com/todoroo/astrid/core/BuiltInFilterExposer.java index 2c2fdbbed..ceb615368 100644 --- a/src/main/java/com/todoroo/astrid/core/BuiltInFilterExposer.java +++ b/src/main/java/com/todoroo/astrid/core/BuiltInFilterExposer.java @@ -9,7 +9,6 @@ import android.content.ContentValues; import android.content.Context; import android.content.res.Resources; -import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.sql.Criterion; import com.todoroo.andlib.sql.Order; import com.todoroo.andlib.sql.Query; @@ -119,11 +118,11 @@ public final class BuiltInFilterExposer { /** * Is this the inbox? */ - public static boolean isInbox(Filter filter) { - return (filter != null && filter.equals(getMyTasksFilter(ContextManager.getContext().getResources()))); + public static boolean isInbox(Context context, Filter filter) { + return (filter != null && filter.equals(getMyTasksFilter(context.getResources()))); } - public static boolean isTodayFilter(Filter filter) { - return (filter != null && filter.equals(getTodayFilter(ContextManager.getContext().getResources()))); + public static boolean isTodayFilter(Context context, Filter filter) { + return (filter != null && filter.equals(getTodayFilter(context.getResources()))); } } diff --git a/src/main/java/com/todoroo/astrid/core/CustomFilterActivity.java b/src/main/java/com/todoroo/astrid/core/CustomFilterActivity.java index c07a07a81..4175e497d 100644 --- a/src/main/java/com/todoroo/astrid/core/CustomFilterActivity.java +++ b/src/main/java/com/todoroo/astrid/core/CustomFilterActivity.java @@ -28,7 +28,6 @@ import android.widget.ListView; import android.widget.TextView; import com.todoroo.andlib.data.Property.CountProperty; -import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.sql.Criterion; import com.todoroo.andlib.sql.Field; import com.todoroo.andlib.sql.Query; @@ -155,7 +154,6 @@ public class CustomFilterActivity extends InjectingActionBarActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setupForDialogOrFullscreen(); - ContextManager.setContext(this); ActionBar ab = getSupportActionBar(); if (ab != null) { diff --git a/src/main/java/com/todoroo/astrid/gcal/CalendarStartupReceiver.java b/src/main/java/com/todoroo/astrid/gcal/CalendarStartupReceiver.java index 82debc7bf..ccf5eb11c 100644 --- a/src/main/java/com/todoroo/astrid/gcal/CalendarStartupReceiver.java +++ b/src/main/java/com/todoroo/astrid/gcal/CalendarStartupReceiver.java @@ -3,7 +3,6 @@ package com.todoroo.astrid.gcal; import android.content.Context; import android.content.Intent; -import com.todoroo.andlib.service.ContextManager; import com.todoroo.astrid.api.AstridApiConstants; import org.tasks.injection.InjectingBroadcastReceiver; @@ -20,7 +19,6 @@ public class CalendarStartupReceiver extends InjectingBroadcastReceiver { public void onReceive(Context context, Intent intent) { super.onReceive(context, intent); - ContextManager.setContext(context); calendarAlarmScheduler.scheduleCalendarAlarms(context, false); } } diff --git a/src/main/java/com/todoroo/astrid/gcal/GCalTaskCompleteListener.java b/src/main/java/com/todoroo/astrid/gcal/GCalTaskCompleteListener.java index ae5db6a93..8d8a6178d 100644 --- a/src/main/java/com/todoroo/astrid/gcal/GCalTaskCompleteListener.java +++ b/src/main/java/com/todoroo/astrid/gcal/GCalTaskCompleteListener.java @@ -12,7 +12,6 @@ import android.content.Intent; import android.net.Uri; import android.text.TextUtils; -import com.todoroo.andlib.service.ContextManager; import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.data.Task; import com.todoroo.astrid.service.TaskService; @@ -34,7 +33,6 @@ public class GCalTaskCompleteListener extends InjectingBroadcastReceiver { public void onReceive(Context context, Intent intent) { super.onReceive(context, intent); - ContextManager.setContext(context); long taskId = intent.getLongExtra(AstridApiConstants.EXTRAS_TASK_ID, -1); if(taskId == -1) { return; diff --git a/src/main/java/com/todoroo/astrid/gtasks/GtasksCustomFilterCriteriaExposer.java b/src/main/java/com/todoroo/astrid/gtasks/GtasksCustomFilterCriteriaExposer.java index 9fc1d1388..27d039a0e 100644 --- a/src/main/java/com/todoroo/astrid/gtasks/GtasksCustomFilterCriteriaExposer.java +++ b/src/main/java/com/todoroo/astrid/gtasks/GtasksCustomFilterCriteriaExposer.java @@ -12,7 +12,6 @@ import android.content.res.Resources; import android.graphics.drawable.BitmapDrawable; import com.todoroo.andlib.data.AbstractModel; -import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.sql.Criterion; import com.todoroo.andlib.sql.Join; import com.todoroo.andlib.sql.Query; @@ -43,8 +42,6 @@ public class GtasksCustomFilterCriteriaExposer extends InjectingBroadcastReceive public void onReceive(Context context, Intent intent) { super.onReceive(context, intent); - ContextManager.setContext(context); - // if we aren't logged in, don't expose sync action if(!gtasksPreferenceService.isLoggedIn()) { return; diff --git a/src/main/java/com/todoroo/astrid/gtasks/OrderedMetadataListFragmentHelper.java b/src/main/java/com/todoroo/astrid/gtasks/OrderedMetadataListFragmentHelper.java index 35cafa825..33ecf3c25 100644 --- a/src/main/java/com/todoroo/astrid/gtasks/OrderedMetadataListFragmentHelper.java +++ b/src/main/java/com/todoroo/astrid/gtasks/OrderedMetadataListFragmentHelper.java @@ -6,6 +6,7 @@ package com.todoroo.astrid.gtasks; import android.app.Activity; +import android.content.Context; import android.database.Cursor; import android.text.TextUtils; import android.util.DisplayMetrics; @@ -178,10 +179,10 @@ public class OrderedMetadataListFragmentHelper implements OrderedListFragm }; @Override - public TaskAdapter createTaskAdapter(TodorooCursor cursor, + public TaskAdapter createTaskAdapter(Context context, TodorooCursor cursor, AtomicReference sqlQueryTemplate) { - taskAdapter = new DraggableTaskAdapter(preferences, fragment, cursor, sqlQueryTemplate); + taskAdapter = new DraggableTaskAdapter(context, preferences, fragment, cursor, sqlQueryTemplate); taskAdapter.addOnCompletedTaskListener(new OnCompletedTaskListener() { @Override @@ -195,9 +196,9 @@ public class OrderedMetadataListFragmentHelper implements OrderedListFragm private final class DraggableTaskAdapter extends TaskAdapter { - private DraggableTaskAdapter(ActivityPreferences preferences, TaskListFragment activity, + private DraggableTaskAdapter(Context context, ActivityPreferences preferences, TaskListFragment activity, Cursor c, AtomicReference query) { - super(preferences, taskAttachmentDao, taskService, activity, c, query, null); + super(context, preferences, taskAttachmentDao, taskService, activity, c, query, null); } @Override diff --git a/src/main/java/com/todoroo/astrid/gtasks/api/GtasksInvoker.java b/src/main/java/com/todoroo/astrid/gtasks/api/GtasksInvoker.java index cccfe17e6..2b3beb295 100644 --- a/src/main/java/com/todoroo/astrid/gtasks/api/GtasksInvoker.java +++ b/src/main/java/com/todoroo/astrid/gtasks/api/GtasksInvoker.java @@ -14,7 +14,6 @@ import com.google.api.services.tasks.TasksRequest; import com.google.api.services.tasks.model.Task; import com.google.api.services.tasks.model.TaskList; import com.google.api.services.tasks.model.TaskLists; -import com.todoroo.andlib.service.ContextManager; import com.todoroo.astrid.gtasks.auth.GtasksTokenValidator; import org.slf4j.Logger; @@ -33,20 +32,21 @@ public class GtasksInvoker { private static final Logger log = LoggerFactory.getLogger(GtasksInvoker.class); + private final Context context; + private final GtasksTokenValidator gtasksTokenValidator; private Tasks service; private GoogleCredential credential = new GoogleCredential(); - private final GtasksTokenValidator gtasksTokenValidator; private String token; private final String key; public static final String AUTH_TOKEN_TYPE = "Manage your tasks"; //"oauth2:https://www.googleapis.com/auth/tasks"; - public GtasksInvoker(GtasksTokenValidator gtasksTokenValidator, String authToken) { + public GtasksInvoker(Context context, GtasksTokenValidator gtasksTokenValidator, String authToken) { + this.context = context; this.gtasksTokenValidator = gtasksTokenValidator; this.token = authToken; - Context context = ContextManager.getContext(); key = context.getString(R.string.gapi_key); credential.setAccessToken(authToken); HttpRequestInitializer httpRequestInitializer = new HttpRequestInitializer() { @@ -67,7 +67,7 @@ public class GtasksInvoker { HttpResponseException h = (HttpResponseException) e; int statusCode = h.getStatusCode(); if (statusCode == 401 || statusCode == 403) { - token = gtasksTokenValidator.validateAuthToken(ContextManager.getContext(), token); + token = gtasksTokenValidator.validateAuthToken(context, token); if (token != null) { credential.setAccessToken(token); } diff --git a/src/main/java/com/todoroo/astrid/gtasks/auth/GtasksLoginActivity.java b/src/main/java/com/todoroo/astrid/gtasks/auth/GtasksLoginActivity.java index ad9b2d0d3..48da4549d 100644 --- a/src/main/java/com/todoroo/astrid/gtasks/auth/GtasksLoginActivity.java +++ b/src/main/java/com/todoroo/astrid/gtasks/auth/GtasksLoginActivity.java @@ -21,7 +21,6 @@ import android.widget.TextView; import android.widget.Toast; import com.google.api.client.googleapis.extensions.android.accounts.GoogleAccountManager; -import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.utility.DialogUtilities; import com.todoroo.astrid.gtasks.GtasksPreferenceService; import com.todoroo.astrid.gtasks.api.GtasksInvoker; @@ -59,7 +58,6 @@ public class GtasksLoginActivity extends InjectingListActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - ContextManager.setContext(this); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.gtasks_login_activity); diff --git a/src/main/java/com/todoroo/astrid/gtasks/auth/GtasksTokenValidator.java b/src/main/java/com/todoroo/astrid/gtasks/auth/GtasksTokenValidator.java index 28d93b9dc..e9de1bb7a 100644 --- a/src/main/java/com/todoroo/astrid/gtasks/auth/GtasksTokenValidator.java +++ b/src/main/java/com/todoroo/astrid/gtasks/auth/GtasksTokenValidator.java @@ -14,12 +14,12 @@ import android.content.Intent; import android.os.Bundle; import com.google.api.client.googleapis.extensions.android.accounts.GoogleAccountManager; -import com.todoroo.andlib.service.ContextManager; import com.todoroo.astrid.gtasks.GtasksPreferenceService; import com.todoroo.astrid.gtasks.api.GoogleTasksException; import com.todoroo.astrid.gtasks.api.GtasksInvoker; import org.tasks.R; +import org.tasks.injection.ForApplication; import java.io.IOException; @@ -30,12 +30,14 @@ import javax.inject.Singleton; public class GtasksTokenValidator { private static final String TOKEN_INTENT_RECEIVED = "intent!"; //$NON-NLS-1$ - private static final int REVALIDATION_TRIES = 4; + + private final Context context; private final GtasksPreferenceService preferences; @Inject - public GtasksTokenValidator(GtasksPreferenceService preferences) { + public GtasksTokenValidator(@ForApplication Context context, GtasksPreferenceService preferences) { + this.context = context; this.preferences = preferences; } @@ -45,7 +47,7 @@ public class GtasksTokenValidator { * @return valid token on success, null on failure */ public synchronized String validateAuthToken(Context c, String token) throws GoogleTasksException { - GoogleAccountManager accountManager = new GoogleAccountManager(ContextManager.getContext()); + GoogleAccountManager accountManager = new GoogleAccountManager(context); if(testToken(token)) { return token; @@ -76,7 +78,7 @@ public class GtasksTokenValidator { } private boolean testToken(String token) { - GtasksInvoker testService = new GtasksInvoker(this, token); + GtasksInvoker testService = new GtasksInvoker(context, this, token); try { testService.ping(); return true; diff --git a/src/main/java/com/todoroo/astrid/gtasks/sync/GtasksSyncService.java b/src/main/java/com/todoroo/astrid/gtasks/sync/GtasksSyncService.java index d666c5024..d9c154882 100644 --- a/src/main/java/com/todoroo/astrid/gtasks/sync/GtasksSyncService.java +++ b/src/main/java/com/todoroo/astrid/gtasks/sync/GtasksSyncService.java @@ -6,6 +6,7 @@ package com.todoroo.astrid.gtasks.sync; import android.content.ContentValues; +import android.content.Context; import android.text.TextUtils; import com.todoroo.andlib.data.DatabaseDao.ModelUpdateListener; @@ -29,6 +30,7 @@ import com.todoroo.astrid.service.TaskService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.tasks.injection.ForApplication; import java.io.IOException; import java.util.concurrent.LinkedBlockingQueue; @@ -44,6 +46,7 @@ public class GtasksSyncService { private static final String DEFAULT_LIST = "@default"; //$NON-NLS-1$ + private Context context; private final MetadataDao metadataDao; private final GtasksMetadataService gtasksMetadataService; private final TaskDao taskDao; @@ -53,9 +56,10 @@ public class GtasksSyncService { private final LinkedBlockingQueue operationQueue = new LinkedBlockingQueue<>(); @Inject - public GtasksSyncService(MetadataDao metadataDao, GtasksMetadataService gtasksMetadataService, + public GtasksSyncService(@ForApplication Context context, MetadataDao metadataDao, GtasksMetadataService gtasksMetadataService, TaskDao taskDao, GtasksPreferenceService gtasksPreferenceService, GtasksTokenValidator gtasksTokenValidator, GtasksMetadata gtasksMetadataFactory) { + this.context = context; this.metadataDao = metadataDao; this.gtasksMetadataService = gtasksMetadataService; this.taskDao = taskDao; @@ -155,7 +159,7 @@ public class GtasksSyncService { continue; } try { - GtasksInvoker invoker = new GtasksInvoker(gtasksTokenValidator, gtasksPreferenceService.getToken()); + GtasksInvoker invoker = new GtasksInvoker(context, gtasksTokenValidator, gtasksPreferenceService.getToken()); op.op(invoker); } catch (IOException e) { log.error(e.getMessage(), e); diff --git a/src/main/java/com/todoroo/astrid/gtasks/sync/GtasksSyncV2Provider.java b/src/main/java/com/todoroo/astrid/gtasks/sync/GtasksSyncV2Provider.java index 0881b09f3..9f47ab54f 100644 --- a/src/main/java/com/todoroo/astrid/gtasks/sync/GtasksSyncV2Provider.java +++ b/src/main/java/com/todoroo/astrid/gtasks/sync/GtasksSyncV2Provider.java @@ -134,7 +134,7 @@ public class GtasksSyncV2Provider { try { String authToken = getValidatedAuthToken(); - final GtasksInvoker invoker = new GtasksInvoker(gtasksTokenValidator, authToken); + final GtasksInvoker invoker = new GtasksInvoker(context, gtasksTokenValidator, authToken); TaskLists remoteLists = null; try { remoteLists = invoker.allGtaskLists(); @@ -208,7 +208,7 @@ public class GtasksSyncV2Provider { try { String authToken = getValidatedAuthToken(); gtasksSyncService.waitUntilEmpty(); - final GtasksInvoker service = new GtasksInvoker(gtasksTokenValidator, authToken); + final GtasksInvoker service = new GtasksInvoker(context, gtasksTokenValidator, authToken); synchronizeListHelper(gtasksList, service, null); } finally { callback.finished(); diff --git a/src/main/java/com/todoroo/astrid/reminders/Notifications.java b/src/main/java/com/todoroo/astrid/reminders/Notifications.java index ed23d0f39..6a2138343 100644 --- a/src/main/java/com/todoroo/astrid/reminders/Notifications.java +++ b/src/main/java/com/todoroo/astrid/reminders/Notifications.java @@ -12,7 +12,6 @@ import android.content.res.Resources; import android.os.Bundle; import android.text.TextUtils; -import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.sql.QueryTemplate; import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.astrid.activity.TaskListActivity; @@ -67,8 +66,6 @@ public class Notifications extends InjectingBroadcastReceiver { public void onReceive(Context context, Intent intent) { super.onReceive(context, intent); - ContextManager.setContext(context); - handle(intent); } diff --git a/src/main/java/com/todoroo/astrid/repeats/RepeatTaskCompleteListener.java b/src/main/java/com/todoroo/astrid/repeats/RepeatTaskCompleteListener.java index 608c38964..919ac5676 100644 --- a/src/main/java/com/todoroo/astrid/repeats/RepeatTaskCompleteListener.java +++ b/src/main/java/com/todoroo/astrid/repeats/RepeatTaskCompleteListener.java @@ -17,7 +17,6 @@ import com.google.ical.values.DateValueImpl; import com.google.ical.values.Frequency; import com.google.ical.values.RRule; import com.google.ical.values.WeekdayNum; -import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.data.Task; @@ -53,7 +52,6 @@ public class RepeatTaskCompleteListener extends InjectingBroadcastReceiver { public void onReceive(Context context, Intent intent) { super.onReceive(context, intent); - ContextManager.setContext(context); long taskId = intent.getLongExtra(AstridApiConstants.EXTRAS_TASK_ID, -1); if(taskId == -1) { return; @@ -92,7 +90,7 @@ public class RepeatTaskCompleteListener extends InjectingBroadcastReceiver { return; } - rescheduleTask(gcalHelper, taskService, task, newDueDate); + rescheduleTask(context, gcalHelper, taskService, task, newDueDate); // send a broadcast Intent broadcastIntent = new Intent(AstridApiConstants.BROADCAST_EVENT_TASK_REPEATED); @@ -104,7 +102,7 @@ public class RepeatTaskCompleteListener extends InjectingBroadcastReceiver { } } - public static void rescheduleTask(GCalHelper gcalHelper, TaskService taskService, Task task, long newDueDate) { + public static void rescheduleTask(Context context, GCalHelper gcalHelper, TaskService taskService, Task task, long newDueDate) { long hideUntil = task.getHideUntil(); if(hideUntil > 0 && task.getDueDate() > 0) { hideUntil += newDueDate - task.getDueDate(); @@ -115,7 +113,7 @@ public class RepeatTaskCompleteListener extends InjectingBroadcastReceiver { task.setHideUntil(hideUntil); task.putTransitory(TaskService.TRANS_REPEAT_COMPLETE, true); - ContentResolver cr = ContextManager.getContext().getContentResolver(); + ContentResolver cr = context.getContentResolver(); gcalHelper.rescheduleRepeatingTask(task, cr); taskService.save(task); } diff --git a/src/main/java/com/todoroo/astrid/service/StartupService.java b/src/main/java/com/todoroo/astrid/service/StartupService.java index 30bb900e7..f03d43fca 100644 --- a/src/main/java/com/todoroo/astrid/service/StartupService.java +++ b/src/main/java/com/todoroo/astrid/service/StartupService.java @@ -15,7 +15,6 @@ import android.media.AudioManager; import android.widget.Toast; import com.todoroo.andlib.data.DatabaseDao.ModelUpdateListener; -import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.sql.Criterion; import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.andlib.utility.DialogUtilities; @@ -103,9 +102,6 @@ public class StartupService { return; } - // sets up activity manager - ContextManager.setContext(activity); - database.addListener(new DatabaseUpdateListener() { @Override public void onDatabaseUpdated() { diff --git a/src/main/java/com/todoroo/astrid/subtasks/AstridOrderedListFragmentHelper.java b/src/main/java/com/todoroo/astrid/subtasks/AstridOrderedListFragmentHelper.java index c7c911609..53cfc75bc 100644 --- a/src/main/java/com/todoroo/astrid/subtasks/AstridOrderedListFragmentHelper.java +++ b/src/main/java/com/todoroo/astrid/subtasks/AstridOrderedListFragmentHelper.java @@ -1,6 +1,7 @@ package com.todoroo.astrid.subtasks; import android.app.Activity; +import android.content.Context; import android.database.Cursor; import android.text.TextUtils; import android.util.DisplayMetrics; @@ -168,10 +169,10 @@ public class AstridOrderedListFragmentHelper implements OrderedListFragmen }; @Override - public TaskAdapter createTaskAdapter(TodorooCursor cursor, + public TaskAdapter createTaskAdapter(Context context, TodorooCursor cursor, AtomicReference sqlQueryTemplate) { - taskAdapter = new DraggableTaskAdapter(preferences, fragment, cursor, sqlQueryTemplate); + taskAdapter = new DraggableTaskAdapter(context, preferences, fragment, cursor, sqlQueryTemplate); getTouchListView().setItemHightNormal(taskAdapter.computeFullRowHeight()); @@ -187,9 +188,9 @@ public class AstridOrderedListFragmentHelper implements OrderedListFragmen private final class DraggableTaskAdapter extends TaskAdapter { - private DraggableTaskAdapter(ActivityPreferences preferences, TaskListFragment activity, + private DraggableTaskAdapter(Context context, ActivityPreferences preferences, TaskListFragment activity, Cursor c, AtomicReference query) { - super(preferences, taskAttachmentDao, taskService, activity, c, query, null); + super(context, preferences, taskAttachmentDao, taskService, activity, c, query, null); } @Override diff --git a/src/main/java/com/todoroo/astrid/subtasks/OrderedListFragmentHelperInterface.java b/src/main/java/com/todoroo/astrid/subtasks/OrderedListFragmentHelperInterface.java index d430b85ec..f05a03202 100644 --- a/src/main/java/com/todoroo/astrid/subtasks/OrderedListFragmentHelperInterface.java +++ b/src/main/java/com/todoroo/astrid/subtasks/OrderedListFragmentHelperInterface.java @@ -1,5 +1,7 @@ package com.todoroo.astrid.subtasks; +import android.content.Context; + import com.todoroo.andlib.data.Property; import com.todoroo.andlib.data.TodorooCursor; import com.todoroo.astrid.adapter.TaskAdapter; @@ -14,7 +16,7 @@ public interface OrderedListFragmentHelperInterface { void beforeSetUpTaskList(Filter filter); void onCreateTask(Task task); void onDeleteTask(Task task); - TaskAdapter createTaskAdapter(TodorooCursor cursor, AtomicReference queryTemplate); + TaskAdapter createTaskAdapter(Context context, TodorooCursor cursor, AtomicReference queryTemplate); Property[] taskProperties(); } diff --git a/src/main/java/com/todoroo/astrid/subtasks/SubtasksHelper.java b/src/main/java/com/todoroo/astrid/subtasks/SubtasksHelper.java index 83cb8f85f..2e58f89b1 100644 --- a/src/main/java/com/todoroo/astrid/subtasks/SubtasksHelper.java +++ b/src/main/java/com/todoroo/astrid/subtasks/SubtasksHelper.java @@ -1,14 +1,13 @@ package com.todoroo.astrid.subtasks; +import android.content.Context; import android.text.TextUtils; import com.todoroo.andlib.data.Property; import com.todoroo.andlib.data.TodorooCursor; import com.todoroo.andlib.sql.Criterion; import com.todoroo.andlib.sql.Query; -import com.todoroo.astrid.actfm.TagViewFragment; import com.todoroo.astrid.api.Filter; -import com.todoroo.astrid.api.FilterWithCustomIntent; import com.todoroo.astrid.core.BuiltInFilterExposer; import com.todoroo.astrid.core.SortHelper; import com.todoroo.astrid.dao.TagDataDao; @@ -23,18 +22,36 @@ import com.todoroo.astrid.subtasks.AstridOrderedListUpdater.Node; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.tasks.injection.ForApplication; import org.tasks.preferences.Preferences; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import javax.inject.Inject; + public class SubtasksHelper { private static final Logger log = LoggerFactory.getLogger(SubtasksHelper.class); - public static boolean shouldUseSubtasksFragmentForFilter(Preferences preferences, Filter filter) { - if(filter == null || BuiltInFilterExposer.isInbox(filter) || BuiltInFilterExposer.isTodayFilter(filter) || SubtasksHelper.isTagFilter(filter)) { + private final Context context; + private final Preferences preferences; + private final TaskService taskService; + private final TagDataDao tagDataDao; + private final TaskListMetadataDao taskListMetadataDao; + + @Inject + public SubtasksHelper(@ForApplication Context context, Preferences preferences, TaskService taskService, TagDataDao tagDataDao, TaskListMetadataDao taskListMetadataDao) { + this.context = context; + this.preferences = preferences; + this.taskService = taskService; + this.tagDataDao = tagDataDao; + this.taskListMetadataDao = taskListMetadataDao; + } + + public boolean shouldUseSubtasksFragmentForFilter(Filter filter) { + if(filter == null || BuiltInFilterExposer.isInbox(context, filter) || BuiltInFilterExposer.isTodayFilter(context, filter) || filter.isTagFilter()) { int sortFlags = preferences.getSortFlags(); if(SortHelper.isManualSort(sortFlags)) { return true; @@ -44,41 +61,29 @@ public class SubtasksHelper { } public static Class subtasksClassForFilter(Filter filter) { - if (SubtasksHelper.isTagFilter(filter)) { + if (filter.isTagFilter()) { return SubtasksTagListFragment.class; } return SubtasksListFragment.class; } - public static boolean isTagFilter(Filter filter) { - if (filter instanceof FilterWithCustomIntent) { - String className = ((FilterWithCustomIntent) filter).customTaskList.getClassName(); - if (TagViewFragment.class.getName().equals(className) - || SubtasksTagListFragment.class.getName().equals(className)) // Need to check this subclass because some shortcuts/widgets may have been saved with it - { - return true; - } - } - return false; - } - - public static String applySubtasksToWidgetFilter(Preferences preferences, TaskService taskService, TagDataDao tagDataDao, TaskListMetadataDao tlmd, Filter filter, String query, String tagName, int limit) { - if (SubtasksHelper.shouldUseSubtasksFragmentForFilter(preferences, filter)) { + public String applySubtasksToWidgetFilter(Filter filter, String query, String tagName, int limit) { + if (shouldUseSubtasksFragmentForFilter(filter)) { // care for manual ordering TagData tagData = tagDataDao.getTagByName(tagName, TagData.UUID, TagData.TAG_ORDERING); TaskListMetadata tlm = null; if (tagData != null) { - tlm = tlmd.fetchByTagId(tagData.getUuid(), TaskListMetadata.TASK_IDS); - } else if (BuiltInFilterExposer.isInbox(filter)) { - tlm = tlmd.fetchByTagId(TaskListMetadata.FILTER_ID_ALL, TaskListMetadata.TASK_IDS); - } else if (BuiltInFilterExposer.isTodayFilter(filter)) { - tlm = tlmd.fetchByTagId(TaskListMetadata.FILTER_ID_TODAY, TaskListMetadata.TASK_IDS); + tlm = taskListMetadataDao.fetchByTagId(tagData.getUuid(), TaskListMetadata.TASK_IDS); + } else if (BuiltInFilterExposer.isInbox(context, filter)) { + tlm = taskListMetadataDao.fetchByTagId(TaskListMetadata.FILTER_ID_ALL, TaskListMetadata.TASK_IDS); + } else if (BuiltInFilterExposer.isTodayFilter(context, filter)) { + tlm = taskListMetadataDao.fetchByTagId(TaskListMetadata.FILTER_ID_TODAY, TaskListMetadata.TASK_IDS); } query = query.replaceAll("ORDER BY .*", ""); query = query + String.format(" ORDER BY %s, %s, %s, %s", Task.DELETION_DATE, Task.COMPLETION_DATE, - getOrderString(taskService, tagData, tlm), Task.CREATION_DATE); + getOrderString(tagData, tlm), Task.CREATION_DATE); if (limit > 0) { query = query + " LIMIT " + limit; } @@ -90,7 +95,7 @@ public class SubtasksHelper { return query; } - private static String getOrderString(TaskService taskService, TagData tagData, TaskListMetadata tlm) { + private String getOrderString(TagData tagData, TaskListMetadata tlm) { String serialized; if (tlm != null) { serialized = tlm.getTaskIDs(); diff --git a/src/main/java/com/todoroo/astrid/subtasks/SubtasksListFragment.java b/src/main/java/com/todoroo/astrid/subtasks/SubtasksListFragment.java index 30318f54b..c3c467c42 100644 --- a/src/main/java/com/todoroo/astrid/subtasks/SubtasksListFragment.java +++ b/src/main/java/com/todoroo/astrid/subtasks/SubtasksListFragment.java @@ -6,6 +6,7 @@ package com.todoroo.astrid.subtasks; import android.app.Activity; +import android.content.Context; import android.view.View; import android.view.ViewGroup; @@ -18,6 +19,7 @@ import com.todoroo.astrid.data.TaskListMetadata; import com.todoroo.astrid.service.TaskService; import org.tasks.R; +import org.tasks.injection.ForApplication; import org.tasks.preferences.ActivityPreferences; import javax.inject.Inject; @@ -38,6 +40,7 @@ public class SubtasksListFragment extends TaskListFragment { @Inject SubtasksFilterUpdater subtasksFilterUpdater; @Inject TaskAttachmentDao taskAttachmentDao; @Inject ActivityPreferences preferences; + @Inject @ForApplication Context context; @Override public void onAttach(Activity activity) { @@ -107,7 +110,7 @@ public class SubtasksListFragment extends TaskListFragment { @Override protected TaskAdapter createTaskAdapter(TodorooCursor cursor) { - return helper.createTaskAdapter(cursor, sqlQueryTemplate); + return helper.createTaskAdapter(context, cursor, sqlQueryTemplate); } @Override diff --git a/src/main/java/com/todoroo/astrid/subtasks/SubtasksTagListFragment.java b/src/main/java/com/todoroo/astrid/subtasks/SubtasksTagListFragment.java index 01ee8b0ea..dfec6ffc2 100644 --- a/src/main/java/com/todoroo/astrid/subtasks/SubtasksTagListFragment.java +++ b/src/main/java/com/todoroo/astrid/subtasks/SubtasksTagListFragment.java @@ -6,6 +6,7 @@ package com.todoroo.astrid.subtasks; import android.app.Activity; +import android.content.Context; import android.view.View; import android.view.ViewGroup; @@ -18,6 +19,7 @@ import com.todoroo.astrid.data.TaskListMetadata; import com.todoroo.astrid.service.TaskService; import org.tasks.R; +import org.tasks.injection.ForApplication; import org.tasks.preferences.ActivityPreferences; import javax.inject.Inject; @@ -28,6 +30,7 @@ public class SubtasksTagListFragment extends TagViewFragment { @Inject SubtasksFilterUpdater subtasksFilterUpdater; @Inject TaskAttachmentDao taskAttachmentDao; @Inject ActivityPreferences preferences; + @Inject @ForApplication Context context; private AstridOrderedListFragmentHelper helper; @@ -100,7 +103,7 @@ public class SubtasksTagListFragment extends TagViewFragment { @Override protected TaskAdapter createTaskAdapter(TodorooCursor cursor) { - return helper.createTaskAdapter(cursor, sqlQueryTemplate); + return helper.createTaskAdapter(context, cursor, sqlQueryTemplate); } @Override diff --git a/src/main/java/com/todoroo/astrid/tags/TagFilterExposer.java b/src/main/java/com/todoroo/astrid/tags/TagFilterExposer.java index e601fc6c0..f9bb54f1c 100644 --- a/src/main/java/com/todoroo/astrid/tags/TagFilterExposer.java +++ b/src/main/java/com/todoroo/astrid/tags/TagFilterExposer.java @@ -13,7 +13,6 @@ import android.content.Intent; import android.os.Bundle; import android.text.TextUtils; -import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.sql.Criterion; import com.todoroo.andlib.sql.Field; import com.todoroo.andlib.sql.Join; @@ -56,8 +55,6 @@ public class TagFilterExposer { } public List getFilters() { - ContextManager.setContext(context); - ArrayList list = new ArrayList<>(); list.addAll(filterFromTags(tagService.getTagList())); diff --git a/src/main/java/com/todoroo/astrid/timers/TimerPlugin.java b/src/main/java/com/todoroo/astrid/timers/TimerPlugin.java index c2e277633..329f9eb66 100644 --- a/src/main/java/com/todoroo/astrid/timers/TimerPlugin.java +++ b/src/main/java/com/todoroo/astrid/timers/TimerPlugin.java @@ -63,7 +63,7 @@ public class TimerPlugin { notificationManager.cancel(Constants.NOTIFICATION_TIMER); } else { Filter filter = TimerFilterExposer.createFilter(context); - Intent notifyIntent = ShortcutActivity.createIntent(filter); + Intent notifyIntent = ShortcutActivity.createIntent(context, filter); notifyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(context, Constants.NOTIFICATION_TIMER, notifyIntent, 0); diff --git a/src/main/java/com/todoroo/astrid/timers/TimerTaskCompleteListener.java b/src/main/java/com/todoroo/astrid/timers/TimerTaskCompleteListener.java index 5c38dea00..6e1fbc0df 100644 --- a/src/main/java/com/todoroo/astrid/timers/TimerTaskCompleteListener.java +++ b/src/main/java/com/todoroo/astrid/timers/TimerTaskCompleteListener.java @@ -8,7 +8,6 @@ package com.todoroo.astrid.timers; import android.content.Context; import android.content.Intent; -import com.todoroo.andlib.service.ContextManager; import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.data.Task; import com.todoroo.astrid.service.TaskService; @@ -27,7 +26,6 @@ public class TimerTaskCompleteListener extends InjectingBroadcastReceiver { public void onReceive(Context context, Intent intent) { super.onReceive(context, intent); - ContextManager.setContext(context); long taskId = intent.getLongExtra(AstridApiConstants.EXTRAS_TASK_ID, -1); if(taskId == -1) { return; diff --git a/src/main/java/com/todoroo/astrid/ui/AstridTimePicker.java b/src/main/java/com/todoroo/astrid/ui/AstridTimePicker.java index 48e38fa6f..db1ae658b 100644 --- a/src/main/java/com/todoroo/astrid/ui/AstridTimePicker.java +++ b/src/main/java/com/todoroo/astrid/ui/AstridTimePicker.java @@ -52,7 +52,7 @@ public class AstridTimePicker extends LinearLayout { hours = (NumberPicker) findViewById(R.id.hours); minutes = (NumberPicker) findViewById(R.id.minutes); - if (Preferences.getBoolean(R.string.p_time_increment, false)) { + if (Preferences.getBoolean(context, R.string.p_time_increment, false)) { minutes.setIncrementBy(5); } else { minutes.setIncrementBy(1); diff --git a/src/main/java/com/todoroo/astrid/ui/DateChangedAlerts.java b/src/main/java/com/todoroo/astrid/ui/DateChangedAlerts.java index 3b636ca6c..1573b2a06 100644 --- a/src/main/java/com/todoroo/astrid/ui/DateChangedAlerts.java +++ b/src/main/java/com/todoroo/astrid/ui/DateChangedAlerts.java @@ -37,6 +37,7 @@ import com.todoroo.astrid.utility.Flags; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.tasks.R; +import org.tasks.injection.ForApplication; import org.tasks.preferences.ActivityPreferences; import java.text.ParseException; @@ -64,10 +65,12 @@ public class DateChangedAlerts { /** Start showing the option to hide future notifs after this many confirmation dialogs */ private static final int HIDE_CHECKBOX_AFTER_SHOWS = 3; + private final Context context; private final ActivityPreferences preferences; @Inject - public DateChangedAlerts(ActivityPreferences preferences) { + public DateChangedAlerts(@ForApplication Context context, ActivityPreferences preferences) { + this.context = context; this.preferences = preferences; } @@ -161,7 +164,7 @@ public class DateChangedAlerts { public void onDateAndTimeSelected(long date) { d.dismiss(); task.setRepeatUntil(date); - RepeatTaskCompleteListener.rescheduleTask(gcalHelper, taskService, task, newDueDate); + RepeatTaskCompleteListener.rescheduleTask(context, gcalHelper, taskService, task, newDueDate); Flags.set(Flags.REFRESH); } diff --git a/src/main/java/com/todoroo/astrid/utility/TodorooPreferenceActivity.java b/src/main/java/com/todoroo/astrid/utility/TodorooPreferenceActivity.java index 156a4f894..f72df5b06 100644 --- a/src/main/java/com/todoroo/astrid/utility/TodorooPreferenceActivity.java +++ b/src/main/java/com/todoroo/astrid/utility/TodorooPreferenceActivity.java @@ -22,8 +22,6 @@ import android.preference.PreferenceGroup; import android.preference.PreferenceManager; import android.preference.RingtonePreference; -import com.todoroo.andlib.service.ContextManager; - import org.tasks.injection.InjectingPreferenceActivity; import org.tasks.preferences.Preferences; import org.tasks.ui.TimePreference; @@ -57,7 +55,6 @@ abstract public class TodorooPreferenceActivity extends InjectingPreferenceActiv public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - ContextManager.setContext(this); addPreferencesFromResource(getPreferenceResource()); } diff --git a/src/main/java/com/todoroo/astrid/voice/VoiceInputAssistant.java b/src/main/java/com/todoroo/astrid/voice/VoiceInputAssistant.java index bf8e182c8..5408910f0 100644 --- a/src/main/java/com/todoroo/astrid/voice/VoiceInputAssistant.java +++ b/src/main/java/com/todoroo/astrid/voice/VoiceInputAssistant.java @@ -13,7 +13,6 @@ import android.content.pm.ResolveInfo; import android.speech.RecognizerIntent; import com.todoroo.andlib.data.Callback; -import com.todoroo.andlib.service.ContextManager; import java.util.ArrayList; import java.util.List; @@ -81,7 +80,7 @@ public class VoiceInputAssistant { Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1); - intent.putExtra(RecognizerIntent.EXTRA_PROMPT, ContextManager.getContext().getString(prompt)); + intent.putExtra(RecognizerIntent.EXTRA_PROMPT, activity.getString(prompt)); activity.startActivityForResult(intent, requestCode); } diff --git a/src/main/java/com/todoroo/astrid/widget/TasksWidget.java b/src/main/java/com/todoroo/astrid/widget/TasksWidget.java index 60bd1e1ef..3fd29b208 100644 --- a/src/main/java/com/todoroo/astrid/widget/TasksWidget.java +++ b/src/main/java/com/todoroo/astrid/widget/TasksWidget.java @@ -12,7 +12,6 @@ import android.content.Context; import android.content.Intent; import android.os.Build; -import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.astrid.activity.TaskEditActivity; import com.todoroo.astrid.activity.TaskEditFragment; @@ -74,7 +73,6 @@ public class TasksWidget extends InjectingAppWidgetProvider { @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { try { - ContextManager.setContext(context); super.onUpdate(context, appWidgetManager, appWidgetIds); if (preIceCreamSandwich()) { diff --git a/src/main/java/com/todoroo/astrid/widget/WidgetUpdateService.java b/src/main/java/com/todoroo/astrid/widget/WidgetUpdateService.java index 2c88abcce..4172912f2 100644 --- a/src/main/java/com/todoroo/astrid/widget/WidgetUpdateService.java +++ b/src/main/java/com/todoroo/astrid/widget/WidgetUpdateService.java @@ -11,14 +11,11 @@ import android.view.View; import android.widget.RemoteViews; import com.todoroo.andlib.data.TodorooCursor; -import com.todoroo.andlib.service.ContextManager; import com.todoroo.astrid.actfm.TagViewFragment; import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.api.FilterWithCustomIntent; import com.todoroo.astrid.core.SortHelper; import com.todoroo.astrid.dao.Database; -import com.todoroo.astrid.dao.TagDataDao; -import com.todoroo.astrid.dao.TaskListMetadataDao; import com.todoroo.astrid.data.Task; import com.todoroo.astrid.service.TaskService; import com.todoroo.astrid.subtasks.SubtasksHelper; @@ -43,14 +40,12 @@ public class WidgetUpdateService extends InjectingService { @Inject Database database; @Inject TaskService taskService; - @Inject TaskListMetadataDao taskListMetadataDao; - @Inject TagDataDao tagDataDao; @Inject WidgetHelper widgetHelper; @Inject Preferences preferences; + @Inject SubtasksHelper subtasksHelper; @Override public void onStart(final Intent intent, int startId) { - ContextManager.setContext(this); new Thread(new Runnable() { @Override public void run() { @@ -102,7 +97,7 @@ public class WidgetUpdateService extends InjectingService { Filter filter = null; try { filter = widgetHelper.getFilter(context, widgetId); - if (SubtasksHelper.isTagFilter(filter)) { + if (filter.isTagFilter()) { ((FilterWithCustomIntent) filter).customTaskList = new ComponentName(context, TagViewFragment.class); // In case legacy widget was created with subtasks fragment } views.setTextViewText(R.id.widget_title, filter.title); @@ -114,7 +109,7 @@ public class WidgetUpdateService extends InjectingService { filter.getSqlQuery(), flags, sort).replaceAll("LIMIT \\d+", "") + " LIMIT " + numberOfTasks; String tagName = preferences.getStringValue(WidgetConfigActivity.PREF_TITLE + widgetId); - query = SubtasksHelper.applySubtasksToWidgetFilter(preferences, taskService, tagDataDao, taskListMetadataDao, filter, query, tagName, numberOfTasks); + query = subtasksHelper.applySubtasksToWidgetFilter(filter, query, tagName, numberOfTasks); database.openForReading(); cursor = taskService.fetchFiltered(query, null, Task.ID, Task.TITLE, Task.DUE_DATE, Task.COMPLETION_DATE); diff --git a/src/main/java/org/tasks/Tasks.java b/src/main/java/org/tasks/Tasks.java index e678fe5e9..e64f133d5 100644 --- a/src/main/java/org/tasks/Tasks.java +++ b/src/main/java/org/tasks/Tasks.java @@ -1,6 +1,5 @@ package org.tasks; -import com.todoroo.andlib.service.ContextManager; import com.todoroo.astrid.dao.Database; import com.todoroo.astrid.dao.MetadataDao; import com.todoroo.astrid.dao.StoreObjectDao; @@ -58,7 +57,5 @@ public class Tasks extends InjectingApplication { super.onCreate(); preferences.setupLogger(); - - ContextManager.setContext(this); } } diff --git a/src/main/java/org/tasks/ui/NavigationDrawerFragment.java b/src/main/java/org/tasks/ui/NavigationDrawerFragment.java index 4fb399322..d80a29f84 100644 --- a/src/main/java/org/tasks/ui/NavigationDrawerFragment.java +++ b/src/main/java/org/tasks/ui/NavigationDrawerFragment.java @@ -45,6 +45,7 @@ import org.slf4j.LoggerFactory; import org.tasks.R; import org.tasks.filters.FilterCounter; import org.tasks.filters.FilterProvider; +import org.tasks.injection.ForApplication; import org.tasks.injection.InjectingFragment; import org.tasks.preferences.Preferences; @@ -88,6 +89,7 @@ public class NavigationDrawerFragment extends InjectingFragment { @Inject FilterCounter filterCounter; @Inject Preferences preferences; @Inject FilterProvider filterProvider; + @Inject @ForApplication Context context; public NavigationDrawerFragment() { } @@ -149,7 +151,7 @@ public class NavigationDrawerFragment extends InjectingFragment { return layout; } - protected void setUpList() { + private void setUpList() { adapter.setListView(mDrawerListView); mDrawerListView.setAdapter(adapter); registerForContextMenu(mDrawerListView); @@ -403,7 +405,7 @@ public class NavigationDrawerFragment extends InjectingFragment { Filter item = adapter.getItem(info.position); MenuItem menuItem = menu.add(0, CONTEXT_MENU_SHORTCUT, 0, R.string.FLA_context_shortcut); - menuItem.setIntent(ShortcutActivity.createIntent(item)); + menuItem.setIntent(ShortcutActivity.createIntent(context, item)); for(int i = 0; i < item.contextMenuLabels.length; i++) { if(item.contextMenuIntents.length <= i) { diff --git a/src/main/java/org/tasks/widget/ScrollableViewsFactory.java b/src/main/java/org/tasks/widget/ScrollableViewsFactory.java index b585d6701..39c0a963c 100644 --- a/src/main/java/org/tasks/widget/ScrollableViewsFactory.java +++ b/src/main/java/org/tasks/widget/ScrollableViewsFactory.java @@ -20,8 +20,6 @@ import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.api.FilterWithCustomIntent; import com.todoroo.astrid.core.SortHelper; import com.todoroo.astrid.dao.Database; -import com.todoroo.astrid.dao.TagDataDao; -import com.todoroo.astrid.dao.TaskListMetadataDao; import com.todoroo.astrid.data.Task; import com.todoroo.astrid.service.TaskService; import com.todoroo.astrid.subtasks.SubtasksHelper; @@ -41,8 +39,7 @@ public class ScrollableViewsFactory implements RemoteViewsService.RemoteViewsFac private final Database database; private final TaskService taskService; - private final TaskListMetadataDao taskListMetadataDao; - private final TagDataDao tagDataDao; + private SubtasksHelper subtasksHelper; private final Preferences preferences; private final Context context; private final Filter filter; @@ -52,15 +49,15 @@ public class ScrollableViewsFactory implements RemoteViewsService.RemoteViewsFac private TodorooCursor cursor; public ScrollableViewsFactory( + SubtasksHelper subtasksHelper, Preferences preferences, Context context, Filter filter, int widgetId, boolean dark, Database database, - TaskService taskService, - TaskListMetadataDao taskListMetadataDao, - TagDataDao tagDataDao) { + TaskService taskService) { + this.subtasksHelper = subtasksHelper; this.preferences = preferences; this.context = context; this.filter = filter; @@ -68,8 +65,6 @@ public class ScrollableViewsFactory implements RemoteViewsService.RemoteViewsFac this.dark = dark; this.database = database; this.taskService = taskService; - this.taskListMetadataDao = taskListMetadataDao; - this.tagDataDao = tagDataDao; } @Override @@ -190,7 +185,7 @@ public class ScrollableViewsFactory implements RemoteViewsService.RemoteViewsFac } private String getQuery(Context context) { - if (SubtasksHelper.isTagFilter(filter)) { + if (filter.isTagFilter()) { ((FilterWithCustomIntent) filter).customTaskList = new ComponentName(context, TagViewFragment.class); // In case legacy widget was created with subtasks fragment } @@ -205,6 +200,6 @@ public class ScrollableViewsFactory implements RemoteViewsService.RemoteViewsFac String tagName = preferences.getStringValue(WidgetConfigActivity.PREF_TITLE + widgetId); - return SubtasksHelper.applySubtasksToWidgetFilter(preferences, taskService, tagDataDao, taskListMetadataDao, filter, query, tagName, 0); + return subtasksHelper.applySubtasksToWidgetFilter(filter, query, tagName, 0); } } diff --git a/src/main/java/org/tasks/widget/ScrollableWidgetUpdateService.java b/src/main/java/org/tasks/widget/ScrollableWidgetUpdateService.java index 030d58001..14131e788 100644 --- a/src/main/java/org/tasks/widget/ScrollableWidgetUpdateService.java +++ b/src/main/java/org/tasks/widget/ScrollableWidgetUpdateService.java @@ -6,9 +6,8 @@ import android.os.Bundle; import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.dao.Database; -import com.todoroo.astrid.dao.TagDataDao; -import com.todoroo.astrid.dao.TaskListMetadataDao; import com.todoroo.astrid.service.TaskService; +import com.todoroo.astrid.subtasks.SubtasksHelper; import org.tasks.injection.InjectingRemoteViewsService; import org.tasks.preferences.Preferences; @@ -22,9 +21,8 @@ public class ScrollableWidgetUpdateService extends InjectingRemoteViewsService { @Inject Database database; @Inject TaskService taskService; - @Inject TaskListMetadataDao taskListMetadataDao; - @Inject TagDataDao tagDataDao; @Inject Preferences preferences; + @Inject SubtasksHelper subtasksHelper; @Override public void onStart(Intent intent, int startId) { @@ -48,7 +46,7 @@ public class ScrollableWidgetUpdateService extends InjectingRemoteViewsService { Filter filter = (Filter) bundle.get(FILTER); int widgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID); boolean isDarkTheme = extras.getBoolean(IS_DARK_THEME); - return new ScrollableViewsFactory(preferences, this, filter, widgetId, isDarkTheme, - database, taskService, taskListMetadataDao, tagDataDao); + return new ScrollableViewsFactory(subtasksHelper, preferences, this, filter, widgetId, isDarkTheme, + database, taskService); } }