Refactored task list fragments to not call getIntent() from their activity

pull/14/head
Sam Bosley 13 years ago
parent 5f47be86b2
commit d009c87cd9

@ -233,7 +233,7 @@ public class C2DMReceiver extends BroadcastReceiver {
} }
notifyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 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, PendingIntent pendingIntent = PendingIntent.getActivity(context,
notifId, notifyIntent, 0); notifId, notifyIntent, 0);

@ -95,6 +95,10 @@ public class TagViewFragment extends TaskListFragment {
// --- UI initialization // --- UI initialization
public TagViewFragment(Bundle extras) {
super(extras);
}
@Override @Override
public void onActivityCreated(final Bundle savedInstanceState) { public void onActivityCreated(final Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState); super.onActivityCreated(savedInstanceState);
@ -174,8 +178,8 @@ public class TagViewFragment extends TaskListFragment {
} }
TaskListActivity activity = (TaskListActivity) getActivity(); TaskListActivity activity = (TaskListActivity) getActivity();
String tag = activity.getIntent().getStringExtra(EXTRA_TAG_NAME); String tag = extras.getString(EXTRA_TAG_NAME);
long remoteId = activity.getIntent().getLongExtra(EXTRA_TAG_REMOTE_ID, 0); long remoteId = extras.getLong(EXTRA_TAG_REMOTE_ID, 0);
if(tag == null && remoteId == 0) if(tag == null && remoteId == 0)
return; return;
@ -200,8 +204,8 @@ public class TagViewFragment extends TaskListFragment {
super.onNewIntent(intent); super.onNewIntent(intent);
if (activity.getIntent().getBooleanExtra(TOKEN_START_ACTIVITY, false)) { if (extras.getBoolean(TOKEN_START_ACTIVITY, false)) {
activity.getIntent().removeExtra(TOKEN_START_ACTIVITY); extras.remove(TOKEN_START_ACTIVITY);
activity.showComments(); activity.showComments();
} }
} }
@ -456,6 +460,7 @@ public class TagViewFragment extends TaskListFragment {
tagData = tagDataService.fetchById(tagData.getId(), TagData.PROPERTIES); tagData = tagDataService.fetchById(tagData.getId(), TagData.PROPERTIES);
filter = TagFilterExposer.filterFromTagData(getActivity(), tagData); filter = TagFilterExposer.filterFromTagData(getActivity(), tagData);
getActivity().getIntent().putExtra(TOKEN_FILTER, filter); getActivity().getIntent().putExtra(TOKEN_FILTER, filter);
extras.putParcelable(TOKEN_FILTER, filter);
Activity activity = getActivity(); Activity activity = getActivity();
if (activity instanceof TaskListActivity) { if (activity instanceof TaskListActivity) {
((TaskListActivity) activity).setListsTitle(filter.title); ((TaskListActivity) activity).setListsTitle(filter.title);

@ -64,6 +64,10 @@ public class GtasksListFragment extends DraggableTaskListFragment {
GtasksList.LAST_SYNC GtasksList.LAST_SYNC
}; };
public GtasksListFragment(Bundle extras) {
super(extras);
}
@Override @Override
public void onActivityCreated(Bundle icicle) { public void onActivityCreated(Bundle icicle) {
super.onActivityCreated(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); list = storeObjectDao.fetch(storeObjectId, LIST_PROPERTIES);
} }

@ -71,6 +71,10 @@ public class NotificationFragment extends TaskListFragment implements OnTimeSetL
private long taskId; private long taskId;
public NotificationFragment(Bundle extras) {
super(extras);
}
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
StartupService.bypassInitialization(); StartupService.bypassInitialization();
@ -120,7 +124,7 @@ public class NotificationFragment extends TaskListFragment implements OnTimeSetL
// hide quick add // hide quick add
getView().findViewById(R.id.taskListFooter).setVisibility(View.GONE); 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(); new ReminderDialog((AstridActivity) getActivity(), taskId, title).show();
} }

@ -25,7 +25,6 @@ import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.Preferences; import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.activity.TaskListActivity; import com.todoroo.astrid.activity.TaskListActivity;
import com.todoroo.astrid.activity.TaskListFragment;
import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.dao.TaskDao; import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
@ -180,7 +179,7 @@ public class Notifications extends BroadcastReceiver {
notifyIntent.putExtra(NotificationFragment.TOKEN_ID, id); notifyIntent.putExtra(NotificationFragment.TOKEN_ID, id);
notifyIntent.putExtra(EXTRAS_TEXT, text); notifyIntent.putExtra(EXTRAS_TEXT, text);
notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK); 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); requestNotification((int)id, notifyIntent, type, title, text, ringTimes);
return true; return true;

@ -31,6 +31,10 @@ public class DraggableTaskListFragment extends TaskListFragment {
// --- task list // --- task list
public DraggableTaskListFragment(Bundle extras) {
super(extras);
}
/** /**
* If database has an indent property for determining how rows are indented, * 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 * return it here so we can read it from the cursor and use it

@ -87,8 +87,8 @@ public class ShortcutActivity extends Activity {
Intent taskListIntent = new Intent(this, TaskListActivity.class); Intent taskListIntent = new Intent(this, TaskListActivity.class);
if(extras != null && extras.containsKey(TaskListFragment.TOKEN_SOURCE)) if(extras != null && extras.containsKey(TaskListActivity.TOKEN_SOURCE))
taskListIntent.putExtra(TaskListFragment.TOKEN_SOURCE, extras.getInt(TaskListFragment.TOKEN_SOURCE)); taskListIntent.putExtra(TaskListActivity.TOKEN_SOURCE, extras.getInt(TaskListActivity.TOKEN_SOURCE));
if(extras != null && extras.containsKey(TOKEN_CUSTOM_CLASS)) { if(extras != null && extras.containsKey(TOKEN_CUSTOM_CLASS)) {
taskListIntent.putExtras(intent.getExtras()); taskListIntent.putExtras(intent.getExtras());

@ -35,6 +35,8 @@ import com.todoroo.astrid.api.FilterListItem;
import com.todoroo.astrid.core.CustomFilterExposer; import com.todoroo.astrid.core.CustomFilterExposer;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.reminders.NotificationFragment; 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.service.ThemeService;
import com.todoroo.astrid.tags.TagFilterExposer; import com.todoroo.astrid.tags.TagFilterExposer;
import com.todoroo.astrid.ui.DateChangedAlerts; 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$ 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 View listsNav;
private ImageView listsNavDisclosure; private ImageView listsNavDisclosure;
private TextView lists; private TextView lists;
@ -142,13 +147,17 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
commentsButton.setOnClickListener(commentsButtonClickListener); commentsButton.setOnClickListener(commentsButtonClickListener);
Filter savedFilter = getIntent().getParcelableExtra(TaskListFragment.TOKEN_FILTER); 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); setupTasklistFragmentWithFilterAndCustomTaskList(savedFilter, NotificationFragment.class);
else else
setupTasklistFragmentWithFilter(savedFilter); setupTasklistFragmentWithFilter(savedFilter);
if (savedFilter != null) if (savedFilter != null)
setListsTitle(savedFilter.title); 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 @Override
public void mainMenuItemSelected(int item) { public void mainMenuItemSelected(int item) {
TaskListFragment tla = getTaskListFragment(); TaskListFragment tla = getTaskListFragment();

@ -135,9 +135,6 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
/** token for passing a {@link Filter} object through extras */ /** token for passing a {@link Filter} object through extras */
public static final String TOKEN_FILTER = "filter"; //$NON-NLS-1$ 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$ public static final String TOKEN_OVERRIDE_ANIM = "finishAnim"; //$NON-NLS-1$
// --- instance variables // --- instance variables
@ -178,6 +175,7 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
private Timer backgroundTimer; private Timer backgroundTimer;
private boolean isFilter; private boolean isFilter;
protected final Bundle extras;
private final TaskListContextMenuExtensionLoader contextMenuExtensionLoader = new TaskListContextMenuExtensionLoader(); private final TaskListContextMenuExtensionLoader contextMenuExtensionLoader = new TaskListContextMenuExtensionLoader();
@ -195,6 +193,11 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
AstridDependencyInjector.initialize(); AstridDependencyInjector.initialize();
} }
public TaskListFragment(Bundle extras) {
super();
this.extras = extras;
}
/** /**
* Container Activity must implement this interface and we ensure that it * Container Activity must implement this interface and we ensure that it
* does during the onAttach() callback * does during the onAttach() callback
@ -278,10 +281,6 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
upgradeService.showChangeLog(getActivity(), upgradeService.showChangeLog(getActivity(),
Preferences.getInt(AstridPreferences.P_UPGRADE_FROM, -1)); Preferences.getInt(AstridPreferences.P_UPGRADE_FROM, -1));
if (getActivity().getIntent().hasExtra(TOKEN_SOURCE)) {
trackActivitySource();
}
getActivity().runOnUiThread(new Runnable() { getActivity().runOnUiThread(new Runnable() {
public void run() { public void run() {
Thread.currentThread().setPriority(Thread.MAX_PRIORITY); 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 * @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) { protected void onNewIntent(Intent intent) {
Bundle extras = intent.getExtras();
if (extras != null) { if (extras != null) {
overrideFinishAnim = extras.getBoolean(TOKEN_OVERRIDE_ANIM); overrideFinishAnim = extras.getBoolean(TOKEN_OVERRIDE_ANIM);
} else { } else {
@ -337,9 +310,9 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
"%" + //$NON-NLS-1$ "%" + //$NON-NLS-1$
query.toUpperCase() + "%")), //$NON-NLS-1$ query.toUpperCase() + "%")), //$NON-NLS-1$
null); null);
intent = new Intent(getActivity(), TaskListActivity.class); Intent searchIntent = new Intent(getActivity(), TaskListActivity.class);
intent.putExtra(TaskListFragment.TOKEN_FILTER, searchFilter); searchIntent.putExtra(TaskListFragment.TOKEN_FILTER, searchFilter);
startActivity(intent); startActivity(searchIntent);
getActivity().finish(); getActivity().finish();
if (overrideFinishAnim) { if (overrideFinishAnim) {
AndroidUtilities.callOverridePendingTransition(getActivity(), AndroidUtilities.callOverridePendingTransition(getActivity(),

@ -37,18 +37,18 @@ public class TaskListFragmentPagerAdapter extends FragmentStatePagerAdapter {
Constructor<?> constructor = component.getConstructor(Boolean.class, Filter.class); Constructor<?> constructor = component.getConstructor(Boolean.class, Filter.class);
return (Fragment) constructor.newInstance(true, filter); return (Fragment) constructor.newInstance(true, filter);
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) {
return new TaskListFragment(); return new TaskListFragment(null);
} catch (InvocationTargetException e) { } catch (InvocationTargetException e) {
return new TaskListFragment(); return new TaskListFragment(null);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
return new TaskListFragment(); return new TaskListFragment(null);
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
return new TaskListFragment(); return new TaskListFragment(null);
} catch (InstantiationException e) { } catch (InstantiationException e) {
return new TaskListFragment(); return new TaskListFragment(null);
} }
} else { } else {
return new TaskListFragment(); return new TaskListFragment(null);
} }
} }

@ -26,10 +26,10 @@ import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.Preferences; import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.activity.TaskEditFragment;
import com.todoroo.astrid.activity.TaskEditActivity; 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.TaskListActivity;
import com.todoroo.astrid.activity.TaskListFragment;
import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.api.FilterWithCustomIntent; import com.todoroo.astrid.api.FilterWithCustomIntent;
import com.todoroo.astrid.api.PermaSql; import com.todoroo.astrid.api.PermaSql;
@ -217,7 +217,7 @@ public class TasksWidget extends AppWidgetProvider {
Bundle extras = AndroidUtilities.bundleFromSerializedString(serializedExtras); Bundle extras = AndroidUtilities.bundleFromSerializedString(serializedExtras);
listIntent.putExtras(extras); 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); listIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
if(filter != null) { if(filter != null) {
listIntent.putExtra(TaskListFragment.TOKEN_FILTER, filter); listIntent.putExtra(TaskListFragment.TOKEN_FILTER, filter);

Loading…
Cancel
Save