Producteev filter: responsible person

pull/14/head
Tim Su 16 years ago
parent 3375e1afb8
commit 05b78aee33

@ -3,10 +3,14 @@
*/ */
package com.todoroo.astrid.producteev; package com.todoroo.astrid.producteev;
import java.util.TreeMap;
import java.util.Map.Entry;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.util.Pair;
import com.timsu.astrid.R; import com.timsu.astrid.R;
import com.todoroo.andlib.sql.Criterion; import com.todoroo.andlib.sql.Criterion;
@ -52,6 +56,25 @@ public class ProducteevFilterExposer extends BroadcastReceiver {
return filter; return filter;
} }
private Filter filterFromUser(Context context, String user, Pair<Long, String> ids) {
String title = context.getString(R.string.producteev_FEx_responsible_title, user);
ContentValues values = new ContentValues();
values.put(Metadata.KEY.name, ProducteevTask.METADATA_KEY);
values.put(ProducteevTask.DASHBOARD_ID.name, ids.first);
values.put(ProducteevTask.ID.name, 0);
values.put(ProducteevTask.CREATOR_ID.name, 0);
values.put(ProducteevTask.RESPONSIBLE_ID.name, ids.second);
Filter filter = new Filter(user, title, new QueryTemplate().join(
ProducteevDataService.METADATA_JOIN).where(Criterion.and(
MetadataCriteria.withKey(ProducteevTask.METADATA_KEY),
TaskCriteria.isActive(),
TaskCriteria.isVisible(),
ProducteevTask.RESPONSIBLE_ID.eq(ids.second))),
values);
return filter;
}
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
// if we aren't logged in, don't expose features // if we aren't logged in, don't expose features
@ -60,26 +83,60 @@ public class ProducteevFilterExposer extends BroadcastReceiver {
StoreObject[] dashboards = ProducteevDataService.getInstance().getDashboards(); StoreObject[] dashboards = ProducteevDataService.getInstance().getDashboards();
// If user does not have any tags, don't show this section at all // If user does not have any dashboards, don't show this section at all
if(dashboards.length == 0) if(dashboards.length == 0)
return; return;
FilterListHeader producteevHeader = new FilterListHeader(context.getString(R.string.producteev_FEx_header));
// load dashboards
Filter[] dashboardFilters = new Filter[dashboards.length]; Filter[] dashboardFilters = new Filter[dashboards.length];
for(int i = 0; i < dashboards.length; i++) for(int i = 0; i < dashboards.length; i++)
dashboardFilters[i] = filterFromList(context, new ProducteevDashboard(dashboards[i])); dashboardFilters[i] = filterFromList(context, new ProducteevDashboard(dashboards[i]));
FilterListHeader producteevHeader = new FilterListHeader(context.getString(R.string.producteev_FEx_header));
FilterCategory producteevDashboards = new FilterCategory(context.getString(R.string.producteev_FEx_dashboard), FilterCategory producteevDashboards = new FilterCategory(context.getString(R.string.producteev_FEx_dashboard),
dashboardFilters); dashboardFilters);
// load responsible people
TreeMap<String, Pair<Long, String>> people = loadResponsiblePeople(dashboards);
Filter[] peopleFilters = new Filter[people.size()];
int index = 0;
for(Entry<String, Pair<Long, String>> person : people.entrySet())
peopleFilters[index++] = filterFromUser(context, person.getKey(), person.getValue());
FilterCategory producteevUsers = new FilterCategory(context.getString(R.string.producteev_FEx_responsible),
peopleFilters);
// transmit filter list // transmit filter list
FilterListItem[] list = new FilterListItem[2]; FilterListItem[] list = new FilterListItem[3];
list[0] = producteevHeader; list[0] = producteevHeader;
list[1] = producteevDashboards; list[1] = producteevDashboards;
list[2] = producteevUsers;
Intent broadcastIntent = new Intent(AstridApiConstants.BROADCAST_SEND_FILTERS); Intent broadcastIntent = new Intent(AstridApiConstants.BROADCAST_SEND_FILTERS);
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_ADDON, ProducteevUtilities.IDENTIFIER); broadcastIntent.putExtra(AstridApiConstants.EXTRAS_ADDON, ProducteevUtilities.IDENTIFIER);
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_RESPONSE, list); broadcastIntent.putExtra(AstridApiConstants.EXTRAS_RESPONSE, list);
context.sendBroadcast(broadcastIntent, AstridApiConstants.PERMISSION_READ); context.sendBroadcast(broadcastIntent, AstridApiConstants.PERMISSION_READ);
} }
/**
* @param dashboards
* @return people in a map of name => pair(dashboard id, user id)
*/
@SuppressWarnings("nls")
private TreeMap<String, Pair<Long, String>> loadResponsiblePeople(
StoreObject[] dashboards) {
TreeMap<String, Pair<Long, String>> results = new TreeMap<String, Pair<Long, String>>();
for(StoreObject dashboard : dashboards) {
String users = dashboard.getValue(ProducteevDashboard.USERS);
String[] entries = users.split(";");
for(String entry : entries) {
String[] data = entry.split(",");
if(data.length != 2)
continue;
results.put(data[1], new Pair<Long, String>(
dashboard.getValue(ProducteevDashboard.REMOTE_ID), data[0])); // name, id
}
}
return results;
}
} }

@ -3,7 +3,6 @@ package com.todoroo.astrid.producteev.sync;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
/** /**
* *
* @author Arne Jans <arne.jans@gmail.com> * @author Arne Jans <arne.jans@gmail.com>
@ -19,7 +18,8 @@ public class ProducteevUser {
private final String lastname; private final String lastname;
public ProducteevUser(long id, String email, String firstname, String lastname) { public ProducteevUser(long id, String email, String firstname,
String lastname) {
this.id = id; this.id = id;
this.email = email; this.email = email;
this.firstname = firstname; this.firstname = firstname;
@ -36,33 +36,33 @@ public class ProducteevUser {
/** /**
* @return the email * @return the email
*/ */
public String getEmail() { public String getEmail() {
return email; return email;
} }
/** /**
* @return the firstname * @return the firstname
*/ */
public String getFirstname() { public String getFirstname() {
return firstname; return firstname;
} }
/** /**
* @return the lastname * @return the lastname
*/ */
public String getLastname() { public String getLastname() {
return lastname; return lastname;
} }
/** /**
* @return the id * @return the id
*/ */
public long getId() { public long getId() {
return id; return id;
} }
@Override @Override
public String toString() { public String toString() {
String displayString = ""; String displayString = "";
boolean hasFirstname = false; boolean hasFirstname = false;
boolean hasLastname = false; boolean hasLastname = false;
@ -77,8 +77,9 @@ public String toString() {
if (hasLastname) if (hasLastname)
displayString += lastname; displayString += lastname;
if (!hasFirstname && !hasLastname && email != null && email.length() > 0) if (!hasFirstname && !hasLastname && email != null
&& email.length() > 0)
displayString += email; displayString += email;
return displayString; return displayString;
} }
} }

Loading…
Cancel
Save