|
|
|
@ -1,5 +1,8 @@
|
|
|
|
|
package com.todoroo.astrid.people;
|
|
|
|
|
|
|
|
|
|
import org.json.JSONException;
|
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
|
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
|
import android.content.ComponentName;
|
|
|
|
|
import android.content.ContentValues;
|
|
|
|
@ -10,22 +13,18 @@ import android.os.Bundle;
|
|
|
|
|
import com.todoroo.andlib.data.TodorooCursor;
|
|
|
|
|
import com.todoroo.andlib.service.ContextManager;
|
|
|
|
|
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.Query;
|
|
|
|
|
import com.todoroo.andlib.sql.QueryTemplate;
|
|
|
|
|
import com.todoroo.astrid.actfm.sync.ActFmSyncService;
|
|
|
|
|
import com.todoroo.astrid.api.AstridApiConstants;
|
|
|
|
|
import com.todoroo.astrid.api.Filter;
|
|
|
|
|
import com.todoroo.astrid.api.FilterListItem;
|
|
|
|
|
import com.todoroo.astrid.api.FilterWithCustomIntent;
|
|
|
|
|
import com.todoroo.astrid.api.FilterWithUpdate;
|
|
|
|
|
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.User;
|
|
|
|
|
import com.todoroo.astrid.tags.TagService;
|
|
|
|
|
|
|
|
|
|
public class PeopleFilterExposer extends BroadcastReceiver {
|
|
|
|
|
@Override
|
|
|
|
@ -60,38 +59,11 @@ public class PeopleFilterExposer extends BroadcastReceiver {
|
|
|
|
|
@SuppressWarnings("nls")
|
|
|
|
|
public static FilterWithCustomIntent filterFromUserData(User user) {
|
|
|
|
|
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();
|
|
|
|
|
QueryTemplate userTemplate = new QueryTemplate().join(Join.inner(Metadata.TABLE.as("mtags"),
|
|
|
|
|
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),
|
|
|
|
|
QueryTemplate userTemplate = new QueryTemplate().where(
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
@ -99,6 +71,13 @@ public class PeopleFilterExposer extends BroadcastReceiver {
|
|
|
|
|
|
|
|
|
|
ContentValues values = new ContentValues();
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
String imageUrl = user.getValue(User.PICTURE);
|
|
|
|
|