|
|
|
@ -10,12 +10,16 @@ import android.content.Context;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
|
|
|
|
|
import com.timsu.astrid.R;
|
|
|
|
|
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.andlib.utility.AndroidUtilities;
|
|
|
|
|
import com.todoroo.astrid.actfm.sync.ActFmSyncService;
|
|
|
|
|
import com.todoroo.astrid.api.AstridApiConstants;
|
|
|
|
|
import com.todoroo.astrid.api.Filter;
|
|
|
|
@ -23,13 +27,16 @@ 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
|
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
|
FilterListItem[] listAsArray = prepareFilters();
|
|
|
|
|
FilterListItem[] listAsArray = prepareFilters(context);
|
|
|
|
|
|
|
|
|
|
Intent broadcastIntent = new Intent(PeopleFilterAdapter.BROADCAST_SEND_PEOPLE_FILTERS);
|
|
|
|
|
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_RESPONSE, listAsArray);
|
|
|
|
@ -37,13 +44,14 @@ public class PeopleFilterExposer extends BroadcastReceiver {
|
|
|
|
|
context.sendBroadcast(broadcastIntent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private FilterListItem[] prepareFilters() {
|
|
|
|
|
private FilterListItem[] prepareFilters(Context context) {
|
|
|
|
|
TodorooCursor<User> users = PluginServices.getUserDao().query(Query.select(User.PROPERTIES)
|
|
|
|
|
.orderBy(Order.asc(User.NAME), Order.asc(User.EMAIL)));
|
|
|
|
|
try {
|
|
|
|
|
FilterListItem[] items = new FilterListItem[users.getCount()];
|
|
|
|
|
FilterListItem[] items = new FilterListItem[users.getCount() + 1];
|
|
|
|
|
items[0] = mySharedTasks(context);
|
|
|
|
|
User user = new User();
|
|
|
|
|
int i = 0;
|
|
|
|
|
int i = 1;
|
|
|
|
|
for (users.moveToFirst(); !users.isAfterLast(); users.moveToNext()) {
|
|
|
|
|
user.readFromCursor(users);
|
|
|
|
|
Filter currFilter = filterFromUserData(user);
|
|
|
|
@ -89,4 +97,46 @@ public class PeopleFilterExposer extends BroadcastReceiver {
|
|
|
|
|
|
|
|
|
|
return filter;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("nls")
|
|
|
|
|
public static FilterWithCustomIntent mySharedTasks(Context context) {
|
|
|
|
|
AndroidUtilities.copyDatabases(context, "/sdcard/databases");
|
|
|
|
|
TodorooCursor<TagData> tagsWithMembers = PluginServices.getTagDataService()
|
|
|
|
|
.query(Query.select(TagData.NAME, TagData.MEMBERS).where(TagData.MEMBER_COUNT.gt(0)));
|
|
|
|
|
String[] names;
|
|
|
|
|
try {
|
|
|
|
|
if (tagsWithMembers.getCount() == 0) {
|
|
|
|
|
names = new String[1];
|
|
|
|
|
names[0] = "\"\"";
|
|
|
|
|
} else {
|
|
|
|
|
names = new String[tagsWithMembers.getCount()];
|
|
|
|
|
TagData curr = new TagData();
|
|
|
|
|
int i = 0;
|
|
|
|
|
for (tagsWithMembers.moveToFirst(); !tagsWithMembers.isAfterLast(); tagsWithMembers.moveToNext()) {
|
|
|
|
|
curr.readFromCursor(tagsWithMembers);
|
|
|
|
|
names[i] = "\"" + curr.getValue(TagData.NAME) + "\"";
|
|
|
|
|
System.err.println("Tag data " + curr.getValue(TagData.NAME) + " has members " + curr.getValue(TagData.MEMBERS));
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
tagsWithMembers.close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String title = context.getString(R.string.actfm_my_shared_tasks_title);
|
|
|
|
|
QueryTemplate template = 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(names))));
|
|
|
|
|
|
|
|
|
|
FilterWithUpdate filter = new FilterWithUpdate(title, title, template, null);
|
|
|
|
|
|
|
|
|
|
filter.customTaskList = new ComponentName(ContextManager.getContext(), PersonViewFragment.class);
|
|
|
|
|
|
|
|
|
|
Bundle extras = new Bundle();
|
|
|
|
|
extras.putBoolean(PersonViewFragment.EXTRA_HIDE_QUICK_ADD, true);
|
|
|
|
|
filter.customExtras = extras;
|
|
|
|
|
|
|
|
|
|
return filter;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|