From 87f0c4a646b01d0426d8ce7c9d6a2be0fdbdf460 Mon Sep 17 00:00:00 2001 From: B Adarsh Date: Mon, 6 Mar 2017 08:01:15 +0530 Subject: [PATCH] Modifies notification for MUC conversations Minor fixes Replaces html.fromHTML with SpannableString --- .../services/NotificationService.java | 39 ++++++++++++++++--- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/services/NotificationService.java b/src/main/java/eu/siacs/conversations/services/NotificationService.java index 7302afb96..164b9633d 100644 --- a/src/main/java/eu/siacs/conversations/services/NotificationService.java +++ b/src/main/java/eu/siacs/conversations/services/NotificationService.java @@ -5,6 +5,7 @@ import android.app.PendingIntent; import android.content.Intent; import android.content.SharedPreferences; import android.graphics.Bitmap; +import android.graphics.Typeface; import android.net.Uri; import android.os.Build; import android.os.SystemClock; @@ -14,6 +15,8 @@ import android.support.v4.app.NotificationCompat.Builder; import android.support.v4.app.NotificationManagerCompat; import android.support.v4.app.RemoteInput; import android.text.Html; +import android.text.SpannableString; +import android.text.style.StyleSpan; import android.util.DisplayMetrics; import android.util.Log; @@ -262,12 +265,16 @@ public class NotificationService { if (messages.size() > 0) { conversation = messages.get(0).getConversation(); final String name = conversation.getName(); + SpannableString styledString; if (Config.HIDE_MESSAGE_TEXT_IN_NOTIFICATION) { int count = messages.size(); - style.addLine(Html.fromHtml(""+name+": "+mXmppConnectionService.getResources().getQuantityString(R.plurals.x_messages,count,count))); + styledString = new SpannableString(name + ": " + mXmppConnectionService.getResources().getQuantityString(R.plurals.x_messages,count,count)); + styledString.setSpan(new StyleSpan(Typeface.BOLD), 0, name.length(), 0); + style.addLine(styledString); } else { - style.addLine(Html.fromHtml("" + name + ": " - + UIHelper.getMessagePreview(mXmppConnectionService, messages.get(0)).first)); + styledString = new SpannableString(name + ": " + UIHelper.getMessagePreview(mXmppConnectionService, messages.get(0)).first); + styledString.setSpan(new StyleSpan(Typeface.BOLD), 0, name.length(), 0); + style.addLine(styledString); } names.append(name); names.append(", "); @@ -388,8 +395,30 @@ public class NotificationService { } builder.setStyle(messagingStyle); } else { - builder.setStyle(new NotificationCompat.BigTextStyle().bigText(getMergedBodies(messages))); - builder.setContentText(UIHelper.getMessagePreview(mXmppConnectionService, messages.get((messages.size()-1))).first); + if(messages.get(0).getConversation().getMode() == Conversation.MODE_SINGLE) { + builder.setStyle(new NotificationCompat.BigTextStyle().bigText(getMergedBodies(messages))); + builder.setContentText(UIHelper.getMessagePreview(mXmppConnectionService, messages.get((messages.size() - 1))).first); + } + else { + final NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle(); + SpannableString styledString; + for (Message message : messages) { + final String name = UIHelper.getMessageDisplayName(message); + styledString = new SpannableString(name + ": " + message.getBody()); + styledString.setSpan(new StyleSpan(Typeface.BOLD), 0, name.length(), 0); + style.addLine(styledString); + } + builder.setStyle(style); + if(messages.size() == 1) { + final String name = UIHelper.getMessageDisplayName(messages.get(0)); + styledString = new SpannableString(name + ": " + messages.get(0).getBody()); + styledString.setSpan(new StyleSpan(Typeface.BOLD), 0, name.length(), 0); + builder.setContentText(styledString); + } + else { + builder.setContentText(messages.size() + " " + mXmppConnectionService.getString(R.string.unread_conversations)); + } + } } }