From 7d9d7bdb07076362ca2bd8e37037d46bb3a9209f Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Thu, 18 Jan 2018 16:22:36 -0600 Subject: [PATCH] Query all task properties in task adapter --- .../todoroo/astrid/adapter/TaskAdapter.java | 35 +++++-------------- .../astrid/core/LinkActionExposer.java | 4 ++- .../java/org/tasks/tasklist/ViewHolder.java | 8 ++--- 3 files changed, 15 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/com/todoroo/astrid/adapter/TaskAdapter.java b/app/src/main/java/com/todoroo/astrid/adapter/TaskAdapter.java index 518867afd..3d4b4391e 100644 --- a/app/src/main/java/com/todoroo/astrid/adapter/TaskAdapter.java +++ b/app/src/main/java/com/todoroo/astrid/adapter/TaskAdapter.java @@ -12,14 +12,15 @@ import android.view.ViewGroup; import android.widget.CursorAdapter; import android.widget.Filterable; +import com.google.common.collect.ObjectArrays; import com.todoroo.andlib.data.Property; -import com.todoroo.andlib.data.Property.IntegerProperty; import com.todoroo.andlib.data.Property.LongProperty; import com.todoroo.andlib.data.Property.StringProperty; import com.todoroo.andlib.data.TodorooCursor; import com.todoroo.astrid.activity.TaskListFragment; import com.todoroo.astrid.data.RemoteModel; import com.todoroo.astrid.data.Task; + import org.tasks.data.TaskAttachment; import java.util.ArrayList; @@ -52,31 +53,13 @@ public class TaskAdapter extends CursorAdapter implements Filterable { public static final StringProperty TAGS = new StringProperty(null, "group_concat(nullif(" + TaskListFragment.TAGS_METADATA_JOIN + ".tag_uid, '')"+ ", ',')").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 - - /** Properties that need to be read from the action item */ - public static final Property[] PROPERTIES = new Property[] { - Task.ID, - Task.UUID, - Task.TITLE, - Task.IMPORTANCE, - Task.DUE_DATE, - Task.COMPLETION_DATE, - Task.MODIFICATION_DATE, - Task.HIDE_UNTIL, - Task.DELETION_DATE, - Task.ELAPSED_SECONDS, - Task.TIMER_START, - Task.RECURRENCE, - Task.REMINDER_LAST, - HAS_NOTES_PROPERTY, // Whether or not the task has notes - TAGS, // Concatenated list of tags - FILE_ID_PROPERTY // File id - }; - - // --- instance variables + + public static final Property[] PROPERTIES = ObjectArrays.concat( + Task.PROPERTIES, + new Property[]{ + TAGS, // Concatenated list of tags + FILE_ID_PROPERTY // File id + }, Property.class); private OnCompletedTaskListener onCompletedTaskListener = null; diff --git a/app/src/main/java/com/todoroo/astrid/core/LinkActionExposer.java b/app/src/main/java/com/todoroo/astrid/core/LinkActionExposer.java index 2e732d1fd..5f2e428c9 100644 --- a/app/src/main/java/com/todoroo/astrid/core/LinkActionExposer.java +++ b/app/src/main/java/com/todoroo/astrid/core/LinkActionExposer.java @@ -32,11 +32,13 @@ import java.util.List; */ public class LinkActionExposer { - public static TaskAction getActionsForTask(Context context, Task task, boolean hasAttachments, boolean hasNotes) { + public static TaskAction getActionsForTask(Context context, Task task, boolean hasAttachments) { if (task == null) { return null; } + boolean hasNotes = task.hasNotes(); + Spannable titleSpan = Spannable.Factory.getInstance().newSpannable(task.getTitle()); Linkify.addLinks(titleSpan, Linkify.ALL); diff --git a/app/src/main/java/org/tasks/tasklist/ViewHolder.java b/app/src/main/java/org/tasks/tasklist/ViewHolder.java index 707d66909..7ee987bdf 100644 --- a/app/src/main/java/org/tasks/tasklist/ViewHolder.java +++ b/app/src/main/java/org/tasks/tasklist/ViewHolder.java @@ -105,7 +105,6 @@ class ViewHolder extends MultiSelectorBindingHolder { private String tagsString; // From join query, not part of the task model private boolean hasFiles; // From join query, not part of the task model - private boolean hasNotes; private final Context context; private final CheckBoxes checkBoxes; private final TagFormatter tagFormatter; @@ -197,7 +196,6 @@ class ViewHolder extends MultiSelectorBindingHolder { 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); @@ -219,7 +217,7 @@ class ViewHolder extends MultiSelectorBindingHolder { setupDueDateAndTags(); // Task action - TaskAction action = getTaskAction(task, hasFiles, hasNotes); + TaskAction action = getTaskAction(task, hasFiles); if (action != null) { taskActionIcon.setVisibility(View.VISIBLE); taskActionIcon.setImageResource(action.icon); @@ -230,11 +228,11 @@ class ViewHolder extends MultiSelectorBindingHolder { } } - private TaskAction getTaskAction(Task task, boolean hasFiles, boolean hasNotes) { + private TaskAction getTaskAction(Task task, boolean hasFiles) { if (task.isCompleted()) { return null; } - return LinkActionExposer.getActionsForTask(context, task, hasFiles, hasNotes); + return LinkActionExposer.getActionsForTask(context, task, hasFiles); } private void setTaskAppearance() {