Implement join with the users table for showing user images in the task adapter

pull/14/head
Sam Bosley 12 years ago
parent baa05dfb46
commit c45d70021b

@ -13,6 +13,7 @@ import android.text.TextUtils;
import com.todoroo.andlib.data.AbstractModel;
import com.todoroo.andlib.data.Property.LongProperty;
import com.todoroo.andlib.data.Property.StringProperty;
import com.todoroo.andlib.data.TodorooCursor;
/**
* A model that is synchronized to a remote server and has a remote id
@ -88,4 +89,14 @@ abstract public class RemoteModel extends AbstractModel {
return value;
}
}
public static String getPictureUrlFromCursor(TodorooCursor<?> cursor, StringProperty pictureProperty, String size) {
String value = cursor.get(pictureProperty);
try {
JSONObject pictureJson = new JSONObject(value);
return pictureJson.optString(size);
} catch (JSONException e) {
return value;
}
}
}

@ -86,6 +86,7 @@ import com.todoroo.astrid.dao.Database;
import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.User;
import com.todoroo.astrid.helper.SyncActionHelper;
import com.todoroo.astrid.helper.TaskListContextMenuExtensionLoader;
import com.todoroo.astrid.helper.TaskListContextMenuExtensionLoader.ContextMenuItem;
@ -101,8 +102,8 @@ import com.todoroo.astrid.service.ThemeService;
import com.todoroo.astrid.service.UpgradeService;
import com.todoroo.astrid.subtasks.SubtasksListFragment;
import com.todoroo.astrid.sync.SyncProviderPreferences;
import com.todoroo.astrid.tags.TaskToTagMetadata;
import com.todoroo.astrid.tags.TagService;
import com.todoroo.astrid.tags.TaskToTagMetadata;
import com.todoroo.astrid.taskrabbit.TaskRabbitMetadata;
import com.todoroo.astrid.timers.TimerPlugin;
import com.todoroo.astrid.ui.QuickAddBar;
@ -910,6 +911,8 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
public static final String TAGS_METADATA_JOIN = "for_tags"; //$NON-NLS-1$
public static final String USER_IMAGE_JOIN = "for_images"; // //$NON-NLS-1$
/**
* Fill in the Task List with current items
*
@ -969,6 +972,7 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
Task.ID.eq(Field.field(TR_METADATA_JOIN + "." + Metadata.TASK.name)))).toString() //$NON-NLS-1$
+ Join.left(Metadata.TABLE.as(TAGS_METADATA_JOIN),
tagsJoinCriterion).toString() //$NON-NLS-1$
+ Join.left(User.TABLE.as(USER_IMAGE_JOIN), Task.USER_ID.eq(User.UUID)).toString()
+ filter.getSqlQuery();
sqlQueryTemplate.set(SortHelper.adjustQueryForFlagsAndSort(

@ -80,7 +80,9 @@ import com.todoroo.astrid.api.TaskDecoration;
import com.todoroo.astrid.api.TaskDecorationExposer;
import com.todoroo.astrid.core.LinkActionExposer;
import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.RemoteModel;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.User;
import com.todoroo.astrid.files.FileMetadata;
import com.todoroo.astrid.files.FilesAction;
import com.todoroo.astrid.files.FilesControlSet;
@ -140,6 +142,7 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
Task.USER,
Task.REMINDER_LAST,
Task.SOCIAL_REMINDER,
User.PICTURE,
TASK_RABBIT_ID, // Task rabbit metadata id (non-zero means it exists)
TAGS // Concatenated list of tags
};
@ -390,6 +393,7 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
if (!titleOnlyLayout) {
viewHolder.isTaskRabbit = (cursor.get(TASK_RABBIT_ID) > 0);
viewHolder.tagsString = cursor.get(TAGS);
viewHolder.imageUrl = RemoteModel.getPictureUrlFromCursor(cursor, User.PICTURE, RemoteModel.PICTURE_THUMB);
}
Task task = viewHolder.task;
@ -422,6 +426,7 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
public ImageView taskActionIcon;
public boolean isTaskRabbit; // From join query, not part of the task model
public String tagsString; // From join query, not part of the task model
public String imageUrl; // From join query, not part of the task model
public View[] decorations;
}
@ -1145,12 +1150,14 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
pictureView.setDefaultImageResource(R.drawable.icn_anyone_transparent);
else {
pictureView.setDefaultImageResource(R.drawable.icn_default_person_image);
try {
JSONObject user = new JSONObject(task.getValue(Task.USER));
pictureView.setUrl(user.optString("picture")); //$NON-NLS-1$
} catch (JSONException e) {
if (Task.isRealUserId(task.getValue(Task.USER_ID))) {
// TODO: Implement a join here
if (!TextUtils.isEmpty(viewHolder.imageUrl)) {
pictureView.setUrl(viewHolder.imageUrl);
} else if (!TextUtils.isEmpty(task.getValue(Task.USER))) {
try {
JSONObject user = new JSONObject(task.getValue(Task.USER));
pictureView.setUrl(user.optString("picture")); //$NON-NLS-1$
} catch (JSONException e) {
//
}
}
}

Loading…
Cancel
Save