Construct members gallery using users join query

pull/14/head
Sam Bosley 12 years ago
parent 1dd8346954
commit b1d255c8d7

@ -66,7 +66,7 @@ public final class TagData extends RemoteModel {
TABLE, "picture");
/** Tag team array (JSON) */
public static final StringProperty MEMBERS = new StringProperty(
@Deprecated public static final StringProperty MEMBERS = new StringProperty(
TABLE, "members");
/** Tag member count */
@ -150,13 +150,13 @@ public final class TagData extends RemoteModel {
static {
defaultValues.put(USER_ID.name, "0");
defaultValues.put(USER.name, "{}");
defaultValues.put(USER.name, "");
defaultValues.put(REMOTE_ID.name, 0);
defaultValues.put(UUID.name, NO_UUID);
defaultValues.put(NAME.name, "");
defaultValues.put(PICTURE.name, "");
defaultValues.put(IS_TEAM.name, 1);
defaultValues.put(MEMBERS.name, "[]");
defaultValues.put(MEMBERS.name, "");
defaultValues.put(MEMBER_COUNT.name, 0);
defaultValues.put(FLAGS.name, 0);
defaultValues.put(COMPLETION_DATE.name, 0);

@ -79,7 +79,7 @@ public class TagMetadata extends AbstractModel {
readPropertiesFromCursor(cursor);
}
public void readFromCursor(TodorooCursor<Metadata> cursor) {
public void readFromCursor(TodorooCursor<TagMetadata> cursor) {
super.readPropertiesFromCursor(cursor);
}

@ -55,7 +55,6 @@ import com.todoroo.astrid.actfm.sync.ActFmSyncService;
import com.todoroo.astrid.activity.TaskEditFragment;
import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.dao.UserDao;
import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.TagMetadata;
import com.todoroo.astrid.data.Task;
@ -218,8 +217,8 @@ public class EditPeopleControlSet extends PopupControlSet {
sharedPeople.add(user);
}
} catch (JSONException e) {
TodorooCursor<User> users = PluginServices.getUserDao().query(Query.select(User.PROPERTIES).where(User.UUID.in(
Query.select(TagMemberMetadata.USER_UUID).from(Metadata.TABLE).where(TagMetadata.TAG_UUID.eq(tagData.getUuid())))));
TodorooCursor<User> users = PluginServices.getUserDao().query(Query.select(User.PROPERTIES).where(Criterion.or(User.UUID.in(
Query.select(TagMemberMetadata.USER_UUID).from(TagMetadata.TABLE).where(TagMetadata.TAG_UUID.eq(tagData.getUuid()))), User.UUID.eq(tagData.getValue(TagData.USER_ID)))));
User user = new User();
for (users.moveToFirst(); !users.isAfterLast(); users.moveToNext()) {
user.clear();

@ -56,16 +56,20 @@ import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.api.FilterWithCustomIntent;
import com.todoroo.astrid.core.SortHelper;
import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
import com.todoroo.astrid.dao.UserDao;
import com.todoroo.astrid.data.RemoteModel;
import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.TagMetadata;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.Update;
import com.todoroo.astrid.data.User;
import com.todoroo.astrid.helper.AsyncImageView;
import com.todoroo.astrid.service.SyncV2Service;
import com.todoroo.astrid.service.TagDataService;
import com.todoroo.astrid.service.ThemeService;
import com.todoroo.astrid.subtasks.SubtasksTagListFragment;
import com.todoroo.astrid.tags.TagFilterExposer;
import com.todoroo.astrid.tags.TagMemberMetadata;
import com.todoroo.astrid.tags.TagService.Tag;
import com.todoroo.astrid.utility.AstridPreferences;
import com.todoroo.astrid.utility.Flags;
@ -103,6 +107,8 @@ public class TagViewFragment extends TaskListFragment {
@Autowired SyncV2Service syncService;
@Autowired UserDao userDao;
protected View taskListView;
private boolean dataLoaded = false;
@ -349,32 +355,77 @@ public class TagViewFragment extends TaskListFragment {
return;
LinearLayout membersView = (LinearLayout)getView().findViewById(R.id.shared_with);
membersView.setOnClickListener(settingsListener);
boolean addedMembers = false;
try {
String membersString = tagData.getValue(TagData.MEMBERS);
JSONArray members = new JSONArray(membersString);
if (members.length() > 0) {
membersView.setOnClickListener(null);
membersView.removeAllViews();
for (int i = 0; i < members.length(); i++) {
JSONObject member = members.getJSONObject(i);
addImageForMember(membersView, member);
String membersString = tagData.getValue(TagData.MEMBERS); // OK for legacy compatibility
if (!TextUtils.isEmpty(membersString)) {
JSONArray members = new JSONArray(membersString);
if (members.length() > 0) {
addedMembers = true;
membersView.setOnClickListener(null);
membersView.removeAllViews();
for (int i = 0; i < members.length(); i++) {
JSONObject member = members.getJSONObject(i);
addImageForMember(membersView, member);
}
}
} else {
TodorooCursor<User> users = userDao.query(Query.select(User.PROPERTIES)
.where(User.UUID.in(Query.select(TagMemberMetadata.USER_UUID)
.from(TagMetadata.TABLE)
.where(Criterion.and(TagMetadata.TAG_UUID.eq(tagData.getUuid()), TagMetadata.DELETION_DATE.eq(0))))));
try {
addedMembers = users.getCount() > 0;
if (addedMembers) {
membersView.setOnClickListener(null);
membersView.removeAllViews();
}
User user = new User();
for (users.moveToFirst(); !users.isAfterLast(); users.moveToNext()) {
user.clear();
user.readFromCursor(users);
JSONObject member = new JSONObject();
ActFmSyncService.JsonHelper.jsonFromUser(member, user);
addImageForMember(membersView, member);
}
} finally {
users.close();
}
// Handle creator
}
} catch (JSONException e) {
e.printStackTrace();
}
if (addedMembers) {
try {
// Handle creator
JSONObject owner;
if(!Task.USER_ID_SELF.equals(tagData.getValue(TagData.USER_ID))) {
owner = new JSONObject(tagData.getValue(TagData.USER));
String userString = tagData.getValue(TagData.USER);
if (!TextUtils.isEmpty(userString)) {
owner = new JSONObject(tagData.getValue(TagData.USER));
} else {
User user = userDao.fetch(tagData.getValue(TagData.USER_ID), User.PROPERTIES);
if (user != null) {
owner = new JSONObject();
ActFmSyncService.JsonHelper.jsonFromUser(owner, user);
} else {
owner = null;
}
}
} else {
owner = ActFmPreferenceService.thisUser();
}
addImageForMember(membersView, owner);
if (owner != null)
addImageForMember(membersView, owner);
JSONObject unassigned = new JSONObject();
unassigned.put("id", Task.USER_ID_UNASSIGNED); //$NON-NLS-1$
unassigned.put("name", getActivity().getString(R.string.actfm_EPA_unassigned)); //$NON-NLS-1$
addImageForMember(membersView, unassigned);
} catch (JSONException e) {
e.printStackTrace();
}
} catch (JSONException e) {
e.printStackTrace();
}
View filterAssigned = getView().findViewById(R.id.filter_assigned);

@ -114,6 +114,8 @@ public class MakeChanges<TYPE extends RemoteModel> extends ServerToClientMessage
ChangeHooks beforeSaveChanges = null;
if (NameMaps.TABLE_ID_TASKS.equals(table))
beforeSaveChanges = new BeforeSaveTaskChanges(model, changes, uuid);
else if (NameMaps.TABLE_ID_TAGS.equals(table))
beforeSaveChanges = new BeforeSaveTagChanges(model, changes, uuid);
if (beforeSaveChanges != null)
beforeSaveChanges.performChanges();
@ -156,6 +158,21 @@ public class MakeChanges<TYPE extends RemoteModel> extends ServerToClientMessage
}
}
private class BeforeSaveTagChanges extends ChangeHooks {
public BeforeSaveTagChanges(TYPE model, JSONObject changes, String uuid) {
super(model, changes, uuid);
}
@Override
public void performChanges() {
JSONArray addMembers = changes.optJSONArray("member_added");
boolean membersAdded = (addMembers != null && addMembers.length() > 0);
if (membersAdded)
model.setValue(TagData.MEMBERS, ""); // Clear this value for migration purposes
}
}
private class AfterSaveTaskChanges extends ChangeHooks {
public AfterSaveTaskChanges(TYPE model, JSONObject changes, String uuid) {
@ -235,7 +252,6 @@ public class MakeChanges<TYPE extends RemoteModel> extends ServerToClientMessage
boolean membersRemoved = (removeMembers != null && removeMembers.length() > 0);
if (membersAdded) {
model.setValue(TagData.MEMBERS, ""); // Clear this value for migration purposes
for (int i = 0; i < addMembers.length(); i++) {
try {
String memberId = addMembers.getString(i);

@ -116,7 +116,7 @@ public class PeopleFilterExposer extends BroadcastReceiver {
@SuppressWarnings("nls")
public static FilterWithCustomIntent mySharedTasks(Context context) {
TodorooCursor<TagData> tagsWithMembers = PluginServices.getTagDataService()
.query(Query.select(TagData.NAME, TagData.MEMBERS).where(TagData.MEMBER_COUNT.gt(0)));
.query(Query.select(TagData.NAME).where(TagData.MEMBER_COUNT.gt(0)));
String[] names;
try {
if (tagsWithMembers.getCount() == 0) {

Loading…
Cancel
Save