From a7046e1de30d73c90b3d3cfe9aed05827bbe8f08 Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Mon, 27 Aug 2012 19:46:02 -0700 Subject: [PATCH] Made all of Tim's suggested edits --- api/src/com/todoroo/andlib/data/Property.java | 6 +++--- api/src/com/todoroo/andlib/data/Table.java | 6 ++++++ .../astrid/activity/TaskListFragment.java | 7 ++++++- .../todoroo/astrid/adapter/TaskAdapter.java | 18 ++++++++++-------- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/api/src/com/todoroo/andlib/data/Property.java b/api/src/com/todoroo/andlib/data/Property.java index b516f6ac9..e3c892d5f 100644 --- a/api/src/com/todoroo/andlib/data/Property.java +++ b/api/src/com/todoroo/andlib/data/Property.java @@ -45,7 +45,7 @@ public abstract class Property extends Field implements Cloneable { * expression which is derived from default table name */ protected Property(Table table, String columnName) { - this(table, columnName, (table == null) ? (columnName) : (table.name + "." + columnName)); + this(table, columnName, (table == null) ? (columnName) : (table.name() + "." + columnName)); } /** @@ -53,7 +53,7 @@ public abstract class Property extends Field implements Cloneable { * expression which is derived from default table name */ protected Property(Table table, String columnName, boolean nullable) { - this(table, columnName, (table == null) ? (columnName) : (table.name + "." + columnName)); + this(table, columnName, (table == null) ? (columnName) : (table.name() + "." + columnName)); this.nullable = nullable; } @@ -218,7 +218,7 @@ public abstract class Property extends Field implements Cloneable { super(table, name, nullable); } - public LongProperty(Table table, String name, String expression) { + protected LongProperty(Table table, String name, String expression) { super(table, name, expression); } diff --git a/api/src/com/todoroo/andlib/data/Table.java b/api/src/com/todoroo/andlib/data/Table.java index 5527e2d8c..29da2cf77 100644 --- a/api/src/com/todoroo/andlib/data/Table.java +++ b/api/src/com/todoroo/andlib/data/Table.java @@ -77,4 +77,10 @@ public final class Table extends SqlTable { return expression + " AS " + alias; //$NON-NLS-1$ return expression; } + + public String name() { + if(hasAlias()) + return alias; + return name; + } } \ No newline at end of file diff --git a/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java b/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java index 173267fc9..78eb1fe97 100644 --- a/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java +++ b/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java @@ -60,6 +60,7 @@ import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.andlib.service.ExceptionService; import com.todoroo.andlib.sql.Criterion; +import com.todoroo.andlib.sql.Field; import com.todoroo.andlib.sql.Join; import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.andlib.utility.Preferences; @@ -881,6 +882,8 @@ public class TaskListFragment extends ListFragment implements OnScrollListener, }); } + public static final String TR_METADATA_JOIN = "for_taskrab"; //$NON-NLS-1$ + /** * Fill in the Task List with current items * @@ -893,7 +896,9 @@ public class TaskListFragment extends ListFragment implements OnScrollListener, // TODO: For now, we'll modify the query to join and include the task rabbit data here. // Eventually, we might consider restructuring things so that this query is constructed elsewhere. - String joinedTaskRabbitQuery = Join.left(Metadata.TABLE, Criterion.and(Metadata.KEY.eq(TaskRabbitMetadata.METADATA_KEY), Task.ID.eq(Metadata.TASK))) + String joinedTaskRabbitQuery = Join.left(Metadata.TABLE.as(TR_METADATA_JOIN), + Criterion.and(Field.field(TR_METADATA_JOIN + "." + Metadata.KEY.name).eq(TaskRabbitMetadata.METADATA_KEY), //$NON-NLS-1$ + Task.ID.eq(Field.field(TR_METADATA_JOIN) + "." + Metadata.TASK.name))) //$NON-NLS-1$ + filter.getSqlQuery(); sqlQueryTemplate.set(SortHelper.adjustQueryForFlagsAndSort( diff --git a/astrid/src/com/todoroo/astrid/adapter/TaskAdapter.java b/astrid/src/com/todoroo/astrid/adapter/TaskAdapter.java index ad965ccd5..ae3c2c7ad 100644 --- a/astrid/src/com/todoroo/astrid/adapter/TaskAdapter.java +++ b/astrid/src/com/todoroo/astrid/adapter/TaskAdapter.java @@ -109,7 +109,8 @@ public class TaskAdapter extends CursorAdapter implements Filterable { public static final String BROADCAST_EXTRA_TASK = "model"; //$NON-NLS-1$ - private static final String TASK_RABBIT_COL = "taskRabbitMd"; + private static final LongProperty TASK_RABBIT_ID = new LongProperty(Metadata.TABLE.as(TaskListFragment.TR_METADATA_JOIN), + Metadata.ID.name); // --- other constants @@ -131,7 +132,7 @@ public class TaskAdapter extends CursorAdapter implements Filterable { Task.NOTES, Task.USER_ID, Task.USER, - (LongProperty) Metadata.ID.as(TASK_RABBIT_COL) // Task rabbit metadata id (non-zero means it exists + TASK_RABBIT_ID // Task rabbit metadata id (non-zero means it exists) }; public static int[] IMPORTANCE_RESOURCES = new int[] { @@ -331,8 +332,7 @@ public class TaskAdapter extends CursorAdapter implements Filterable { TodorooCursor cursor = (TodorooCursor)c; ViewHolder viewHolder = ((ViewHolder)view.getTag()); - int taskRabbitIndex = cursor.getColumnIndex(TASK_RABBIT_COL); - viewHolder.isTaskRabbit = (taskRabbitIndex >= 0 && c.getLong(taskRabbitIndex) > 0); + viewHolder.isTaskRabbit = (cursor.get(TASK_RABBIT_ID) > 0); Task task = viewHolder.task; task.clear(); @@ -439,7 +439,7 @@ public class TaskAdapter extends CursorAdapter implements Filterable { // image view final AsyncImageView pictureView = viewHolder.picture; { if (pictureView != null) { - if(task.getValue(Task.USER_ID) == Task.USER_ID_SELF /*&& !container.isTaskRabbit()*/) { + if(task.getValue(Task.USER_ID) == Task.USER_ID_SELF && !viewHolder.isTaskRabbit) { pictureView.setVisibility(View.GONE); if (viewHolder.pictureBorder != null) viewHolder.pictureBorder.setVisibility(View.GONE); @@ -784,11 +784,14 @@ public class TaskAdapter extends CursorAdapter implements Filterable { private final Map taskActionLoader = Collections.synchronizedMap(new HashMap()); + @SuppressWarnings("nls") public class ActionsLoaderThread extends Thread { public static final String FILE_COLUMN = "fileId"; private static final String METADATA_JOIN = "for_actions"; + private final LongProperty fileIdProperty = new LongProperty(Metadata.TABLE.as(METADATA_JOIN), Metadata.ID.name); + @Override public void run() { AndroidUtilities.sleepDeep(500L); @@ -799,7 +802,7 @@ public class TaskAdapter extends CursorAdapter implements Filterable { groupedQuery = query.get() + " GROUP BY " + Task.ID; Query q = Query.select(Task.ID, Task.TITLE, Task.NOTES, Task.COMPLETION_DATE, - new LongProperty(Metadata.TABLE, Metadata.ID.name, METADATA_JOIN + "." + Metadata.ID.name).as(FILE_COLUMN)) + fileIdProperty.as(FILE_COLUMN)) .join(Join.left(Metadata.TABLE.as(METADATA_JOIN), Criterion.and(Field.field(METADATA_JOIN + "." + Metadata.KEY.name).eq(FileMetadata.METADATA_KEY), Task.ID.eq(Field.field(METADATA_JOIN + "." + Metadata.TASK.name))))).withQueryTemplate(groupedQuery); @@ -809,14 +812,13 @@ public class TaskAdapter extends CursorAdapter implements Filterable { Task task = new Task(); LinkActionExposer linkActionExposer = new LinkActionExposer(); - int filesIndex = fetchCursor.getColumnIndex(FILE_COLUMN); for(fetchCursor.moveToFirst(); !fetchCursor.isAfterLast(); fetchCursor.moveToNext()) { task.clear(); task.readFromCursor(fetchCursor); if(task.isCompleted()) continue; - boolean hasAttachments = (filesIndex > 0 && fetchCursor.getLong(filesIndex) > 0); + boolean hasAttachments = (fetchCursor.get(fileIdProperty) > 0); List actions = linkActionExposer. getActionsForTask(ContextManager.getContext(), task, hasAttachments); if (actions.size() > 0)