Made all of Tim's suggested edits

pull/14/head
Sam Bosley 12 years ago
parent 4264ca9409
commit a7046e1de3

@ -45,7 +45,7 @@ public abstract class Property<TYPE> 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<TYPE> 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<TYPE> 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);
}

@ -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;
}
}

@ -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(

@ -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<Task> cursor = (TodorooCursor<Task>)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<Long, TaskAction> taskActionLoader = Collections.synchronizedMap(new HashMap<Long, TaskAction>());
@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<TaskAction> actions = linkActionExposer.
getActionsForTask(ContextManager.getContext(), task, hasAttachments);
if (actions.size() > 0)

Loading…
Cancel
Save