diff --git a/src/googleplay/java/com/todoroo/astrid/gtasks/OrderedMetadataListFragmentHelper.java b/src/googleplay/java/com/todoroo/astrid/gtasks/OrderedMetadataListFragmentHelper.java index 89855a949..67d417af5 100644 --- a/src/googleplay/java/com/todoroo/astrid/gtasks/OrderedMetadataListFragmentHelper.java +++ b/src/googleplay/java/com/todoroo/astrid/gtasks/OrderedMetadataListFragmentHelper.java @@ -33,6 +33,7 @@ import com.todoroo.astrid.ui.DraggableListView.SwipeListener; import org.tasks.R; import org.tasks.dialogs.DialogBuilder; import org.tasks.preferences.Preferences; +import org.tasks.tasklist.ViewHolder; import org.tasks.themes.ThemeCache; import org.tasks.ui.CheckBoxes; diff --git a/src/main/java/com/todoroo/astrid/activity/TaskListFragment.java b/src/main/java/com/todoroo/astrid/activity/TaskListFragment.java index ae3f55f94..779ecf3a9 100644 --- a/src/main/java/com/todoroo/astrid/activity/TaskListFragment.java +++ b/src/main/java/com/todoroo/astrid/activity/TaskListFragment.java @@ -35,7 +35,6 @@ import com.todoroo.andlib.sql.Criterion; import com.todoroo.andlib.sql.QueryTemplate; import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.astrid.adapter.TaskAdapter; -import com.todoroo.astrid.adapter.TaskAdapter.ViewHolder; import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.api.CustomFilter; import com.todoroo.astrid.api.Filter; @@ -66,6 +65,7 @@ import org.tasks.injection.FragmentComponent; import org.tasks.injection.InjectingListFragment; import org.tasks.notifications.NotificationManager; import org.tasks.preferences.Preferences; +import org.tasks.tasklist.ViewHolder; import org.tasks.themes.ThemeCache; import org.tasks.ui.CheckBoxes; import org.tasks.ui.MenuColorizer; diff --git a/src/main/java/com/todoroo/astrid/adapter/TaskAdapter.java b/src/main/java/com/todoroo/astrid/adapter/TaskAdapter.java index e3538bf26..c2adc0bc1 100644 --- a/src/main/java/com/todoroo/astrid/adapter/TaskAdapter.java +++ b/src/main/java/com/todoroo/astrid/adapter/TaskAdapter.java @@ -63,6 +63,7 @@ import com.todoroo.astrid.ui.CheckableImageView; import org.tasks.R; import org.tasks.dialogs.DialogBuilder; import org.tasks.preferences.Preferences; +import org.tasks.tasklist.ViewHolder; import org.tasks.themes.ThemeCache; import org.tasks.themes.ThemeColor; import org.tasks.ui.CheckBoxes; @@ -94,9 +95,9 @@ public class TaskAdapter extends CursorAdapter implements Filterable { private static final char SPACE = '\u0020'; private static final char HAIR_SPACE = '\u200a'; - private static final StringProperty TAGS = new StringProperty(null, "group_concat(nullif(" + TaskListFragment.TAGS_METADATA_JOIN + "." + TaskToTagMetadata.TAG_UUID.name + ", '')"+ ", ',')").as("tags"); - private static final LongProperty FILE_ID_PROPERTY = TaskAttachment.ID.cloneAs(TaskListFragment.FILE_METADATA_JOIN, "fileId"); - private static final IntegerProperty HAS_NOTES_PROPERTY = new IntegerProperty(null, "length(" + Task.NOTES + ") > 0").as("hasNotes"); + public static final StringProperty TAGS = new StringProperty(null, "group_concat(nullif(" + TaskListFragment.TAGS_METADATA_JOIN + "." + TaskToTagMetadata.TAG_UUID.name + ", '')"+ ", ',')").as("tags"); + public static final LongProperty FILE_ID_PROPERTY = TaskAttachment.ID.cloneAs(TaskListFragment.FILE_METADATA_JOIN, "fileId"); + public static final IntegerProperty HAS_NOTES_PROPERTY = new IntegerProperty(null, "length(" + Task.NOTES + ") > 0").as("hasNotes"); // --- other constants @@ -257,30 +258,10 @@ public class TaskAdapter extends CursorAdapter implements Filterable { @Override public View newView(Context context, Cursor cursor, ViewGroup parent) { ViewGroup view = (ViewGroup)inflater.inflate(R.layout.task_adapter_row_simple, parent, false); - - // create view holder - ViewHolder viewHolder = new ViewHolder(); - viewHolder.task = new Task(); - viewHolder.rowBody = (ViewGroup)view.findViewById(R.id.rowBody); - viewHolder.nameView = (TextView)view.findViewById(R.id.title); - viewHolder.completeBox = (CheckableImageView)view.findViewById(R.id.completeBox); - viewHolder.dueDate = (TextView)view.findViewById(R.id.due_date); - viewHolder.tagBlock = (TextView) view.findViewById(R.id.tag_block); - viewHolder.taskActionContainer = view.findViewById(R.id.taskActionContainer); - viewHolder.taskActionIcon = (ImageView)view.findViewById(R.id.taskActionIcon); - boolean showFullTaskTitle = preferences.getBoolean(R.string.p_fullTaskTitle, false); - if (showFullTaskTitle) { - viewHolder.nameView.setMaxLines(Integer.MAX_VALUE); - viewHolder.nameView.setSingleLine(false); - viewHolder.nameView.setEllipsize(null); - } - - view.setTag(viewHolder); - for(int i = 0; i < view.getChildCount(); i++) { - view.getChildAt(i).setTag(viewHolder); - } + // create view holder + new ViewHolder(view, showFullTaskTitle); // add UI component listeners addListeners(view); @@ -293,13 +274,7 @@ public class TaskAdapter extends CursorAdapter implements Filterable { public void bindView(View view, Context context, Cursor c) { TodorooCursor cursor = (TodorooCursor)c; ViewHolder viewHolder = ((ViewHolder)view.getTag()); - - viewHolder.tagsString = cursor.get(TAGS); - viewHolder.hasFiles = cursor.get(FILE_ID_PROPERTY) > 0; - viewHolder.hasNotes = cursor.get(HAS_NOTES_PROPERTY) > 0; - - // TODO: see if this is a performance issue - viewHolder.task = new Task(cursor); + viewHolder.bindView(cursor); setFieldContentsAndVisibility(view); setTaskAppearance(viewHolder, viewHolder.task); @@ -318,26 +293,6 @@ public class TaskAdapter extends CursorAdapter implements Filterable { } } - /** - * View Holder saves a lot of findViewById lookups. - * - * @author Tim Su - * - */ - public static class ViewHolder { - public Task task; - public ViewGroup rowBody; - public TextView nameView; - public CheckableImageView completeBox; - public TextView dueDate; - public TextView tagBlock; - public View taskActionContainer; - public ImageView taskActionIcon; - public String tagsString; // From join query, not part of the task model - public boolean hasFiles; // From join query, not part of the task model - public boolean hasNotes; - } - /** Helper method to set the contents and visibility of each field */ public synchronized void setFieldContentsAndVisibility(View view) { ViewHolder viewHolder = (ViewHolder)view.getTag(); diff --git a/src/main/java/com/todoroo/astrid/subtasks/AstridOrderedListFragmentHelper.java b/src/main/java/com/todoroo/astrid/subtasks/AstridOrderedListFragmentHelper.java index 424d0a704..a5e697b3a 100644 --- a/src/main/java/com/todoroo/astrid/subtasks/AstridOrderedListFragmentHelper.java +++ b/src/main/java/com/todoroo/astrid/subtasks/AstridOrderedListFragmentHelper.java @@ -31,6 +31,7 @@ import com.todoroo.astrid.ui.DraggableListView.SwipeListener; import org.tasks.R; import org.tasks.dialogs.DialogBuilder; import org.tasks.preferences.Preferences; +import org.tasks.tasklist.ViewHolder; import org.tasks.themes.ThemeCache; import org.tasks.ui.CheckBoxes; diff --git a/src/main/java/org/tasks/tasklist/ViewHolder.java b/src/main/java/org/tasks/tasklist/ViewHolder.java new file mode 100644 index 000000000..0b8401a98 --- /dev/null +++ b/src/main/java/org/tasks/tasklist/ViewHolder.java @@ -0,0 +1,62 @@ +package org.tasks.tasklist; + +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.TextView; + +import com.todoroo.andlib.data.TodorooCursor; +import com.todoroo.astrid.adapter.TaskAdapter; +import com.todoroo.astrid.data.Task; +import com.todoroo.astrid.ui.CheckableImageView; + +import org.tasks.R; + +import butterknife.BindView; +import butterknife.ButterKnife; + +/** + * View Holder saves a lot of findViewById lookups. + * + * @author Tim Su + */ +public class ViewHolder { + public Task task; + @BindView(R.id.rowBody) public ViewGroup rowBody; + @BindView(R.id.title) public TextView nameView; + @BindView(R.id.completeBox) public CheckableImageView completeBox; + @BindView(R.id.due_date) public TextView dueDate; + @BindView(R.id.tag_block) public TextView tagBlock; + @BindView(R.id.taskActionContainer) public View taskActionContainer; + @BindView(R.id.taskActionIcon) public ImageView taskActionIcon; + + public String tagsString; // From join query, not part of the task model + public boolean hasFiles; // From join query, not part of the task model + public boolean hasNotes; + + public ViewHolder(ViewGroup view, boolean showFullTaskTitle) { + ButterKnife.bind(this, view); + + task = new Task(); + + if (showFullTaskTitle) { + nameView.setMaxLines(Integer.MAX_VALUE); + nameView.setSingleLine(false); + nameView.setEllipsize(null); + } + + view.setTag(this); + for(int i = 0; i < view.getChildCount(); i++) { + view.getChildAt(i).setTag(this); + } + } + + public void bindView(TodorooCursor cursor) { + tagsString = cursor.get(TaskAdapter.TAGS); + hasFiles = cursor.get(TaskAdapter.FILE_ID_PROPERTY) > 0; + hasNotes = cursor.get(TaskAdapter.HAS_NOTES_PROPERTY) > 0; + + // TODO: see if this is a performance issue + task = new Task(cursor); + } +}