Added a default people filter that shows all the tasks you have shared with anyone

pull/14/head
Sam Bosley 13 years ago
parent 4c845f2dfb
commit 4dd8bff567

@ -10,12 +10,16 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import com.timsu.astrid.R;
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.andlib.utility.AndroidUtilities;
import com.todoroo.astrid.actfm.sync.ActFmSyncService; 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;
@ -23,13 +27,16 @@ 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
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
FilterListItem[] listAsArray = prepareFilters(); FilterListItem[] listAsArray = prepareFilters(context);
Intent broadcastIntent = new Intent(PeopleFilterAdapter.BROADCAST_SEND_PEOPLE_FILTERS); Intent broadcastIntent = new Intent(PeopleFilterAdapter.BROADCAST_SEND_PEOPLE_FILTERS);
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_RESPONSE, listAsArray); broadcastIntent.putExtra(AstridApiConstants.EXTRAS_RESPONSE, listAsArray);
@ -37,13 +44,14 @@ public class PeopleFilterExposer extends BroadcastReceiver {
context.sendBroadcast(broadcastIntent); context.sendBroadcast(broadcastIntent);
} }
private FilterListItem[] prepareFilters() { private FilterListItem[] prepareFilters(Context context) {
TodorooCursor<User> users = PluginServices.getUserDao().query(Query.select(User.PROPERTIES) TodorooCursor<User> users = PluginServices.getUserDao().query(Query.select(User.PROPERTIES)
.orderBy(Order.asc(User.NAME), Order.asc(User.EMAIL))); .orderBy(Order.asc(User.NAME), Order.asc(User.EMAIL)));
try { try {
FilterListItem[] items = new FilterListItem[users.getCount()]; FilterListItem[] items = new FilterListItem[users.getCount() + 1];
items[0] = mySharedTasks(context);
User user = new User(); User user = new User();
int i = 0; int i = 1;
for (users.moveToFirst(); !users.isAfterLast(); users.moveToNext()) { for (users.moveToFirst(); !users.isAfterLast(); users.moveToNext()) {
user.readFromCursor(users); user.readFromCursor(users);
Filter currFilter = filterFromUserData(user); Filter currFilter = filterFromUserData(user);
@ -89,4 +97,46 @@ public class PeopleFilterExposer extends BroadcastReceiver {
return filter; 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;
}
} }

@ -33,8 +33,7 @@ public class PeopleViewActivity extends TaskListActivity {
@Override @Override
protected Filter getDefaultFilter() { protected Filter getDefaultFilter() {
// TODO More suitable default return PeopleFilterExposer.mySharedTasks(this);
return super.getDefaultFilter();
} }
@Override @Override

@ -25,6 +25,8 @@ public class PersonViewFragment extends TaskListFragment {
public static final String EXTRA_USER_ID_LOCAL = "user_local_id"; //$NON-NLS-1$ public static final String EXTRA_USER_ID_LOCAL = "user_local_id"; //$NON-NLS-1$
public static final String EXTRA_HIDE_QUICK_ADD = "hide_quickAdd"; //$NON-NLS-1$
private static final String LAST_FETCH_KEY = "actfm_last_user_"; //$NON-NLS-1$ private static final String LAST_FETCH_KEY = "actfm_last_user_"; //$NON-NLS-1$
protected static final int MENU_REFRESH_ID = MENU_SUPPORT_ID + 1; protected static final int MENU_REFRESH_ID = MENU_SUPPORT_ID + 1;
@ -54,8 +56,8 @@ public class PersonViewFragment extends TaskListFragment {
super.initializeData(); super.initializeData();
if (extras.containsKey(EXTRA_USER_ID_LOCAL)) { if (extras.containsKey(EXTRA_USER_ID_LOCAL)) {
user = userDao.fetch(extras.getLong(EXTRA_USER_ID_LOCAL), User.PROPERTIES); user = userDao.fetch(extras.getLong(EXTRA_USER_ID_LOCAL), User.PROPERTIES);
((TextView)taskListView.findViewById(android.R.id.empty)).setText(getEmptyDisplayString());
} }
((TextView)taskListView.findViewById(android.R.id.empty)).setText(getEmptyDisplayString());
} }
@Override @Override
@ -65,6 +67,9 @@ public class PersonViewFragment extends TaskListFragment {
if (user != null) if (user != null)
quickAddBar.getQuickAddBox().setHint(getString(R.string.TLA_quick_add_hint_assign, user.getDisplayName())); quickAddBar.getQuickAddBox().setHint(getString(R.string.TLA_quick_add_hint_assign, user.getDisplayName()));
if (extras.containsKey(EXTRA_HIDE_QUICK_ADD))
quickAddBar.setVisibility(View.GONE);
} }
@Override @Override
@ -99,24 +104,26 @@ public class PersonViewFragment extends TaskListFragment {
} }
private void refreshData(final boolean manual) { private void refreshData(final boolean manual) {
((TextView)taskListView.findViewById(android.R.id.empty)).setText(R.string.DLG_loading); if (user != null) {
((TextView)taskListView.findViewById(android.R.id.empty)).setText(R.string.DLG_loading);
syncService.synchronizeList(user, manual, new ProgressBarSyncResultCallback(getActivity(), this,
R.id.progressBar, new Runnable() { syncService.synchronizeList(user, manual, new ProgressBarSyncResultCallback(getActivity(), this,
@Override R.id.progressBar, new Runnable() {
public void run() { @Override
if (manual) public void run() {
ContextManager.getContext().sendBroadcast(new Intent(AstridApiConstants.BROADCAST_EVENT_REFRESH)); if (manual)
else ContextManager.getContext().sendBroadcast(new Intent(AstridApiConstants.BROADCAST_EVENT_REFRESH));
refresh(); else
((TextView)taskListView.findViewById(android.R.id.empty)).setText(getEmptyDisplayString()); refresh();
} ((TextView)taskListView.findViewById(android.R.id.empty)).setText(getEmptyDisplayString());
})); }
}));
}
} }
private String getEmptyDisplayString() { private String getEmptyDisplayString() {
String userName = user != null ? user.getDisplayName() : null; String userName = user != null ? user.getDisplayName() : null;
return TextUtils.isEmpty(userName) ? getString(R.string.TLA_no_items) : getString(R.string.TLA_no_items_person, userName); return TextUtils.isEmpty(userName) ? getString(R.string.actfm_my_shared_tasks_empty) : getString(R.string.TLA_no_items_person, userName);
} }
} }

@ -46,6 +46,12 @@
<!-- Cancel button for task view prompt --> <!-- Cancel button for task view prompt -->
<string name="actfm_view_task_cancel">Stay Here</string> <string name="actfm_view_task_cancel">Stay Here</string>
<!-- Title for the "My Shared Tasks" filter -->
<string name="actfm_my_shared_tasks_title">My Shared Tasks</string>
<!-- Empty list for the "My Shared Tasks" filter -->
<string name="actfm_my_shared_tasks_empty">No shared tasks</string>
<!-- ================================================== TagViewActivity == --> <!-- ================================================== TagViewActivity == -->
<!-- Tag View Activity: Add Comment hint --> <!-- Tag View Activity: Add Comment hint -->

@ -154,7 +154,7 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
int contentView = getContentView(); int contentView = getContentView();
if (contentView == R.layout.task_list_wrapper_activity) if (contentView == R.layout.task_list_wrapper_activity)
swipeEnabled = true; swipeEnabled = true;
setContentView(getContentView()); setContentView(contentView);
ActionBar actionBar = getSupportActionBar(); ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE); actionBar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);
@ -176,6 +176,7 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
if (extras != null) if (extras != null)
extras = (Bundle) extras.clone(); extras = (Bundle) extras.clone();
Filter savedFilter = getIntent().getParcelableExtra(TaskListFragment.TOKEN_FILTER); Filter savedFilter = getIntent().getParcelableExtra(TaskListFragment.TOKEN_FILTER);
if (Intent.ACTION_SEARCH.equals(getIntent().getAction())) { if (Intent.ACTION_SEARCH.equals(getIntent().getAction())) {
String query = getIntent().getStringExtra(SearchManager.QUERY).trim(); String query = getIntent().getStringExtra(SearchManager.QUERY).trim();
@ -185,14 +186,14 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
"%" + //$NON-NLS-1$ "%" + //$NON-NLS-1$
query.toUpperCase() + "%")), //$NON-NLS-1$ query.toUpperCase() + "%")), //$NON-NLS-1$
null); null);
if (extras == null)
extras = new Bundle();
extras.putParcelable(TaskListFragment.TOKEN_FILTER, savedFilter);
} }
if (savedFilter == null) if (savedFilter == null)
savedFilter = getDefaultFilter(); savedFilter = getDefaultFilter();
if (extras == null)
extras = new Bundle();
extras.putParcelable(TaskListFragment.TOKEN_FILTER, savedFilter);
if (swipeIsEnabled()) { if (swipeIsEnabled()) {
FilterListFragment flf = getFilterListFragment(); FilterListFragment flf = getFilterListFragment();

Loading…
Cancel
Save