diff --git a/src/main/java/com/todoroo/astrid/activity/TaskEditFragment.java b/src/main/java/com/todoroo/astrid/activity/TaskEditFragment.java index 201a49d63..6ed9f1ac0 100755 --- a/src/main/java/com/todoroo/astrid/activity/TaskEditFragment.java +++ b/src/main/java/com/todoroo/astrid/activity/TaskEditFragment.java @@ -358,7 +358,6 @@ public final class TaskEditFragment extends InjectingFragment implements EditNot if (tagsChanged) { tla.tagsChanged(); } - tla.refreshTaskList(); if (isNewTask) { tla.getTaskListFragment().onTaskCreated(model.getId(), model.getUuid()); } @@ -397,7 +396,6 @@ public final class TaskEditFragment extends InjectingFragment implements EditNot */ public static void removeExtrasFromIntent(Intent intent) { if (intent != null) { - intent.removeExtra(TaskListActivity.TOKEN_SWITCH_TO_FILTER); intent.removeExtra(TaskListActivity.OPEN_TASK); intent.removeExtra(TOKEN_PICTURE_IN_PROGRESS); } diff --git a/src/main/java/com/todoroo/astrid/activity/TaskListActivity.java b/src/main/java/com/todoroo/astrid/activity/TaskListActivity.java index 879304851..021b3d151 100644 --- a/src/main/java/com/todoroo/astrid/activity/TaskListActivity.java +++ b/src/main/java/com/todoroo/astrid/activity/TaskListActivity.java @@ -118,8 +118,6 @@ public class TaskListActivity extends InjectingAppCompatActivity implements private NavigationDrawerFragment navigationDrawer; private ArrayList controlOrder; - public static final String TOKEN_SWITCH_TO_FILTER = "newListCreated"; //$NON-NLS-1$ - /** For indicating the new list screen should be launched at fragment setup time */ public static final String TOKEN_CREATE_NEW_LIST = "createNewList"; //$NON-NLS-1$ public static final String TOKEN_CREATE_NEW_LIST_NAME = "newListName"; //$NON-NLS-1$ @@ -200,11 +198,15 @@ public class TaskListActivity extends InjectingAppCompatActivity implements Filter filter = intent.getParcelableExtra(TaskListFragment.TOKEN_FILTER); extras.putAll(configureIntentAndExtrasWithFilter(intent, filter)); taskListFragment = newTaskListFragment(filter, extras); + intent.removeExtra(TaskListFragment.TOKEN_FILTER); } else { taskListFragment = getTaskListFragment(); if (taskListFragment == null) { Filter filter = getDefaultFilter(); - extras.putAll(configureIntentAndExtrasWithFilter(intent, filter)); + Bundle bundle = configureIntentAndExtrasWithFilter(intent, filter); + if (bundle != null) { + extras.putAll(bundle); + } taskListFragment = newTaskListFragment(filter, extras); } } @@ -408,9 +410,7 @@ public class TaskListActivity extends InjectingAppCompatActivity implements Timber.e(e, e.getMessage()); newFragment = new TaskListFragment(); } - Bundle args = new Bundle(); - args.putBundle(TaskListFragment.TOKEN_EXTRAS, extras); - newFragment.setArguments(args); + newFragment.initialize(filter, extras); return newFragment; } @@ -418,12 +418,6 @@ public class TaskListActivity extends InjectingAppCompatActivity implements protected void onPostResume() { super.onPostResume(); - if (getIntent().hasExtra(TOKEN_SWITCH_TO_FILTER)) { - Filter newList = getIntent().getParcelableExtra(TOKEN_SWITCH_TO_FILTER); - getIntent().removeExtra(TOKEN_SWITCH_TO_FILTER); - onFilterItemClicked(newList); - } - if (getIntent().hasExtra(OPEN_TASK)) { long id = getIntent().getLongExtra(OPEN_TASK, 0); if (id > 0) { @@ -563,7 +557,7 @@ public class TaskListActivity extends InjectingAppCompatActivity implements Filter newList = data.getParcelableExtra(TagSettingsActivity.TOKEN_NEW_FILTER); if (newList != null) { - getIntent().putExtra(TOKEN_SWITCH_TO_FILTER, newList); // Handle in onPostResume() + onFilterItemClicked(newList); navigationDrawer.clear(); } @@ -580,7 +574,7 @@ public class TaskListActivity extends InjectingAppCompatActivity implements td = tagDataDao.fetch(uuid, TagData.PROPERTIES); if (td != null) { Filter filter = TagFilterExposer.filterFromTagData(this, td); - getIntent().putExtra(TOKEN_SWITCH_TO_FILTER, filter); + onFilterItemClicked(filter); } } else { tlf.refresh(); @@ -594,7 +588,7 @@ public class TaskListActivity extends InjectingAppCompatActivity implements activeUuid = tagData.getUuid(); } if (activeUuid.equals(uuid)) { - getIntent().putExtra(TOKEN_SWITCH_TO_FILTER, BuiltInFilterExposer.getMyTasksFilter(getResources())); // Handle in onPostResume() + onFilterItemClicked(BuiltInFilterExposer.getMyTasksFilter(getResources())); navigationDrawer.clear(); // Should auto refresh } else { tlf.refresh(); @@ -609,9 +603,9 @@ public class TaskListActivity extends InjectingAppCompatActivity implements String action = data.getAction(); if (AstridApiConstants.BROADCAST_EVENT_FILTER_RENAMED.equals(action)) { CustomFilter customFilter = data.getParcelableExtra(FilterSettingsActivity.TOKEN_FILTER); - getIntent().putExtra(TOKEN_SWITCH_TO_FILTER, customFilter); + onFilterItemClicked(customFilter); } else if(AstridApiConstants.BROADCAST_EVENT_FILTER_DELETED.equals(action)) { - getIntent().putExtra(TOKEN_SWITCH_TO_FILTER, BuiltInFilterExposer.getMyTasksFilter(getResources())); + onFilterItemClicked(BuiltInFilterExposer.getMyTasksFilter(getResources())); } navigationDrawer.refresh(); @@ -621,7 +615,7 @@ public class TaskListActivity extends InjectingAppCompatActivity implements TasksWidget.updateWidgets(this); if (data.hasExtra(SortActivity.EXTRA_TOGGLE_MANUAL)) { - getIntent().putExtra(TOKEN_SWITCH_TO_FILTER, getTaskListFragment().getFilter()); + onFilterItemClicked(getTaskListFragment().getFilter()); } else { getTaskListFragment().setUpTaskList(); } @@ -651,13 +645,6 @@ public class TaskListActivity extends InjectingAppCompatActivity implements } } - protected void refreshTaskList() { - TaskListFragment tlf = getTaskListFragment(); - if (tlf != null) { - tlf.refresh(); - } - } - public void refreshFilterCount() { navigationDrawer.refreshFilterCount(); } @@ -726,12 +713,9 @@ public class TaskListActivity extends InjectingAppCompatActivity implements int lastSelectedList = intent.getIntExtra(NavigationDrawerFragment.TOKEN_LAST_SELECTED, 0); intent = ((FilterWithCustomIntent)filter).getCustomIntent(); intent.putExtra(NavigationDrawerFragment.TOKEN_LAST_SELECTED, lastSelectedList); - } else { - intent.putExtra(TaskListFragment.TOKEN_FILTER, filter); + setIntent(intent); } - setIntent(intent); - Bundle extras = intent.getExtras(); if (extras != null) { extras = (Bundle) extras.clone(); diff --git a/src/main/java/com/todoroo/astrid/activity/TaskListFragment.java b/src/main/java/com/todoroo/astrid/activity/TaskListFragment.java index c583132af..8216b6068 100644 --- a/src/main/java/com/todoroo/astrid/activity/TaskListFragment.java +++ b/src/main/java/com/todoroo/astrid/activity/TaskListFragment.java @@ -87,6 +87,9 @@ import timber.log.Timber; */ public class TaskListFragment extends InjectingListFragment implements SwipeRefreshLayout.OnRefreshListener { + private static final String EXTRA_FILTER = "extra_filter"; + private static final String EXTRA_EXTRAS = "extra_extras"; + public static final String TAG_TASKLIST_FRAGMENT = "tasklist_fragment"; //$NON-NLS-1$ // --- activities @@ -107,8 +110,6 @@ public class TaskListFragment extends InjectingListFragment implements SwipeRefr /** token for passing a {@link Filter} object through extras */ public static final String TOKEN_FILTER = "filter"; //$NON-NLS-1$ - public static final String TOKEN_EXTRAS = "extras"; //$NON-NLS-1$ - // --- instance variables @Inject TaskService taskService; @@ -186,12 +187,33 @@ public class TaskListFragment extends InjectingListFragment implements SwipeRefr @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - extras = getArguments() != null ? getArguments().getBundle(TOKEN_EXTRAS) : null; + + if (savedInstanceState != null) { + filter = savedInstanceState.getParcelable(EXTRA_FILTER); + extras = savedInstanceState.getBundle(EXTRA_EXTRAS); + } + + if (filter == null) { + filter = BuiltInFilterExposer.getMyTasksFilter(getResources()); + } if (extras == null) { extras = new Bundle(); // Just need an empty one to prevent potential null pointers } } + public void initialize(Filter filter, Bundle extras) { + this.filter = filter; + this.extras = extras; + } + + @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + + outState.putParcelable(EXTRA_FILTER, filter); + outState.putBundle(EXTRA_EXTRAS, extras); + } + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -280,12 +302,6 @@ public class TaskListFragment extends InjectingListFragment implements SwipeRefr } protected void initializeData() { - if (extras != null && extras.containsKey(TOKEN_FILTER)) { - filter = extras.getParcelable(TOKEN_FILTER); -// extras.remove(TOKEN_FILTER); // Otherwise writing this filter to parcel gives infinite recursion - } else { - filter = BuiltInFilterExposer.getMyTasksFilter(getResources()); - } filter.setFilterQueryOverride(null); isInbox = BuiltInFilterExposer.isInbox(context, filter); isTodayFilter = false; @@ -342,6 +358,8 @@ public class TaskListFragment extends InjectingListFragment implements SwipeRefr } protected void setUpUiComponents() { + registerForContextMenu(getListView()); + // set listener for quick-changing task priority getListView().setOnKeyListener(new OnKeyListener() { @Override @@ -544,7 +562,6 @@ public class TaskListFragment extends InjectingListFragment implements SwipeRefr taskAdapter = createTaskAdapter(currentCursor); setListAdapter(taskAdapter); - registerForContextMenu(getListView()); loadTaskListContent(); } diff --git a/src/main/java/org/tasks/Notifier.java b/src/main/java/org/tasks/Notifier.java index fd1770685..8dcb0e664 100644 --- a/src/main/java/org/tasks/Notifier.java +++ b/src/main/java/org/tasks/Notifier.java @@ -17,12 +17,12 @@ import com.todoroo.andlib.data.TodorooCursor; import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.astrid.activity.TaskListActivity; +import com.todoroo.astrid.activity.TaskListFragment; import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.dao.TaskDao; import com.todoroo.astrid.data.Task; import com.todoroo.astrid.reminders.ReminderService; import com.todoroo.astrid.service.TaskService; -import com.todoroo.astrid.utility.Flags; import com.todoroo.astrid.voice.VoiceOutputAssistant; import org.tasks.injection.ForApplication; @@ -158,7 +158,7 @@ public class Notifier { PendingIntent pendingIntent = PendingIntent.getActivity(context, (title + query).hashCode(), new Intent(context, TaskListActivity.class) {{ setFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_MULTIPLE_TASK); - putExtra(TaskListActivity.TOKEN_SWITCH_TO_FILTER, new Filter(title, query, AndroidUtilities.contentValuesFromSerializedString(valuesForNewTasks))); + putExtra(TaskListFragment.TOKEN_FILTER, new Filter(title, query, AndroidUtilities.contentValuesFromSerializedString(valuesForNewTasks))); }}, PendingIntent.FLAG_UPDATE_CURRENT); Notification notification = new NotificationCompat.Builder(context) diff --git a/src/main/java/org/tasks/ui/NavigationDrawerFragment.java b/src/main/java/org/tasks/ui/NavigationDrawerFragment.java index c0a4dd539..038353812 100644 --- a/src/main/java/org/tasks/ui/NavigationDrawerFragment.java +++ b/src/main/java/org/tasks/ui/NavigationDrawerFragment.java @@ -16,7 +16,6 @@ import android.widget.AdapterView; import android.widget.ListView; import com.todoroo.astrid.actfm.TagSettingsActivity; -import com.todoroo.astrid.activity.TaskListActivity; import com.todoroo.astrid.activity.TaskListFragment; import com.todoroo.astrid.adapter.FilterAdapter; import com.todoroo.astrid.api.AstridApiConstants; @@ -100,7 +99,7 @@ public class NavigationDrawerFragment extends InjectingFragment { Filter newList = data.getParcelableExtra(TagSettingsActivity.TOKEN_NEW_FILTER); if (newList != null) { - getActivity().getIntent().putExtra(TaskListActivity.TOKEN_SWITCH_TO_FILTER, newList); + mCallbacks.onFilterItemClicked(newList); clear(); } } else {