Remove OrderedListFragmentHelperInterface

pull/467/head
Alex Baker 8 years ago
parent daf70f0354
commit 698574e3b0

@ -5,11 +5,16 @@
*/
package com.todoroo.astrid.gtasks;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.ListView;
import com.todoroo.andlib.data.Property;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.astrid.activity.TaskListFragment;
import com.todoroo.astrid.adapter.TaskAdapter;
import com.todoroo.astrid.api.GtasksFilter;
@ -19,15 +24,15 @@ import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.data.StoreObject;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.service.SyncV2Service;
import com.todoroo.astrid.subtasks.OrderedListFragmentHelperInterface;
import com.todoroo.astrid.subtasks.SubtasksListFragment;
import com.todoroo.astrid.sync.SyncResultCallback;
import com.todoroo.astrid.tags.TagService;
import org.tasks.Broadcaster;
import org.tasks.R;
import org.tasks.dialogs.DialogBuilder;
import org.tasks.injection.ForApplication;
import org.tasks.injection.FragmentComponent;
import org.tasks.preferences.Preferences;
import org.tasks.themes.Theme;
import org.tasks.themes.ThemeCache;
import org.tasks.ui.CheckBoxes;
@ -36,7 +41,7 @@ import java.util.Arrays;
import javax.inject.Inject;
public class GtasksListFragment extends SubtasksListFragment {
public class GtasksListFragment extends TaskListFragment {
public static TaskListFragment newGtasksListFragment(GtasksFilter filter, GtasksList list) {
GtasksListFragment fragment = new GtasksListFragment();
@ -50,23 +55,19 @@ public class GtasksListFragment extends SubtasksListFragment {
@Inject TaskDao taskDao;
@Inject MetadataDao metadataDao;
@Inject GtasksTaskListUpdater gtasksTaskListUpdater;
@Inject GtasksPreferenceService gtasksPreferenceService;
@Inject SyncV2Service syncService;
@Inject TaskAttachmentDao taskAttachmentDao;
@Inject Preferences preferences;
@Inject DialogBuilder dialogBuilder;
@Inject Broadcaster broadcaster;
@Inject CheckBoxes checkBoxes;
@Inject TagService tagService;
@Inject ThemeCache themeCache;
@Inject @ForApplication Context context;
@Inject Theme theme;
private GtasksList list;
@Override
protected OrderedListFragmentHelperInterface createFragmentHelper() {
return new OrderedMetadataListFragmentHelper<>(preferences, taskAttachmentDao, taskDao,
metadataDao, this, gtasksTaskListUpdater, dialogBuilder, checkBoxes, tagService, themeCache);
}
protected OrderedMetadataListFragmentHelper<GtasksList> helper;
private int lastVisibleIndex = -1;
@Override
public void onCreate(Bundle savedInstanceState) {
@ -77,7 +78,7 @@ public class GtasksListFragment extends SubtasksListFragment {
list = new GtasksList(storeObject);
}
((OrderedMetadataListFragmentHelper<GtasksList>)helper).setList(list);
helper.setList(list);
}
@Override
@ -94,6 +95,7 @@ public class GtasksListFragment extends SubtasksListFragment {
@Override
protected void onTaskDelete(Task task) {
super.onTaskDelete(task);
helper.onDeleteTask(task);
}
@ -132,4 +134,62 @@ public class GtasksListFragment extends SubtasksListFragment {
properties.add(gtasksTaskListUpdater.orderProperty());
return properties.toArray(new Property<?>[properties.size()]);
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
helper = new OrderedMetadataListFragmentHelper<>(preferences, taskAttachmentDao, taskDao,
metadataDao, this, gtasksTaskListUpdater, dialogBuilder, checkBoxes, tagService, themeCache);
}
@Override
protected int getListBody() {
return R.layout.task_list_body_subtasks;
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
helper.setUpUiComponents();
}
@Override
public void setTaskAdapter() {
helper.beforeSetUpTaskList(filter);
super.setTaskAdapter();
}
@Override
public void onPause() {
super.onPause();
lastVisibleIndex = getListView().getFirstVisiblePosition();
}
@Override
public void onResume() {
super.onResume();
ListView listView = getListView();
if (lastVisibleIndex >= 0) {
listView.setSelection(lastVisibleIndex);
}
unregisterForContextMenu(listView);
}
@Override
public void onTaskCreated(String uuid) {
helper.onCreateTask(uuid);
}
@Override
protected TaskAdapter createTaskAdapter(TodorooCursor<Task> cursor) {
return helper.createTaskAdapter(theme.wrap(context), cursor, taskListDataProvider.getSqlQueryTemplate());
}
@Override
public void inject(FragmentComponent component) {
component.inject(this);
}
}

@ -27,7 +27,6 @@ import com.todoroo.astrid.dao.TaskAttachmentDao;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.subtasks.OrderedListFragmentHelperInterface;
import com.todoroo.astrid.tags.TagService;
import com.todoroo.astrid.ui.DraggableListView;
@ -45,7 +44,7 @@ import java.util.concurrent.atomic.AtomicReference;
import timber.log.Timber;
public class OrderedMetadataListFragmentHelper<LIST> implements OrderedListFragmentHelperInterface {
public class OrderedMetadataListFragmentHelper<LIST> {
private final DisplayMetrics metrics = new DisplayMetrics();
private final OrderedMetadataListUpdater<LIST> updater;
@ -95,7 +94,6 @@ public class OrderedMetadataListFragmentHelper<LIST> implements OrderedListFragm
return (DraggableListView) fragment.getListView();
}
@Override
public void setUpUiComponents() {
TypedValue tv = new TypedValue();
getActivity().getTheme().resolveAttribute(R.attr.colorAccent, tv, false);
@ -106,7 +104,6 @@ public class OrderedMetadataListFragmentHelper<LIST> implements OrderedListFragm
getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
}
@Override
public void beforeSetUpTaskList(Filter filter) {
}
@ -179,7 +176,6 @@ public class OrderedMetadataListFragmentHelper<LIST> implements OrderedListFragm
}
};
@Override
public TaskAdapter createTaskAdapter(Context context, TodorooCursor<Task> cursor,
AtomicReference<String> sqlQueryTemplate) {
@ -261,15 +257,12 @@ public class OrderedMetadataListFragmentHelper<LIST> implements OrderedListFragm
this.list = list;
}
@Override
public void onCreateTask(String uuid) {
//
}
@Override
public void onDeleteTask(Task task) {
updater.onDeleteTask(list, task.getId());
taskAdapter.notifyDataSetInvalidated();
}
}

@ -267,7 +267,7 @@ public class TaskListFragment extends InjectingListFragment implements
completed.setEnabled(false);
}
if (this instanceof SubtasksTagListFragment || this instanceof SubtasksListFragment) {
if (this instanceof SubtasksTagListFragment || this instanceof SubtasksListFragment || this instanceof GtasksListFragment) {
hidden.setChecked(true);
hidden.setEnabled(false);
}
@ -412,7 +412,7 @@ public class TaskListFragment extends InjectingListFragment implements
listView.setItemsCanFocus(false);
}
if ((this instanceof SubtasksListFragment) || (this instanceof SubtasksTagListFragment)) {
if (this instanceof SubtasksListFragment || this instanceof SubtasksTagListFragment || this instanceof GtasksListFragment) {
return;
}

@ -41,7 +41,7 @@ import java.util.concurrent.atomic.AtomicReference;
import timber.log.Timber;
public class AstridOrderedListFragmentHelper<LIST> implements OrderedListFragmentHelperInterface {
public class AstridOrderedListFragmentHelper<LIST> {
private final DisplayMetrics metrics = new DisplayMetrics();
private final AstridOrderedListUpdater<LIST> updater;
@ -87,7 +87,6 @@ public class AstridOrderedListFragmentHelper<LIST> implements OrderedListFragmen
return fragment.getFilter();
}
@Override
public void setUpUiComponents() {
TypedValue tv = new TypedValue();
getActivity().getTheme().resolveAttribute(R.attr.colorAccent, tv, false);
@ -101,7 +100,6 @@ public class AstridOrderedListFragmentHelper<LIST> implements OrderedListFragmen
draggableListView.setItemHightNormal(taskAdapter.computeFullRowHeight());
}
@Override
public void beforeSetUpTaskList(Filter filter) {
updater.initialize(list, filter);
}
@ -178,7 +176,6 @@ public class AstridOrderedListFragmentHelper<LIST> implements OrderedListFragmen
}
};
@Override
public TaskAdapter createTaskAdapter(Context context, TodorooCursor<Task> cursor,
AtomicReference<String> sqlQueryTemplate) {
@ -270,14 +267,12 @@ public class AstridOrderedListFragmentHelper<LIST> implements OrderedListFragmen
this.list = list;
}
@Override
public void onCreateTask(String uuid) {
updater.onCreateTask(list, getFilter(), uuid);
fragment.reconstructCursor();
fragment.loadTaskListContent();
}
@Override
public void onDeleteTask(Task task) {
updater.onDeleteTask(list, getFilter(), task.getUuid());
taskAdapter.notifyDataSetInvalidated();

@ -1,20 +0,0 @@
package com.todoroo.astrid.subtasks;
import android.content.Context;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.astrid.adapter.TaskAdapter;
import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.data.Task;
import java.util.concurrent.atomic.AtomicReference;
public interface OrderedListFragmentHelperInterface {
void setUpUiComponents();
void beforeSetUpTaskList(Filter filter);
void onCreateTask(String uuid);
void onDeleteTask(Task task);
TaskAdapter createTaskAdapter(Context context, TodorooCursor<Task> cursor, AtomicReference<String> queryTemplate);
}

@ -22,7 +22,6 @@ import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.dao.TaskListMetadataDao;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.TaskListMetadata;
import com.todoroo.astrid.gtasks.GtasksListFragment;
import com.todoroo.astrid.tags.TagService;
import org.tasks.R;
@ -50,7 +49,7 @@ public class SubtasksListFragment extends TaskListFragment {
return fragment;
}
protected OrderedListFragmentHelperInterface helper;
protected AstridOrderedListFragmentHelper<TaskListMetadata> helper;
private int lastVisibleIndex = -1;
@ -70,11 +69,7 @@ public class SubtasksListFragment extends TaskListFragment {
public void onAttach(Activity activity) {
super.onAttach(activity);
helper = createFragmentHelper();
}
protected OrderedListFragmentHelperInterface createFragmentHelper() {
return new AstridOrderedListFragmentHelper<>(preferences, taskAttachmentDao,
helper = new AstridOrderedListFragmentHelper<>(preferences, taskAttachmentDao,
this, subtasksFilterUpdater, dialogBuilder, checkBoxes, tagService, themeCache, taskDao);
}
@ -92,9 +87,7 @@ public class SubtasksListFragment extends TaskListFragment {
@Override
public void setTaskAdapter() {
if (helper instanceof AstridOrderedListFragmentHelper) {
((AstridOrderedListFragmentHelper<TaskListMetadata>) helper).setList(initializeTaskListMetadata());
}
helper.setList(initializeTaskListMetadata());
helper.beforeSetUpTaskList(filter);
super.setTaskAdapter();
@ -162,10 +155,6 @@ public class SubtasksListFragment extends TaskListFragment {
@Override
public void inject(FragmentComponent component) {
if (this instanceof GtasksListFragment) {
component.inject((GtasksListFragment) this);
} else {
component.inject(this);
}
}
}

Loading…
Cancel
Save