Fix notifications for media messages without text.

They now read 'media message' in italics.

Closes #2649
This commit is contained in:
Rhodey Orbits 2015-03-12 11:54:08 -07:00 committed by Moxie Marlinspike
parent 96896bf8f1
commit 2011391e65
3 changed files with 16 additions and 4 deletions

View File

@ -441,12 +441,14 @@
<string name="MessageNotifier_d_new_messages">%d new messages</string> <string name="MessageNotifier_d_new_messages">%d new messages</string>
<string name="MessageNotifier_most_recent_from_s">Most recent from: %s</string> <string name="MessageNotifier_most_recent_from_s">Most recent from: %s</string>
<string name="MessageNotifier_encrypted_message">Encrypted message...</string> <string name="MessageNotifier_encrypted_message">Encrypted message...</string>
<string name="MessageNotifier_media_message_with_text">Media message: %s</string>
<string name="MessageNotifier_no_subject">(No subject)</string> <string name="MessageNotifier_no_subject">(No subject)</string>
<string name="MessageNotifier_message_delivery_failed">Message delivery failed.</string> <string name="MessageNotifier_message_delivery_failed">Message delivery failed.</string>
<string name="MessageNotifier_failed_to_deliver_message">Failed to deliver message.</string> <string name="MessageNotifier_failed_to_deliver_message">Failed to deliver message.</string>
<string name="MessageNotifier_error_delivering_message">Error delivering message.</string> <string name="MessageNotifier_error_delivering_message">Error delivering message.</string>
<string name="MessageNotifier_mark_all_as_read">Mark all as read</string> <string name="MessageNotifier_mark_all_as_read">Mark all as read</string>
<string name="MessageNotifier_mark_as_read">Mark as read</string> <string name="MessageNotifier_mark_as_read">Mark as read</string>
<string name="MessageNotifier_media_message">Media message</string>
<!-- QuickResponseService --> <!-- QuickResponseService -->
<string name="QuickResponseService_sorry_quick_response_is_not_yet_supported_by_textsecure">Sorry, Quick Response is not yet supported by TextSecure!</string> <string name="QuickResponseService_sorry_quick_response_is_not_yet_supported_by_textsecure">Sorry, Quick Response is not yet supported by TextSecure!</string>

View File

@ -51,6 +51,7 @@ import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.recipients.RecipientFactory; import org.thoughtcrime.securesms.recipients.RecipientFactory;
import org.thoughtcrime.securesms.recipients.Recipients; import org.thoughtcrime.securesms.recipients.Recipients;
import org.thoughtcrime.securesms.service.KeyCachingService; import org.thoughtcrime.securesms.service.KeyCachingService;
import org.thoughtcrime.securesms.util.SpanUtil;
import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.whispersystems.textsecure.api.messages.TextSecureEnvelope; import org.whispersystems.textsecure.api.messages.TextSecureEnvelope;
@ -339,7 +340,7 @@ public class MessageNotifier {
Recipient recipient = record.getIndividualRecipient(); Recipient recipient = record.getIndividualRecipient();
Recipients recipients = record.getRecipients(); Recipients recipients = record.getRecipients();
long threadId = record.getThreadId(); long threadId = record.getThreadId();
SpannableString body = record.getDisplayBody(); CharSequence body = record.getDisplayBody();
Uri image = null; Uri image = null;
Recipients threadRecipients = null; Recipients threadRecipients = null;
@ -348,8 +349,13 @@ public class MessageNotifier {
} }
if (SmsDatabase.Types.isDecryptInProgressType(record.getType()) || !record.getBody().isPlaintext()) { if (SmsDatabase.Types.isDecryptInProgressType(record.getType()) || !record.getBody().isPlaintext()) {
body = new SpannableString(context.getString(R.string.MessageNotifier_encrypted_message)); body = SpanUtil.italic(context.getString(R.string.MessageNotifier_encrypted_message));
body.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), 0, body.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } else if (record.isMms() && TextUtils.isEmpty(body)) {
body = SpanUtil.italic(context.getString(R.string.MessageNotifier_media_message));
} else if (record.isMms()) {
String message = context.getString(R.string.MessageNotifier_media_message_with_text, body);
int italicLength = message.length() - body.length();
body = SpanUtil.italic(message, italicLength);
} }
notificationState.addNotification(new NotificationItem(recipient, recipients, threadRecipients, threadId, body, image)); notificationState.addNotification(new NotificationItem(recipient, recipients, threadRecipients, threadId, body, image));

View File

@ -10,8 +10,12 @@ import android.text.style.StyleSpan;
public class SpanUtil { public class SpanUtil {
public static CharSequence italic(CharSequence sequence) { public static CharSequence italic(CharSequence sequence) {
return italic(sequence, sequence.length());
}
public static CharSequence italic(CharSequence sequence, int length) {
SpannableString spannable = new SpannableString(sequence); SpannableString spannable = new SpannableString(sequence);
spannable.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), 0, sequence.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); spannable.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), 0, length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
return spannable; return spannable;
} }