Skip to content

Commit

Permalink
Use names in social reminders
Browse files Browse the repository at this point in the history
  • Loading branch information
sbosley committed Apr 15, 2013
1 parent ddd15d6 commit 787ae91
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public static void jsonFromUser(JSONObject json, User model) throws JSONExceptio
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 {
Expand Down
35 changes: 28 additions & 7 deletions astrid/plugin-src/com/todoroo/astrid/reminders/ReminderDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -173,10 +175,11 @@ private void addFacesToReminder(Activity activity, Task task) {
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) {
Expand Down Expand Up @@ -206,8 +209,15 @@ private void addFacesToReminder(Activity activity, Task task) {
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 {
Expand All @@ -218,7 +228,7 @@ private void addFacesToReminder(Activity activity, Task task) {
}
}

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$
Expand All @@ -229,19 +239,30 @@ private void addPicturesFromJSONArray(JSONArray array, LinkedHashSet<String> pic
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();
for (tags.moveToFirst(); !tags.isAfterLast() && pictureUrls.size() < MAX_FACES; tags.moveToNext()) {
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)
Expand All @@ -263,7 +284,7 @@ private void addTagFaces(long taskId, LinkedHashSet<String> pictureUrls, AtomicB
}
}
try {
addPicturesFromJSONArray(people, pictureUrls, isSharedTask);
addPicturesFromJSONArray(people, pictureUrls, names, isSharedTask);
} catch (JSONException e2) {
//
}
Expand Down
8 changes: 5 additions & 3 deletions astrid/res/values/strings-reminders.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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 -->
Expand Down

0 comments on commit 787ae91

Please sign in to comment.