From d009c87cd93466cdf4f9ecbff4e660fcbc17bd56 Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Tue, 21 Feb 2012 15:34:38 -0800 Subject: [PATCH] Refactored task list fragments to not call getIntent() from their activity --- .../com/timsu/astrid/C2DMReceiver.java | 2 +- .../todoroo/astrid/actfm/TagViewFragment.java | 13 ++++-- .../astrid/gtasks/GtasksListFragment.java | 6 ++- .../reminders/NotificationFragment.java | 6 ++- .../astrid/reminders/Notifications.java | 3 +- .../activity/DraggableTaskListFragment.java | 4 ++ .../astrid/activity/ShortcutActivity.java | 4 +- .../astrid/activity/TaskListActivity.java | 36 ++++++++++++++- .../astrid/activity/TaskListFragment.java | 45 ++++--------------- .../adapter/TaskListFragmentPagerAdapter.java | 12 ++--- .../todoroo/astrid/widget/TasksWidget.java | 6 +-- 11 files changed, 80 insertions(+), 57 deletions(-) diff --git a/astrid/plugin-src/com/timsu/astrid/C2DMReceiver.java b/astrid/plugin-src/com/timsu/astrid/C2DMReceiver.java index 43e571ed9..09474f79e 100644 --- a/astrid/plugin-src/com/timsu/astrid/C2DMReceiver.java +++ b/astrid/plugin-src/com/timsu/astrid/C2DMReceiver.java @@ -233,7 +233,7 @@ public class C2DMReceiver extends BroadcastReceiver { } notifyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - notifyIntent.putExtra(TaskListFragment.TOKEN_SOURCE, Constants.SOURCE_C2DM); + notifyIntent.putExtra(TaskListActivity.TOKEN_SOURCE, Constants.SOURCE_C2DM); PendingIntent pendingIntent = PendingIntent.getActivity(context, notifId, notifyIntent, 0); diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewFragment.java b/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewFragment.java index 5da005c80..d7d294e1e 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewFragment.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewFragment.java @@ -95,6 +95,10 @@ public class TagViewFragment extends TaskListFragment { // --- UI initialization + public TagViewFragment(Bundle extras) { + super(extras); + } + @Override public void onActivityCreated(final Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); @@ -174,8 +178,8 @@ public class TagViewFragment extends TaskListFragment { } TaskListActivity activity = (TaskListActivity) getActivity(); - String tag = activity.getIntent().getStringExtra(EXTRA_TAG_NAME); - long remoteId = activity.getIntent().getLongExtra(EXTRA_TAG_REMOTE_ID, 0); + String tag = extras.getString(EXTRA_TAG_NAME); + long remoteId = extras.getLong(EXTRA_TAG_REMOTE_ID, 0); if(tag == null && remoteId == 0) return; @@ -200,8 +204,8 @@ public class TagViewFragment extends TaskListFragment { super.onNewIntent(intent); - if (activity.getIntent().getBooleanExtra(TOKEN_START_ACTIVITY, false)) { - activity.getIntent().removeExtra(TOKEN_START_ACTIVITY); + if (extras.getBoolean(TOKEN_START_ACTIVITY, false)) { + extras.remove(TOKEN_START_ACTIVITY); activity.showComments(); } } @@ -456,6 +460,7 @@ public class TagViewFragment extends TaskListFragment { tagData = tagDataService.fetchById(tagData.getId(), TagData.PROPERTIES); filter = TagFilterExposer.filterFromTagData(getActivity(), tagData); getActivity().getIntent().putExtra(TOKEN_FILTER, filter); + extras.putParcelable(TOKEN_FILTER, filter); Activity activity = getActivity(); if (activity instanceof TaskListActivity) { ((TaskListActivity) activity).setListsTitle(filter.title); diff --git a/astrid/plugin-src/com/todoroo/astrid/gtasks/GtasksListFragment.java b/astrid/plugin-src/com/todoroo/astrid/gtasks/GtasksListFragment.java index 65e4896c0..c23346951 100644 --- a/astrid/plugin-src/com/todoroo/astrid/gtasks/GtasksListFragment.java +++ b/astrid/plugin-src/com/todoroo/astrid/gtasks/GtasksListFragment.java @@ -64,6 +64,10 @@ public class GtasksListFragment extends DraggableTaskListFragment { GtasksList.LAST_SYNC }; + public GtasksListFragment(Bundle extras) { + super(extras); + } + @Override public void onActivityCreated(Bundle icicle) { super.onActivityCreated(icicle); @@ -86,7 +90,7 @@ public class GtasksListFragment extends DraggableTaskListFragment { } }); - long storeObjectId = getActivity().getIntent().getLongExtra(TOKEN_STORE_ID, 0); + long storeObjectId = extras.getLong(TOKEN_STORE_ID, 0); list = storeObjectDao.fetch(storeObjectId, LIST_PROPERTIES); } diff --git a/astrid/plugin-src/com/todoroo/astrid/reminders/NotificationFragment.java b/astrid/plugin-src/com/todoroo/astrid/reminders/NotificationFragment.java index ecab8b894..46af4dff5 100644 --- a/astrid/plugin-src/com/todoroo/astrid/reminders/NotificationFragment.java +++ b/astrid/plugin-src/com/todoroo/astrid/reminders/NotificationFragment.java @@ -71,6 +71,10 @@ public class NotificationFragment extends TaskListFragment implements OnTimeSetL private long taskId; + public NotificationFragment(Bundle extras) { + super(extras); + } + @Override public void onCreate(Bundle savedInstanceState) { StartupService.bypassInitialization(); @@ -120,7 +124,7 @@ public class NotificationFragment extends TaskListFragment implements OnTimeSetL // hide quick add getView().findViewById(R.id.taskListFooter).setVisibility(View.GONE); - String title = getActivity().getIntent().getStringExtra(Notifications.EXTRAS_TEXT); + String title = extras.getString(Notifications.EXTRAS_TEXT); new ReminderDialog((AstridActivity) getActivity(), taskId, title).show(); } diff --git a/astrid/plugin-src/com/todoroo/astrid/reminders/Notifications.java b/astrid/plugin-src/com/todoroo/astrid/reminders/Notifications.java index 8f605fb2a..64742888d 100644 --- a/astrid/plugin-src/com/todoroo/astrid/reminders/Notifications.java +++ b/astrid/plugin-src/com/todoroo/astrid/reminders/Notifications.java @@ -25,7 +25,6 @@ import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.Preferences; import com.todoroo.astrid.activity.TaskListActivity; -import com.todoroo.astrid.activity.TaskListFragment; import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.dao.TaskDao; import com.todoroo.astrid.data.Task; @@ -180,7 +179,7 @@ public class Notifications extends BroadcastReceiver { notifyIntent.putExtra(NotificationFragment.TOKEN_ID, id); notifyIntent.putExtra(EXTRAS_TEXT, text); notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK); - notifyIntent.putExtra(TaskListFragment.TOKEN_SOURCE, Constants.SOURCE_NOTIFICATION); + notifyIntent.putExtra(TaskListActivity.TOKEN_SOURCE, Constants.SOURCE_NOTIFICATION); requestNotification((int)id, notifyIntent, type, title, text, ringTimes); return true; diff --git a/astrid/src/com/todoroo/astrid/activity/DraggableTaskListFragment.java b/astrid/src/com/todoroo/astrid/activity/DraggableTaskListFragment.java index 51ff0fd00..c295475e8 100644 --- a/astrid/src/com/todoroo/astrid/activity/DraggableTaskListFragment.java +++ b/astrid/src/com/todoroo/astrid/activity/DraggableTaskListFragment.java @@ -31,6 +31,10 @@ public class DraggableTaskListFragment extends TaskListFragment { // --- task list + public DraggableTaskListFragment(Bundle extras) { + super(extras); + } + /** * If database has an indent property for determining how rows are indented, * return it here so we can read it from the cursor and use it diff --git a/astrid/src/com/todoroo/astrid/activity/ShortcutActivity.java b/astrid/src/com/todoroo/astrid/activity/ShortcutActivity.java index 2b1cdf32f..87a7620b9 100644 --- a/astrid/src/com/todoroo/astrid/activity/ShortcutActivity.java +++ b/astrid/src/com/todoroo/astrid/activity/ShortcutActivity.java @@ -87,8 +87,8 @@ public class ShortcutActivity extends Activity { Intent taskListIntent = new Intent(this, TaskListActivity.class); - if(extras != null && extras.containsKey(TaskListFragment.TOKEN_SOURCE)) - taskListIntent.putExtra(TaskListFragment.TOKEN_SOURCE, extras.getInt(TaskListFragment.TOKEN_SOURCE)); + if(extras != null && extras.containsKey(TaskListActivity.TOKEN_SOURCE)) + taskListIntent.putExtra(TaskListActivity.TOKEN_SOURCE, extras.getInt(TaskListActivity.TOKEN_SOURCE)); if(extras != null && extras.containsKey(TOKEN_CUSTOM_CLASS)) { taskListIntent.putExtras(intent.getExtras()); diff --git a/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java b/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java index 79451c127..860aa29c7 100644 --- a/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java +++ b/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java @@ -35,6 +35,8 @@ import com.todoroo.astrid.api.FilterListItem; import com.todoroo.astrid.core.CustomFilterExposer; import com.todoroo.astrid.data.Task; import com.todoroo.astrid.reminders.NotificationFragment; +import com.todoroo.astrid.service.StatisticsConstants; +import com.todoroo.astrid.service.StatisticsService; import com.todoroo.astrid.service.ThemeService; import com.todoroo.astrid.tags.TagFilterExposer; import com.todoroo.astrid.ui.DateChangedAlerts; @@ -49,6 +51,9 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener public static final String TOKEN_SELECTED_FILTER = "selectedFilter"; //$NON-NLS-1$ + /** token for indicating source of TLA launch */ + public static final String TOKEN_SOURCE = "source"; //$NON-NLS-1$ + private View listsNav; private ImageView listsNavDisclosure; private TextView lists; @@ -142,13 +147,17 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener commentsButton.setOnClickListener(commentsButtonClickListener); Filter savedFilter = getIntent().getParcelableExtra(TaskListFragment.TOKEN_FILTER); - if (getIntent().getIntExtra(TaskListFragment.TOKEN_SOURCE, Constants.SOURCE_DEFAULT) == Constants.SOURCE_NOTIFICATION) + if (getIntent().getIntExtra(TOKEN_SOURCE, Constants.SOURCE_DEFAULT) == Constants.SOURCE_NOTIFICATION) setupTasklistFragmentWithFilterAndCustomTaskList(savedFilter, NotificationFragment.class); else setupTasklistFragmentWithFilter(savedFilter); if (savedFilter != null) setListsTitle(savedFilter.title); + + if (getIntent().hasExtra(TOKEN_SOURCE)) { + trackActivitySource(); + } } /** @@ -448,6 +457,31 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener } } + /** + * Report who launched this activity + */ + protected void trackActivitySource() { + switch (getIntent().getIntExtra(TOKEN_SOURCE, + Constants.SOURCE_DEFAULT)) { + case Constants.SOURCE_NOTIFICATION: + StatisticsService.reportEvent(StatisticsConstants.LAUNCH_FROM_NOTIFICATION); + break; + case Constants.SOURCE_OTHER: + StatisticsService.reportEvent(StatisticsConstants.LAUNCH_FROM_OTHER); + break; + case Constants.SOURCE_PPWIDGET: + StatisticsService.reportEvent(StatisticsConstants.LAUNCH_FROM_PPW); + break; + case Constants.SOURCE_WIDGET: + StatisticsService.reportEvent(StatisticsConstants.LAUNCH_FROM_WIDGET); + break; + case Constants.SOURCE_C2DM: + StatisticsService.reportEvent(StatisticsConstants.LAUNCH_FROM_C2DM); + break; + } + getIntent().putExtra(TOKEN_SOURCE, Constants.SOURCE_DEFAULT); // Only report source once + } + @Override public void mainMenuItemSelected(int item) { TaskListFragment tla = getTaskListFragment(); diff --git a/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java b/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java index c13669494..a00e5b24b 100644 --- a/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java +++ b/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java @@ -135,9 +135,6 @@ public class TaskListFragment extends ListFragment implements OnScrollListener, /** token for passing a {@link Filter} object through extras */ public static final String TOKEN_FILTER = "filter"; //$NON-NLS-1$ - /** token for indicating source of TLA launch */ - public static final String TOKEN_SOURCE = "source"; //$NON-NLS-1$ - public static final String TOKEN_OVERRIDE_ANIM = "finishAnim"; //$NON-NLS-1$ // --- instance variables @@ -178,6 +175,7 @@ public class TaskListFragment extends ListFragment implements OnScrollListener, private Timer backgroundTimer; private boolean isFilter; + protected final Bundle extras; private final TaskListContextMenuExtensionLoader contextMenuExtensionLoader = new TaskListContextMenuExtensionLoader(); @@ -195,6 +193,11 @@ public class TaskListFragment extends ListFragment implements OnScrollListener, AstridDependencyInjector.initialize(); } + public TaskListFragment(Bundle extras) { + super(); + this.extras = extras; + } + /** * Container Activity must implement this interface and we ensure that it * does during the onAttach() callback @@ -278,10 +281,6 @@ public class TaskListFragment extends ListFragment implements OnScrollListener, upgradeService.showChangeLog(getActivity(), Preferences.getInt(AstridPreferences.P_UPGRADE_FROM, -1)); - if (getActivity().getIntent().hasExtra(TOKEN_SOURCE)) { - trackActivitySource(); - } - getActivity().runOnUiThread(new Runnable() { public void run() { Thread.currentThread().setPriority(Thread.MAX_PRIORITY); @@ -289,31 +288,6 @@ public class TaskListFragment extends ListFragment implements OnScrollListener, }); } - /** - * Report who launched this activity - */ - protected void trackActivitySource() { - switch (getActivity().getIntent().getIntExtra(TOKEN_SOURCE, - Constants.SOURCE_DEFAULT)) { - case Constants.SOURCE_NOTIFICATION: - StatisticsService.reportEvent(StatisticsConstants.LAUNCH_FROM_NOTIFICATION); - break; - case Constants.SOURCE_OTHER: - StatisticsService.reportEvent(StatisticsConstants.LAUNCH_FROM_OTHER); - break; - case Constants.SOURCE_PPWIDGET: - StatisticsService.reportEvent(StatisticsConstants.LAUNCH_FROM_PPW); - break; - case Constants.SOURCE_WIDGET: - StatisticsService.reportEvent(StatisticsConstants.LAUNCH_FROM_WIDGET); - break; - case Constants.SOURCE_C2DM: - StatisticsService.reportEvent(StatisticsConstants.LAUNCH_FROM_C2DM); - break; - } - getActivity().getIntent().putExtra(TOKEN_SOURCE, Constants.SOURCE_DEFAULT); // Only report source once - } - /** * @return the current tag you are viewing, or null if you're not viewing a tag */ @@ -322,7 +296,6 @@ public class TaskListFragment extends ListFragment implements OnScrollListener, } protected void onNewIntent(Intent intent) { - Bundle extras = intent.getExtras(); if (extras != null) { overrideFinishAnim = extras.getBoolean(TOKEN_OVERRIDE_ANIM); } else { @@ -337,9 +310,9 @@ public class TaskListFragment extends ListFragment implements OnScrollListener, "%" + //$NON-NLS-1$ query.toUpperCase() + "%")), //$NON-NLS-1$ null); - intent = new Intent(getActivity(), TaskListActivity.class); - intent.putExtra(TaskListFragment.TOKEN_FILTER, searchFilter); - startActivity(intent); + Intent searchIntent = new Intent(getActivity(), TaskListActivity.class); + searchIntent.putExtra(TaskListFragment.TOKEN_FILTER, searchFilter); + startActivity(searchIntent); getActivity().finish(); if (overrideFinishAnim) { AndroidUtilities.callOverridePendingTransition(getActivity(), diff --git a/astrid/src/com/todoroo/astrid/adapter/TaskListFragmentPagerAdapter.java b/astrid/src/com/todoroo/astrid/adapter/TaskListFragmentPagerAdapter.java index 9e51001a6..00a93d155 100644 --- a/astrid/src/com/todoroo/astrid/adapter/TaskListFragmentPagerAdapter.java +++ b/astrid/src/com/todoroo/astrid/adapter/TaskListFragmentPagerAdapter.java @@ -37,18 +37,18 @@ public class TaskListFragmentPagerAdapter extends FragmentStatePagerAdapter { Constructor constructor = component.getConstructor(Boolean.class, Filter.class); return (Fragment) constructor.newInstance(true, filter); } catch (NoSuchMethodException e) { - return new TaskListFragment(); + return new TaskListFragment(null); } catch (InvocationTargetException e) { - return new TaskListFragment(); + return new TaskListFragment(null); } catch (ClassNotFoundException e) { - return new TaskListFragment(); + return new TaskListFragment(null); } catch (IllegalAccessException e) { - return new TaskListFragment(); + return new TaskListFragment(null); } catch (InstantiationException e) { - return new TaskListFragment(); + return new TaskListFragment(null); } } else { - return new TaskListFragment(); + return new TaskListFragment(null); } } diff --git a/astrid/src/com/todoroo/astrid/widget/TasksWidget.java b/astrid/src/com/todoroo/astrid/widget/TasksWidget.java index 1f9541a27..bdc12fb05 100644 --- a/astrid/src/com/todoroo/astrid/widget/TasksWidget.java +++ b/astrid/src/com/todoroo/astrid/widget/TasksWidget.java @@ -26,10 +26,10 @@ import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.Preferences; -import com.todoroo.astrid.activity.TaskEditFragment; import com.todoroo.astrid.activity.TaskEditActivity; -import com.todoroo.astrid.activity.TaskListFragment; +import com.todoroo.astrid.activity.TaskEditFragment; import com.todoroo.astrid.activity.TaskListActivity; +import com.todoroo.astrid.activity.TaskListFragment; import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.api.FilterWithCustomIntent; import com.todoroo.astrid.api.PermaSql; @@ -217,7 +217,7 @@ public class TasksWidget extends AppWidgetProvider { Bundle extras = AndroidUtilities.bundleFromSerializedString(serializedExtras); listIntent.putExtras(extras); } - listIntent.putExtra(TaskListFragment.TOKEN_SOURCE, Constants.SOURCE_WIDGET); + listIntent.putExtra(TaskListActivity.TOKEN_SOURCE, Constants.SOURCE_WIDGET); listIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK); if(filter != null) { listIntent.putExtra(TaskListFragment.TOKEN_FILTER, filter);