diff --git a/astrid/src/com/todoroo/astrid/service/UpdateMessageService.java b/astrid/src/com/todoroo/astrid/service/UpdateMessageService.java index c9ccd0692..f8bd07ca4 100644 --- a/astrid/src/com/todoroo/astrid/service/UpdateMessageService.java +++ b/astrid/src/com/todoroo/astrid/service/UpdateMessageService.java @@ -92,8 +92,7 @@ public class UpdateMessageService { displayUpdateDialog(message); } - private static class MessageTuple { - public boolean htmlMessage = false; + public static class MessageTuple { public String message = null; public List linkText = new ArrayList(); public List click = new ArrayList(); @@ -224,25 +223,27 @@ public class UpdateMessageService { toReturn.click.add(click); } else { JSONArray links = update.optJSONArray("links"); - for (int j = 0; j < links.length(); j++) { - JSONObject link = links.optJSONObject(j); - if (link == null) - continue; - String linkText = link.optString("title"); - if (TextUtils.isEmpty(linkText)) - continue; - - final String url = link.optString("url"); - OnClickListener click = new OnClickListener() { - @Override - public void onClick(View v) { - Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); - activity.startActivity(intent); - } - }; + if (links != null) { + for (int j = 0; j < links.length(); j++) { + JSONObject link = links.optJSONObject(j); + if (link == null) + continue; + String linkText = link.optString("title"); + if (TextUtils.isEmpty(linkText)) + continue; + + final String url = link.optString("url"); + OnClickListener click = new OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); + activity.startActivity(intent); + } + }; - toReturn.linkText.add(linkText); - toReturn.click.add(click); + toReturn.linkText.add(linkText); + toReturn.click.add(click); + } } } diff --git a/tests/src/com/todoroo/astrid/service/UpdateMessageServiceTest.java b/tests/src/com/todoroo/astrid/service/UpdateMessageServiceTest.java index 1b4fe2e0a..bbd7d54e6 100644 --- a/tests/src/com/todoroo/astrid/service/UpdateMessageServiceTest.java +++ b/tests/src/com/todoroo/astrid/service/UpdateMessageServiceTest.java @@ -12,12 +12,8 @@ import org.apache.http.HttpEntity; import org.json.JSONArray; import org.weloveastrid.rmilk.MilkUtilities; -import android.text.Spannable; -import android.text.style.ClickableSpan; - import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.service.RestClient; -import com.todoroo.andlib.utility.Pair; import com.todoroo.astrid.dao.StoreObjectDao; import com.todoroo.astrid.dao.StoreObjectDao.StoreObjectCriteria; import com.todoroo.astrid.test.DatabaseTestCase; @@ -33,7 +29,7 @@ public class UpdateMessageServiceTest extends DatabaseTestCase { new TestUpdateMessageService() { @Override - void verifyMessage(Pair message) { + void verifyMessage(MessageTuple message) { fail("should not have displayed updates"); } @@ -52,7 +48,7 @@ public class UpdateMessageServiceTest extends DatabaseTestCase { new TestUpdateMessageService() { @Override - void verifyMessage(Pair message) { + void verifyMessage(MessageTuple message) { fail("should not have displayed updates"); } @@ -69,8 +65,8 @@ public class UpdateMessageServiceTest extends DatabaseTestCase { new TestUpdateMessageService() { @Override - void verifyMessage(Pair message) { - assertTrue(message.getLeft().toString().contains("yo")); + void verifyMessage(MessageTuple message) { + assertTrue(message.message.toString().contains("yo")); } @Override @@ -86,9 +82,9 @@ public class UpdateMessageServiceTest extends DatabaseTestCase { new TestUpdateMessageService() { @Override - void verifyMessage(Pair message) { - assertTrue(message.getLeft().toString().contains("yo")); - assertFalse(message.getLeft().toString().contains("cat")); // We only process the first update now + void verifyMessage(MessageTuple message) { + assertTrue(message.message.toString().contains("yo")); + assertFalse(message.message.toString().contains("cat")); // We only process the first update now } @Override @@ -104,8 +100,8 @@ public class UpdateMessageServiceTest extends DatabaseTestCase { new TestUpdateMessageService() { @Override - void verifyMessage(Pair message) { - assertTrue(message.getLeft().toString().contains("yo")); + void verifyMessage(MessageTuple message) { + assertTrue(message.message.toString().contains("yo")); } @Override @@ -117,7 +113,7 @@ public class UpdateMessageServiceTest extends DatabaseTestCase { new TestUpdateMessageService() { @Override - void verifyMessage(Pair message) { + void verifyMessage(MessageTuple message) { fail("should have not displayed again"); } @@ -139,9 +135,8 @@ public class UpdateMessageServiceTest extends DatabaseTestCase { new TestUpdateMessageService() { @Override - void verifyMessage(Pair message) { - assertTrue(message.getLeft().toString().contains("yo")); - assertTrue(message.getLeft().toString().contains("date")); + void verifyMessage(MessageTuple message) { + assertTrue(message.message.toString().contains("yo")); } @Override @@ -158,8 +153,8 @@ public class UpdateMessageServiceTest extends DatabaseTestCase { new TestUpdateMessageService() { @Override - void verifyMessage(Pair message) { - assertTrue(message.getLeft().toString().contains("rmilk man")); + void verifyMessage(MessageTuple message) { + assertTrue(message.message.toString().contains("rmilk man")); } @Override @@ -176,7 +171,7 @@ public class UpdateMessageServiceTest extends DatabaseTestCase { new TestUpdateMessageService() { @Override - void verifyMessage(Pair message) { + void verifyMessage(MessageTuple message) { fail("displayed update"); } @@ -198,8 +193,8 @@ public class UpdateMessageServiceTest extends DatabaseTestCase { new TestUpdateMessageService() { @Override - void verifyMessage(Pair message) { - assertTrue(message.getLeft().toString().contains("astrid man")); + void verifyMessage(MessageTuple message) { + assertTrue(message.message.toString().contains("astrid man")); } @Override @@ -215,7 +210,7 @@ public class UpdateMessageServiceTest extends DatabaseTestCase { new TestUpdateMessageService() { @Override - void verifyMessage(Pair message) { + void verifyMessage(MessageTuple message) { fail("displayed update"); } @@ -237,9 +232,9 @@ public class UpdateMessageServiceTest extends DatabaseTestCase { new TestUpdateMessageService() { @Override - void verifyMessage(Pair message) { - assertNotNull(message.getRight()); - assertTrue(((Spannable)message).getSpans(0, message.getRight().length(), ClickableSpan.class).length > 0); + void verifyMessage(MessageTuple message) { + assertTrue(message.linkText.size() > 0); + assertTrue(message.click.size() > 0); } @Override @@ -255,9 +250,9 @@ public class UpdateMessageServiceTest extends DatabaseTestCase { new TestUpdateMessageService() { @Override - void verifyMessage(Pair message) { - assertNotNull(message.getRight()); - assertTrue(((Spannable)message).getSpans(0, message.getRight().length(), ClickableSpan.class).length > 0); + void verifyMessage(MessageTuple message) { + assertTrue(message.linkText.size() > 0); + assertTrue(message.click.size() > 0); } @Override @@ -290,7 +285,7 @@ public class UpdateMessageServiceTest extends DatabaseTestCase { }; } - abstract void verifyMessage(Pair message); + abstract void verifyMessage(MessageTuple message); abstract String getUpdates(String url) throws IOException; @@ -299,16 +294,16 @@ public class UpdateMessageServiceTest extends DatabaseTestCase { } @Override - protected Pair buildUpdateMessage(JSONArray updates) { - Pair message = super.buildUpdateMessage(updates); - if(message == null || message.getLeft().length() == 0) + protected MessageTuple buildUpdateMessage(JSONArray updates) { + MessageTuple message = super.buildUpdateMessage(updates); + if(message == null || message.message.length() == 0) onEmptyMessage(); return message; } @Override - protected void displayUpdateDialog(Pair builder) { - verifyMessage(builder); + protected void displayUpdateDialog(MessageTuple tuple) { + verifyMessage(tuple); } }