Use names in social reminders

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

@ -187,6 +187,7 @@ public final class ActFmSyncService {
json.put("name", model.getDisplayName());
json.put("email", model.getValue(User.EMAIL));
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 {

@ -5,8 +5,10 @@
*/
package com.todoroo.astrid.reminders;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import org.json.JSONArray;
@ -173,10 +175,11 @@ public class ReminderDialog extends Dialog {
return;
Resources resources = activity.getResources();
LinkedHashSet<String> pictureUrls = new LinkedHashSet<String>();
List<String> names = new ArrayList<String>();
AtomicBoolean isSharedTask = new AtomicBoolean(false);
if (pictureUrls.size() < MAX_FACES) {
addTagFaces(task.getId(), pictureUrls, isSharedTask);
addTagFaces(task.getId(), pictureUrls, names, isSharedTask);
}
if (pictureUrls.size() > 0) {
@ -206,8 +209,15 @@ public class ReminderDialog extends Dialog {
container.setOrientation(LinearLayout.VERTICAL);
container.addView(layout, 0);
((TextView) findViewById(R.id.reminder_message)).setText(
Notifications.getRandomReminder(activity.getResources().getStringArray(R.array.reminders_social)));
String text;
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);
} 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++) {
JSONObject person = array.getJSONObject(i);
if (person.has("picture")) { //$NON-NLS-1$
@ -229,11 +239,22 @@ public class ReminderDialog extends Dialog {
if (!TextUtils.isEmpty(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);
try {
TagData td = new TagData();
@ -241,7 +262,7 @@ public class ReminderDialog extends Dialog {
td.readFromCursor(tags);
try {
JSONArray people = new JSONArray(td.getValue(TagData.MEMBERS));
addPicturesFromJSONArray(people, pictureUrls, isSharedTask);
addPicturesFromJSONArray(people, pictureUrls, names, isSharedTask);
} catch (JSONException e) {
JSONArray people = new JSONArray();
TodorooCursor<User> users = userDao.query(Query.select(User.PROPERTIES)
@ -263,7 +284,7 @@ public class ReminderDialog extends Dialog {
}
}
try {
addPicturesFromJSONArray(people, pictureUrls, isSharedTask);
addPicturesFromJSONArray(people, pictureUrls, names, isSharedTask);
} catch (JSONException e2) {
//
}

@ -310,9 +310,11 @@
<!-- =============================================== random reminders == -->
<string-array name="reminders_social">
<item>These people are counting on you!</item>
</string-array>
<string name="reminders_social">These people are counting on you!</string>
<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">
<!-- reminders: Make these < 20 chars so the task name is displayed -->

Loading…
Cancel
Save