include ticker information in notification. fixes #3532

This commit is contained in:
Daniel Gultsch 2019-09-08 17:58:15 +02:00
parent dd9777a6b7
commit 8b69f8ae50
2 changed files with 15 additions and 16 deletions

View file

@ -11,7 +11,6 @@ import android.content.SharedPreferences;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.graphics.drawable.Icon;
import android.media.AudioAttributes; import android.media.AudioAttributes;
import android.media.RingtoneManager; import android.media.RingtoneManager;
import android.net.Uri; import android.net.Uri;
@ -23,7 +22,6 @@ import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationCompat.BigPictureStyle; import android.support.v4.app.NotificationCompat.BigPictureStyle;
import android.support.v4.app.NotificationCompat.Builder; import android.support.v4.app.NotificationCompat.Builder;
import android.support.v4.app.NotificationManagerCompat; import android.support.v4.app.NotificationManagerCompat;
import android.support.v4.app.NotificationCompat.CarExtender.UnreadConversation;
import android.support.v4.app.Person; import android.support.v4.app.Person;
import android.support.v4.app.RemoteInput; import android.support.v4.app.RemoteInput;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
@ -32,7 +30,6 @@ import android.text.SpannableString;
import android.text.style.StyleSpan; import android.text.style.StyleSpan;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
import android.util.Pair;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -64,7 +61,6 @@ import eu.siacs.conversations.utils.Compatibility;
import eu.siacs.conversations.utils.GeoHelper; import eu.siacs.conversations.utils.GeoHelper;
import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.utils.UIHelper;
import eu.siacs.conversations.xmpp.XmppConnection; import eu.siacs.conversations.xmpp.XmppConnection;
import rocks.xmpp.addr.Jid;
public class NotificationService { public class NotificationService {
@ -469,10 +465,7 @@ public class NotificationService {
private Builder buildMultipleConversation(final boolean notify, final boolean quietHours) { private Builder buildMultipleConversation(final boolean notify, final boolean quietHours) {
final Builder mBuilder = new NotificationCompat.Builder(mXmppConnectionService, quietHours ? "quiet_hours" : (notify ? "messages" : "silent_messages")); final Builder mBuilder = new NotificationCompat.Builder(mXmppConnectionService, quietHours ? "quiet_hours" : (notify ? "messages" : "silent_messages"));
final NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle(); final NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();
style.setBigContentTitle(notifications.size() style.setBigContentTitle(mXmppConnectionService.getString(R.string.x_unread_conversations,notifications.size()));
+ " "
+ mXmppConnectionService
.getString(R.string.unread_conversations));
final StringBuilder names = new StringBuilder(); final StringBuilder names = new StringBuilder();
Conversation conversation = null; Conversation conversation = null;
for (final ArrayList<Message> messages : notifications.values()) { for (final ArrayList<Message> messages : notifications.values()) {
@ -497,10 +490,8 @@ public class NotificationService {
if (names.length() >= 2) { if (names.length() >= 2) {
names.delete(names.length() - 2, names.length()); names.delete(names.length() - 2, names.length());
} }
mBuilder.setContentTitle(notifications.size() mBuilder.setContentTitle(mXmppConnectionService.getString(R.string.x_unread_conversations, notifications.size()));
+ " " mBuilder.setTicker(mXmppConnectionService.getString(R.string.x_unread_conversations, notifications.size()));
+ mXmppConnectionService
.getString(R.string.unread_conversations));
mBuilder.setContentText(names.toString()); mBuilder.setContentText(names.toString());
mBuilder.setStyle(style); mBuilder.setStyle(style);
if (conversation != null) { if (conversation != null) {
@ -627,8 +618,11 @@ public class NotificationService {
CharSequence text = getMergedBodies(tmp); CharSequence text = getMergedBodies(tmp);
bigPictureStyle.setSummaryText(text); bigPictureStyle.setSummaryText(text);
builder.setContentText(text); builder.setContentText(text);
builder.setTicker(text);
} else { } else {
builder.setContentText(UIHelper.getFileDescriptionString(mXmppConnectionService, message)); final String description = UIHelper.getFileDescriptionString(mXmppConnectionService, message);
builder.setContentText(description);
builder.setTicker(description);
} }
builder.setStyle(bigPictureStyle); builder.setStyle(bigPictureStyle);
} catch (final IOException e) { } catch (final IOException e) {
@ -685,7 +679,9 @@ public class NotificationService {
} else { } else {
if (messages.get(0).getConversation().getMode() == Conversation.MODE_SINGLE) { if (messages.get(0).getConversation().getMode() == Conversation.MODE_SINGLE) {
builder.setStyle(new NotificationCompat.BigTextStyle().bigText(getMergedBodies(messages))); builder.setStyle(new NotificationCompat.BigTextStyle().bigText(getMergedBodies(messages)));
builder.setContentText(UIHelper.getMessagePreview(mXmppConnectionService, messages.get(messages.size()-1)).first); final CharSequence preview = UIHelper.getMessagePreview(mXmppConnectionService, messages.get(messages.size()-1)).first;
builder.setContentText(preview);
builder.setTicker(preview);
builder.setNumber(messages.size()); builder.setNumber(messages.size());
} else { } else {
final NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle(); final NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();
@ -703,8 +699,11 @@ public class NotificationService {
styledString = new SpannableString(name + ": " + messages.get(0).getBody()); styledString = new SpannableString(name + ": " + messages.get(0).getBody());
styledString.setSpan(new StyleSpan(Typeface.BOLD), 0, name.length(), 0); styledString.setSpan(new StyleSpan(Typeface.BOLD), 0, name.length(), 0);
builder.setContentText(styledString); builder.setContentText(styledString);
builder.setTicker(styledString);
} else { } else {
builder.setContentText(mXmppConnectionService.getResources().getQuantityString(R.plurals.x_messages, count, count)); final String text = mXmppConnectionService.getResources().getQuantityString(R.plurals.x_messages, count, count);
builder.setContentText(text);
builder.setTicker(text);
} }
} }
} }

View file

@ -30,7 +30,7 @@
<string name="just_now">just now</string> <string name="just_now">just now</string>
<string name="minute_ago">1 min ago</string> <string name="minute_ago">1 min ago</string>
<string name="minutes_ago">%d mins ago</string> <string name="minutes_ago">%d mins ago</string>
<string name="unread_conversations">unread Conversations</string> <string name="x_unread_conversations">%d unread conversations</string>
<string name="sending">sending…</string> <string name="sending">sending…</string>
<string name="message_decrypting">Decrypting message. Please wait…</string> <string name="message_decrypting">Decrypting message. Please wait…</string>
<string name="pgp_message">OpenPGP encrypted message</string> <string name="pgp_message">OpenPGP encrypted message</string>