diff --git a/astrid/res/layout/update_message_link.xml b/astrid/res/layout/update_message_link.xml new file mode 100644 index 000000000..018f37067 --- /dev/null +++ b/astrid/res/layout/update_message_link.xml @@ -0,0 +1,25 @@ + + + + + + + + + \ No newline at end of file diff --git a/astrid/src/com/todoroo/astrid/service/UpdateMessageService.java b/astrid/src/com/todoroo/astrid/service/UpdateMessageService.java index fecf03cbf..e27c1c21b 100644 --- a/astrid/src/com/todoroo/astrid/service/UpdateMessageService.java +++ b/astrid/src/com/todoroo/astrid/service/UpdateMessageService.java @@ -40,6 +40,7 @@ import com.todoroo.andlib.service.RestClient; import com.todoroo.andlib.sql.Query; import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.andlib.utility.DialogUtilities; +import com.todoroo.andlib.utility.Pair; import com.todoroo.astrid.actfm.sync.ActFmPreferenceService; import com.todoroo.astrid.dao.StoreObjectDao; import com.todoroo.astrid.dao.StoreObjectDao.StoreObjectCriteria; @@ -82,8 +83,8 @@ public class UpdateMessageService { if(updates == null || updates.length() == 0) return; - CharSequence message = buildUpdateMessage(updates); - if(message.length() == 0) + Pair message = buildUpdateMessage(updates); + if(message == null || message.getLeft().length() == 0) return; displayUpdateDialog(message); @@ -108,27 +109,29 @@ public class UpdateMessageService { } } - protected void displayUpdateDialog(CharSequence message) { + protected void displayUpdateDialog(Pair message) { if(activity == null) return; final DialogShower ds; - if (message instanceof Spannable) { - final TextView textView = new TextView(activity); - textView.setText(message); - textView.setTextSize(16); - textView.setTextColor(activity.getResources().getColor(ThemeService.getDialogTextColor())); - textView.setMovementMethod(LinkMovementMethod.getInstance()); - textView.setPadding(10, 0, 10, 0); + if (message.getRight() != null) { + final View view = activity.getLayoutInflater().inflate(R.layout.update_message_link, null); + TextView messageView = (TextView) view.findViewById(R.id.update_message); + messageView.setText(message.getLeft()); + messageView.setTextColor(activity.getResources().getColor(ThemeService.getDialogTextColor())); + + final TextView linkView = (TextView) view.findViewById(R.id.update_link); + linkView.setMovementMethod(LinkMovementMethod.getInstance()); + linkView.setText(message.getRight()); ds = new DialogShower() { @Override public void showDialog(Activity a) { final Dialog d = new AlertDialog.Builder(a) .setTitle(R.string.UpS_updates_title) - .setView(textView) + .setView(view) .setPositiveButton(R.string.DLG_ok, null) .create(); - textView.setOnClickListener(new OnClickListener() { + linkView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { d.dismiss(); @@ -159,7 +162,7 @@ public class UpdateMessageService { } - protected CharSequence buildUpdateMessage(JSONArray updates) { + protected Pair buildUpdateMessage(JSONArray updates) { for(int i = 0; i < updates.length(); i++) { JSONObject update; try { @@ -184,30 +187,30 @@ public class UpdateMessageService { continue; } - CharSequence toReturn; + Pair toReturn; String type = update.optString("type", null); if ("screen".equals(type) || "pref".equals(type)) { String linkText = update.optString("link"); - Spannable span = Spannable.Factory.getInstance().newSpannable(message + "\n\n" + linkText); + Spannable span = Spannable.Factory.getInstance().newSpannable(linkText); ClickableSpan click = getClickableSpanForUpdate(update, type); if (click == null) continue; - span.setSpan(click, span.length() - linkText.length(), span.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE); - toReturn = span; + span.setSpan(click, 0, span.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE); + toReturn = Pair.create(message, span); } else { StringBuilder builder = new StringBuilder(); if(date != null) builder.append("" + date + "
"); builder.append(message); builder.append("

"); - toReturn = builder.toString(); + toReturn = Pair.create(builder.toString(), null); } if(messageAlreadySeen(date, message)) continue; return toReturn; } - return ""; + return null; } private ClickableSpan getClickableSpanForUpdate(JSONObject update, String type) {