diff --git a/astrid/src/main/java/com/todoroo/astrid/activity/TaskListFragment.java b/astrid/src/main/java/com/todoroo/astrid/activity/TaskListFragment.java index 4f050c079..236db9f09 100644 --- a/astrid/src/main/java/com/todoroo/astrid/activity/TaskListFragment.java +++ b/astrid/src/main/java/com/todoroo/astrid/activity/TaskListFragment.java @@ -58,7 +58,6 @@ import com.todoroo.astrid.data.TagData; import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.TaskAttachment; import com.todoroo.astrid.data.TaskListMetadata; -import com.todoroo.astrid.gtasks.GtasksListFragment; import com.todoroo.astrid.gtasks.GtasksPreferenceService; import com.todoroo.astrid.helper.SyncActionHelper; import com.todoroo.astrid.service.SyncV2Service; @@ -66,6 +65,7 @@ import com.todoroo.astrid.service.TaskDeleter; import com.todoroo.astrid.service.TaskDuplicator; import com.todoroo.astrid.service.TaskService; import com.todoroo.astrid.subtasks.SubtasksHelper; +import com.todoroo.astrid.subtasks.SubtasksListFragment; import com.todoroo.astrid.subtasks.SubtasksUpdater; import com.todoroo.astrid.tags.TaskToTagMetadata; import com.todoroo.astrid.timers.TimerPlugin; @@ -325,7 +325,7 @@ public class TaskListFragment extends InjectingListFragment implements OnSortSel getListView().setItemsCanFocus(false); } - if (!(this instanceof GtasksListFragment)) { + if (!(this instanceof SubtasksListFragment)) { getListView().setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, @@ -912,7 +912,7 @@ public class TaskListFragment extends InjectingListFragment implements OnSortSel extras.putParcelable(TOKEN_FILTER, filter); if(newState) { ((AstridActivity) getActivity()).setupTasklistFragmentWithFilterAndCustomTaskList(filter, - extras, GtasksListFragment.class); + extras, SubtasksListFragment.class); } else { filter.setFilterQueryOverride(null); ((AstridActivity)getActivity()).setupTasklistFragmentWithFilterAndCustomTaskList(filter, diff --git a/astrid/src/main/java/com/todoroo/astrid/gtasks/GtasksListFragment.java b/astrid/src/main/java/com/todoroo/astrid/gtasks/GtasksListFragment.java index ed92604e9..bb90835ce 100644 --- a/astrid/src/main/java/com/todoroo/astrid/gtasks/GtasksListFragment.java +++ b/astrid/src/main/java/com/todoroo/astrid/gtasks/GtasksListFragment.java @@ -11,27 +11,22 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view.MenuItem; -import android.view.View; -import android.view.ViewGroup; import android.widget.TextView; import com.todoroo.andlib.data.Property; import com.todoroo.andlib.data.TodorooCursor; import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.DialogUtilities; -import com.todoroo.astrid.activity.TaskListFragment; -import com.todoroo.astrid.adapter.TaskAdapter; import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.dao.MetadataDao; import com.todoroo.astrid.dao.StoreObjectDao; import com.todoroo.astrid.dao.TaskAttachmentDao; import com.todoroo.astrid.data.StoreObject; import com.todoroo.astrid.data.Task; -import com.todoroo.astrid.data.TaskListMetadata; import com.todoroo.astrid.service.SyncV2Service; import com.todoroo.astrid.service.TaskService; -import com.todoroo.astrid.subtasks.AstridOrderedListFragmentHelper; import com.todoroo.astrid.subtasks.OrderedListFragmentHelperInterface; +import com.todoroo.astrid.subtasks.SubtasksListFragment; import org.tasks.R; import org.tasks.injection.ForActivity; @@ -41,11 +36,7 @@ import org.tasks.sync.SyncThrottle; import javax.inject.Inject; -public class GtasksListFragment extends TaskListFragment { - - protected OrderedListFragmentHelperInterface helper; - - private int lastVisibleIndex = -1; +public class GtasksListFragment extends SubtasksListFragment { public static final String TOKEN_STORE_ID = "storeId"; //$NON-NLS-1$ @@ -72,6 +63,7 @@ public class GtasksListFragment extends TaskListFragment { GtasksList.LAST_SYNC }; + @Override protected OrderedListFragmentHelperInterface createFragmentHelper() { return new OrderedMetadataListFragmentHelper<>(preferences, taskAttachmentDao, taskService, metadataDao, this, gtasksTaskListUpdater); } @@ -174,72 +166,4 @@ public class GtasksListFragment extends TaskListFragment { public Property[] taskProperties() { return helper.taskProperties(); } - - @Override - public void onAttach(Activity activity) { - super.onAttach(activity); - - helper = createFragmentHelper(); - } - - @Override - protected View getListBody(ViewGroup root) { - return getActivity().getLayoutInflater().inflate(R.layout.task_list_body_subtasks, root, false); - } - - @Override - protected void setUpUiComponents() { - super.setUpUiComponents(); - - helper.setUpUiComponents(); - } - - @Override - public void setUpTaskList() { - if (helper instanceof AstridOrderedListFragmentHelper) { - ((AstridOrderedListFragmentHelper) helper).setList(taskListMetadata); - } - helper.beforeSetUpTaskList(filter); - - super.setUpTaskList(); - - unregisterForContextMenu(getListView()); - } - - @Override - public void onPause() { - super.onPause(); - lastVisibleIndex = getListView().getFirstVisiblePosition(); - } - - @Override - public void onResume() { - super.onResume(); - if (lastVisibleIndex >=0) { - getListView().setSelection(lastVisibleIndex); - } - } - - @Override - protected boolean isDraggable() { - return true; - } - - @Override - public void onTaskCreated(Task task) { - super.onTaskCreated(task); - helper.onCreateTask(task); - } - - @Override - protected TaskAdapter createTaskAdapter(TodorooCursor cursor) { - return helper.createTaskAdapter(cursor, sqlQueryTemplate); - } - - @Override - protected void refresh() { - initializeTaskListMetadata(); - setUpTaskList(); - setSyncOngoing(false); - } } diff --git a/astrid/src/main/java/com/todoroo/astrid/subtasks/SubtasksHelper.java b/astrid/src/main/java/com/todoroo/astrid/subtasks/SubtasksHelper.java index 1e01dea8a..5934e8f2f 100644 --- a/astrid/src/main/java/com/todoroo/astrid/subtasks/SubtasksHelper.java +++ b/astrid/src/main/java/com/todoroo/astrid/subtasks/SubtasksHelper.java @@ -18,7 +18,6 @@ import com.todoroo.astrid.data.RemoteModel; import com.todoroo.astrid.data.TagData; import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.TaskListMetadata; -import com.todoroo.astrid.gtasks.GtasksListFragment; import com.todoroo.astrid.service.TaskService; import com.todoroo.astrid.subtasks.AstridOrderedListUpdater.Node; @@ -48,7 +47,7 @@ public class SubtasksHelper { if (SubtasksHelper.isTagFilter(filter)) { return SubtasksTagListFragment.class; } - return GtasksListFragment.class; + return SubtasksListFragment.class; } public static boolean isTagFilter(Filter filter) { diff --git a/astrid/src/main/java/com/todoroo/astrid/subtasks/SubtasksListFragment.java b/astrid/src/main/java/com/todoroo/astrid/subtasks/SubtasksListFragment.java new file mode 100644 index 000000000..30318f54b --- /dev/null +++ b/astrid/src/main/java/com/todoroo/astrid/subtasks/SubtasksListFragment.java @@ -0,0 +1,120 @@ +/** + * Copyright (c) 2012 Todoroo Inc + * + * See the file "LICENSE" for the full license governing this code. + */ +package com.todoroo.astrid.subtasks; + +import android.app.Activity; +import android.view.View; +import android.view.ViewGroup; + +import com.todoroo.andlib.data.TodorooCursor; +import com.todoroo.astrid.activity.TaskListFragment; +import com.todoroo.astrid.adapter.TaskAdapter; +import com.todoroo.astrid.dao.TaskAttachmentDao; +import com.todoroo.astrid.data.Task; +import com.todoroo.astrid.data.TaskListMetadata; +import com.todoroo.astrid.service.TaskService; + +import org.tasks.R; +import org.tasks.preferences.ActivityPreferences; + +import javax.inject.Inject; + +/** + * Fragment for subtasks + * + * @author Tim Su + * + */ +public class SubtasksListFragment extends TaskListFragment { + + protected OrderedListFragmentHelperInterface helper; + + private int lastVisibleIndex = -1; + + @Inject TaskService taskService; + @Inject SubtasksFilterUpdater subtasksFilterUpdater; + @Inject TaskAttachmentDao taskAttachmentDao; + @Inject ActivityPreferences preferences; + + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + + helper = createFragmentHelper(); + } + + protected OrderedListFragmentHelperInterface createFragmentHelper() { + return new AstridOrderedListFragmentHelper<>(preferences, taskAttachmentDao, taskService, this, subtasksFilterUpdater); + } + + @Override + protected View getListBody(ViewGroup root) { + return getActivity().getLayoutInflater().inflate(R.layout.task_list_body_subtasks, root, false); + } + + @Override + protected void setUpUiComponents() { + super.setUpUiComponents(); + + helper.setUpUiComponents(); + } + + @Override + public void setUpTaskList() { + if (helper instanceof AstridOrderedListFragmentHelper) { + ((AstridOrderedListFragmentHelper) helper).setList(taskListMetadata); + } + helper.beforeSetUpTaskList(filter); + + super.setUpTaskList(); + + unregisterForContextMenu(getListView()); + } + + @Override + public void onPause() { + super.onPause(); + lastVisibleIndex = getListView().getFirstVisiblePosition(); + } + + @Override + public void onResume() { + super.onResume(); + if (lastVisibleIndex >=0) { + getListView().setSelection(lastVisibleIndex); + } + } + + @Override + protected boolean isDraggable() { + return true; + } + + @Override + public void onTaskCreated(Task task) { + super.onTaskCreated(task); + helper.onCreateTask(task); + } + + @Override + protected void onTaskDelete(Task task) { + super.onTaskDelete(task); + helper.onDeleteTask(task); + } + + @Override + protected TaskAdapter createTaskAdapter(TodorooCursor cursor) { + return helper.createTaskAdapter(cursor, sqlQueryTemplate); + } + + @Override + protected void refresh() { + initializeTaskListMetadata(); + setUpTaskList(); + setSyncOngoing(false); + } + +} diff --git a/astrid/src/main/java/org/tasks/injection/FragmentModule.java b/astrid/src/main/java/org/tasks/injection/FragmentModule.java index b6b68a36b..9dba40c59 100644 --- a/astrid/src/main/java/org/tasks/injection/FragmentModule.java +++ b/astrid/src/main/java/org/tasks/injection/FragmentModule.java @@ -12,6 +12,7 @@ import com.todoroo.astrid.core.CustomFilterExposer; import com.todoroo.astrid.gtasks.GtasksFilterExposer; import com.todoroo.astrid.gtasks.GtasksListFragment; import com.todoroo.astrid.reminders.NotificationFragment; +import com.todoroo.astrid.subtasks.SubtasksListFragment; import com.todoroo.astrid.subtasks.SubtasksTagListFragment; import com.todoroo.astrid.tags.TagFilterExposer; import com.todoroo.astrid.timers.TimerFilterExposer; @@ -29,6 +30,7 @@ import dagger.Provides; TaskListFragment.class, GtasksListFragment.class, NotificationFragment.class, + SubtasksListFragment.class, SubtasksTagListFragment.class, TagViewFragment.class, TaskEditFragment.class,