Fixed many bugs with people filters

pull/14/head
Sam Bosley 13 years ago
parent 0ed664a663
commit cc76e6d178

@ -1,5 +1,8 @@
package com.todoroo.astrid.people; package com.todoroo.astrid.people;
import org.json.JSONException;
import org.json.JSONObject;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.ContentValues; import android.content.ContentValues;
@ -10,22 +13,18 @@ import android.os.Bundle;
import com.todoroo.andlib.data.TodorooCursor; import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.sql.Criterion; import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Field;
import com.todoroo.andlib.sql.Join;
import com.todoroo.andlib.sql.Order; import com.todoroo.andlib.sql.Order;
import com.todoroo.andlib.sql.Query; import com.todoroo.andlib.sql.Query;
import com.todoroo.andlib.sql.QueryTemplate; import com.todoroo.andlib.sql.QueryTemplate;
import com.todoroo.astrid.actfm.sync.ActFmSyncService;
import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.api.FilterListItem; import com.todoroo.astrid.api.FilterListItem;
import com.todoroo.astrid.api.FilterWithCustomIntent; import com.todoroo.astrid.api.FilterWithCustomIntent;
import com.todoroo.astrid.api.FilterWithUpdate; import com.todoroo.astrid.api.FilterWithUpdate;
import com.todoroo.astrid.core.PluginServices; import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.User; import com.todoroo.astrid.data.User;
import com.todoroo.astrid.tags.TagService;
public class PeopleFilterExposer extends BroadcastReceiver { public class PeopleFilterExposer extends BroadcastReceiver {
@Override @Override
@ -60,38 +59,11 @@ public class PeopleFilterExposer extends BroadcastReceiver {
@SuppressWarnings("nls") @SuppressWarnings("nls")
public static FilterWithCustomIntent filterFromUserData(User user) { public static FilterWithCustomIntent filterFromUserData(User user) {
String email = user.getValue(User.EMAIL); String email = user.getValue(User.EMAIL);
String[] tags;
TodorooCursor<TagData> tagsWithUser = PluginServices.getTagDataService().query(Query.select(TagData.NAME)
.where(Criterion.or(
TagData.MEMBERS.like("%" + email + "%"),
TagData.USER.like("%" + email + "%"),
TagData.USER_ID.eq(user.getId()))));
try {
if (tagsWithUser.getCount() == 0) {
tags = new String[1];
tags[0] = "\"\"";
} else {
tags = new String[tagsWithUser.getCount()];
int i = 0;
TagData curr = new TagData();
for (tagsWithUser.moveToFirst(); !tagsWithUser.isAfterLast(); tagsWithUser.moveToNext()) {
curr.readFromCursor(tagsWithUser);
tags[i] = "\"" + curr.getValue(TagData.NAME) + "\"";
i++;
}
}
} finally {
tagsWithUser.close();
}
String title = user.getDisplayName(); String title = user.getDisplayName();
QueryTemplate userTemplate = new QueryTemplate().join(Join.inner(Metadata.TABLE.as("mtags"), QueryTemplate userTemplate = new QueryTemplate().where(
Criterion.and(Task.ID.eq(Field.field("mtags." + Metadata.TASK.name)),
Field.field("mtags." + Metadata.KEY.name).eq(TagService.KEY),
Field.field("mtags." + TagService.TAG.name).in(tags),
Criterion.or(Task.USER.like("%" + email + "%"), Criterion.or(Task.USER.like("%" + email + "%"),
Task.USER_ID.eq(user.getValue(User.REMOTE_ID)))))); Task.USER_ID.eq(user.getValue(User.REMOTE_ID))));
FilterWithUpdate filter = new FilterWithUpdate(title, title, userTemplate, null); FilterWithUpdate filter = new FilterWithUpdate(title, title, userTemplate, null);
@ -99,6 +71,13 @@ public class PeopleFilterExposer extends BroadcastReceiver {
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
values.put(Task.USER_ID.name, user.getValue(User.REMOTE_ID)); values.put(Task.USER_ID.name, user.getValue(User.REMOTE_ID));
try {
JSONObject userJson = new JSONObject();
ActFmSyncService.JsonHelper.jsonFromUser(userJson, user);
values.put(Task.USER.name, userJson.toString());
} catch (JSONException e) {
// Ignored
}
filter.valuesForNewTasks = values; filter.valuesForNewTasks = values;
String imageUrl = user.getValue(User.PICTURE); String imageUrl = user.getValue(User.PICTURE);

@ -20,4 +20,10 @@ public class PersonViewFragment extends TaskListFragment {
return parent; return parent;
} }
@Override
protected void setupQuickAddBar() {
super.setupQuickAddBar();
quickAddBar.setUsePeopleControl(false);
}
} }

@ -509,7 +509,7 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
getView().findViewById(R.id.progressBar).setVisibility(View.GONE); getView().findViewById(R.id.progressBar).setVisibility(View.GONE);
} }
private void setupQuickAddBar() { protected void setupQuickAddBar() {
quickAddBar = (QuickAddBar) getView().findViewById(R.id.taskListFooter); quickAddBar = (QuickAddBar) getView().findViewById(R.id.taskListFooter);
quickAddBar.initialize(getActivity(), this, mListener); quickAddBar.initialize(getActivity(), this, mListener);

@ -505,6 +505,9 @@ public class TaskService {
task.mergeWith(forTask); task.mergeWith(forTask);
} }
if (task.getValue(Task.USER_ID) != Task.USER_ID_SELF)
task.putTransitory(TRANS_ASSIGNED, true);
boolean markup = taskService.quickAdd(task); boolean markup = taskService.quickAdd(task);
if (markup) if (markup)
task.putTransitory(TRANS_QUICK_ADD_MARKUP, true); task.putTransitory(TRANS_QUICK_ADD_MARKUP, true);

@ -70,6 +70,7 @@ public class QuickAddBar extends LinearLayout {
private RepeatControlSet repeatControl; private RepeatControlSet repeatControl;
private GCalControlSet gcalControl; private GCalControlSet gcalControl;
private EditPeopleControlSet peopleControl; private EditPeopleControlSet peopleControl;
private boolean usePeopleControl = true;
@Autowired AddOnService addOnService; @Autowired AddOnService addOnService;
@Autowired ExceptionService exceptionService; @Autowired ExceptionService exceptionService;
@ -178,6 +179,11 @@ public class QuickAddBar extends LinearLayout {
setUpQuickAddControlSets(); setUpQuickAddControlSets();
} }
public void setUsePeopleControl(boolean usePeopleControl) {
this.usePeopleControl = usePeopleControl;
peopleControl.getDisplayView().setVisibility(usePeopleControl ? View.VISIBLE : View.GONE);
}
private void setUpQuickAddControlSets() { private void setUpQuickAddControlSets() {
repeatControl = new RepeatControlSet(activity, repeatControl = new RepeatControlSet(activity,
@ -245,7 +251,7 @@ public class QuickAddBar extends LinearLayout {
try { try {
if (title != null) if (title != null)
title = title.trim(); title = title.trim();
boolean assignedToMe = peopleControl.willBeAssignedToMe(); boolean assignedToMe = usePeopleControl ? peopleControl.willBeAssignedToMe() : true;
if (!assignedToMe && !actFmPreferenceService.isLoggedIn()) { if (!assignedToMe && !actFmPreferenceService.isLoggedIn()) {
DialogInterface.OnClickListener okListener = new DialogInterface.OnClickListener() { DialogInterface.OnClickListener okListener = new DialogInterface.OnClickListener() {
@Override @Override

Loading…
Cancel
Save