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>
@ -11,74 +10,76 @@ import org.json.JSONObject;
@SuppressWarnings("nls") @SuppressWarnings("nls")
public class ProducteevUser { public class ProducteevUser {
private final long id; private final long id;
private final String email;
private final String firstname; private final String email;
private final String lastname; private final String firstname;
public ProducteevUser(long id, String email, String firstname, String lastname) { private final String lastname;
this.id = id;
this.email = email;
this.firstname = firstname;
this.lastname = lastname;
}
public ProducteevUser(JSONObject elt) throws JSONException { public ProducteevUser(long id, String email, String firstname,
this.id = elt.getLong("id"); String lastname) {
this.email = elt.getString("email"); this.id = id;
this.firstname = elt.getString("firstname"); this.email = email;
this.lastname = elt.getString("lastname"); this.firstname = firstname;
} this.lastname = lastname;
}
/** public ProducteevUser(JSONObject elt) throws JSONException {
* @return the email this.id = elt.getLong("id");
*/ this.email = elt.getString("email");
public String getEmail() { this.firstname = elt.getString("firstname");
return email; this.lastname = elt.getString("lastname");
} }
/** /**
* @return the firstname * @return the email
*/ */
public String getFirstname() { public String getEmail() {
return firstname; return email;
} }
/** /**
* @return the lastname * @return the firstname
*/ */
public String getLastname() { public String getFirstname() {
return lastname; return firstname;
} }
/** /**
* @return the id * @return the lastname
*/ */
public long getId() { public String getLastname() {
return id; return lastname;
} }
@Override /**
public String toString() { * @return the id
String displayString = ""; */
boolean hasFirstname = false; public long getId() {
boolean hasLastname = false; return id;
if (firstname != null && firstname.length() > 0) {
displayString += firstname;
hasFirstname = true;
} }
if (lastname != null && lastname.length() > 0)
hasLastname = true;
if (hasFirstname && hasLastname)
displayString += " ";
if (hasLastname)
displayString += lastname;
if (!hasFirstname && !hasLastname && email != null && email.length() > 0) @Override
displayString += email; public String toString() {
return displayString; String displayString = "";
} boolean hasFirstname = false;
boolean hasLastname = false;
if (firstname != null && firstname.length() > 0) {
displayString += firstname;
hasFirstname = true;
}
if (lastname != null && lastname.length() > 0)
hasLastname = true;
if (hasFirstname && hasLastname)
displayString += " ";
if (hasLastname)
displayString += lastname;
if (!hasFirstname && !hasLastname && email != null
&& email.length() > 0)
displayString += email;
return displayString;
}
} }

Loading…
Cancel
Save