Use names in social reminders

pull/14/head
Sam Bosley 12 years ago
parent ddd15d62ca
commit 787ae912dc

@ -187,6 +187,7 @@ public final class ActFmSyncService {
json.put("name", model.getDisplayName()); json.put("name", model.getDisplayName());
json.put("email", model.getValue(User.EMAIL)); json.put("email", model.getValue(User.EMAIL));
json.put("picture", model.getPictureUrl(User.PICTURE, RemoteModel.PICTURE_THUMB)); json.put("picture", model.getPictureUrl(User.PICTURE, RemoteModel.PICTURE_THUMB));
json.put("first_name", model.getValue(User.FIRST_NAME));
} }
public static void featuredListFromJson(JSONObject json, TagData model) throws JSONException { public static void featuredListFromJson(JSONObject json, TagData model) throws JSONException {

@ -5,8 +5,10 @@
*/ */
package com.todoroo.astrid.reminders; package com.todoroo.astrid.reminders;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import org.json.JSONArray; import org.json.JSONArray;
@ -173,10 +175,11 @@ public class ReminderDialog extends Dialog {
return; return;
Resources resources = activity.getResources(); Resources resources = activity.getResources();
LinkedHashSet<String> pictureUrls = new LinkedHashSet<String>(); LinkedHashSet<String> pictureUrls = new LinkedHashSet<String>();
List<String> names = new ArrayList<String>();
AtomicBoolean isSharedTask = new AtomicBoolean(false); AtomicBoolean isSharedTask = new AtomicBoolean(false);
if (pictureUrls.size() < MAX_FACES) { if (pictureUrls.size() < MAX_FACES) {
addTagFaces(task.getId(), pictureUrls, isSharedTask); addTagFaces(task.getId(), pictureUrls, names, isSharedTask);
} }
if (pictureUrls.size() > 0) { if (pictureUrls.size() > 0) {
@ -206,8 +209,15 @@ public class ReminderDialog extends Dialog {
container.setOrientation(LinearLayout.VERTICAL); container.setOrientation(LinearLayout.VERTICAL);
container.addView(layout, 0); container.addView(layout, 0);
((TextView) findViewById(R.id.reminder_message)).setText( String text;
Notifications.getRandomReminder(activity.getResources().getStringArray(R.array.reminders_social))); if (names.size() == 0)
text = activity.getString(R.string.reminders_social);
else if (names.size() == 1)
text = activity.getString(R.string.reminders_social_one, names.get(0));
else
text = activity.getString(R.string.reminders_social_multiple, names.get(0), names.get(1));
((TextView) findViewById(R.id.reminder_message)).setText(text);
task.setValue(Task.SOCIAL_REMINDER, Task.REMINDER_SOCIAL_FACES); task.setValue(Task.SOCIAL_REMINDER, Task.REMINDER_SOCIAL_FACES);
} else { } else {
@ -218,7 +228,7 @@ public class ReminderDialog extends Dialog {
} }
} }
private void addPicturesFromJSONArray(JSONArray array, LinkedHashSet<String> pictureUrls, AtomicBoolean isSharedTask) throws JSONException { private void addPicturesFromJSONArray(JSONArray array, LinkedHashSet<String> pictureUrls, List<String> names, AtomicBoolean isSharedTask) throws JSONException {
for (int i = 0; i < array.length(); i++) { for (int i = 0; i < array.length(); i++) {
JSONObject person = array.getJSONObject(i); JSONObject person = array.getJSONObject(i);
if (person.has("picture")) { //$NON-NLS-1$ if (person.has("picture")) { //$NON-NLS-1$
@ -229,11 +239,22 @@ public class ReminderDialog extends Dialog {
if (!TextUtils.isEmpty(pictureUrl)) { if (!TextUtils.isEmpty(pictureUrl)) {
pictureUrls.add(pictureUrl); pictureUrls.add(pictureUrl);
} }
String name = person.optString("first_name"); //$NON-NLS-1$
if (!TextUtils.isEmpty(name))
names.add(name);
else {
name = person.optString("name"); //$NON-NLS-1$
if (!TextUtils.isEmpty(name))
names.add(name);
}
} }
} }
} }
private void addTagFaces(long taskId, LinkedHashSet<String> pictureUrls, AtomicBoolean isSharedTask) { private void addTagFaces(long taskId, LinkedHashSet<String> pictureUrls, List<String> names, AtomicBoolean isSharedTask) {
TodorooCursor<TagData> tags = tagService.getTagDataForTask(taskId, Criterion.all, TagData.UUID, TagData.MEMBERS); TodorooCursor<TagData> tags = tagService.getTagDataForTask(taskId, Criterion.all, TagData.UUID, TagData.MEMBERS);
try { try {
TagData td = new TagData(); TagData td = new TagData();
@ -241,7 +262,7 @@ public class ReminderDialog extends Dialog {
td.readFromCursor(tags); td.readFromCursor(tags);
try { try {
JSONArray people = new JSONArray(td.getValue(TagData.MEMBERS)); JSONArray people = new JSONArray(td.getValue(TagData.MEMBERS));
addPicturesFromJSONArray(people, pictureUrls, isSharedTask); addPicturesFromJSONArray(people, pictureUrls, names, isSharedTask);
} catch (JSONException e) { } catch (JSONException e) {
JSONArray people = new JSONArray(); JSONArray people = new JSONArray();
TodorooCursor<User> users = userDao.query(Query.select(User.PROPERTIES) TodorooCursor<User> users = userDao.query(Query.select(User.PROPERTIES)
@ -263,7 +284,7 @@ public class ReminderDialog extends Dialog {
} }
} }
try { try {
addPicturesFromJSONArray(people, pictureUrls, isSharedTask); addPicturesFromJSONArray(people, pictureUrls, names, isSharedTask);
} catch (JSONException e2) { } catch (JSONException e2) {
// //
} }

@ -310,9 +310,11 @@
<!-- =============================================== random reminders == --> <!-- =============================================== random reminders == -->
<string-array name="reminders_social"> <string name="reminders_social">These people are counting on you!</string>
<item>These people are counting on you!</item>
</string-array> <string name="reminders_social_one">%s is counting on you!</string>
<string name="reminders_social_multiple">%1$s, %2$s, and others are counting on you!</string>
<string-array name="reminders"> <string-array name="reminders">
<!-- reminders: Make these < 20 chars so the task name is displayed --> <!-- reminders: Make these < 20 chars so the task name is displayed -->

Loading…
Cancel
Save