Query all task properties in task adapter

pull/618/head
Alex Baker 7 years ago
parent 5496edc6bf
commit 7d9d7bdb07

@ -12,14 +12,15 @@ import android.view.ViewGroup;
import android.widget.CursorAdapter; import android.widget.CursorAdapter;
import android.widget.Filterable; import android.widget.Filterable;
import com.google.common.collect.ObjectArrays;
import com.todoroo.andlib.data.Property; 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.LongProperty;
import com.todoroo.andlib.data.Property.StringProperty; import com.todoroo.andlib.data.Property.StringProperty;
import com.todoroo.andlib.data.TodorooCursor; import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.astrid.activity.TaskListFragment; import com.todoroo.astrid.activity.TaskListFragment;
import com.todoroo.astrid.data.RemoteModel; import com.todoroo.astrid.data.RemoteModel;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
import org.tasks.data.TaskAttachment; import org.tasks.data.TaskAttachment;
import java.util.ArrayList; 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 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 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");
public static final Property<?>[] PROPERTIES = ObjectArrays.concat(
// --- other constants Task.PROPERTIES,
new Property<?>[]{
/** 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 TAGS, // Concatenated list of tags
FILE_ID_PROPERTY // File id FILE_ID_PROPERTY // File id
}; }, Property.class);
// --- instance variables
private OnCompletedTaskListener onCompletedTaskListener = null; private OnCompletedTaskListener onCompletedTaskListener = null;

@ -32,11 +32,13 @@ import java.util.List;
*/ */
public class LinkActionExposer { 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) { if (task == null) {
return null; return null;
} }
boolean hasNotes = task.hasNotes();
Spannable titleSpan = Spannable.Factory.getInstance().newSpannable(task.getTitle()); Spannable titleSpan = Spannable.Factory.getInstance().newSpannable(task.getTitle());
Linkify.addLinks(titleSpan, Linkify.ALL); Linkify.addLinks(titleSpan, Linkify.ALL);

@ -105,7 +105,6 @@ class ViewHolder extends MultiSelectorBindingHolder {
private String tagsString; // From join query, not part of the task model 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 hasFiles; // From join query, not part of the task model
private boolean hasNotes;
private final Context context; private final Context context;
private final CheckBoxes checkBoxes; private final CheckBoxes checkBoxes;
private final TagFormatter tagFormatter; private final TagFormatter tagFormatter;
@ -197,7 +196,6 @@ class ViewHolder extends MultiSelectorBindingHolder {
void bindView(TodorooCursor cursor) { void bindView(TodorooCursor cursor) {
tagsString = cursor.get(TaskAdapter.TAGS); tagsString = cursor.get(TaskAdapter.TAGS);
hasFiles = cursor.get(TaskAdapter.FILE_ID_PROPERTY) > 0; hasFiles = cursor.get(TaskAdapter.FILE_ID_PROPERTY) > 0;
hasNotes = cursor.get(TaskAdapter.HAS_NOTES_PROPERTY) > 0;
// TODO: see if this is a performance issue // TODO: see if this is a performance issue
task = new Task(cursor); task = new Task(cursor);
@ -219,7 +217,7 @@ class ViewHolder extends MultiSelectorBindingHolder {
setupDueDateAndTags(); setupDueDateAndTags();
// Task action // Task action
TaskAction action = getTaskAction(task, hasFiles, hasNotes); TaskAction action = getTaskAction(task, hasFiles);
if (action != null) { if (action != null) {
taskActionIcon.setVisibility(View.VISIBLE); taskActionIcon.setVisibility(View.VISIBLE);
taskActionIcon.setImageResource(action.icon); 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()) { if (task.isCompleted()) {
return null; return null;
} }
return LinkActionExposer.getActionsForTask(context, task, hasFiles, hasNotes); return LinkActionExposer.getActionsForTask(context, task, hasFiles);
} }
private void setTaskAppearance() { private void setTaskAppearance() {

Loading…
Cancel
Save