2015-07-31 15:05:24 -07:00
|
|
|
package org.thoughtcrime.securesms.notifications;
|
|
|
|
|
|
|
|
import android.app.Notification;
|
|
|
|
import android.app.PendingIntent;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
import android.support.annotation.Nullable;
|
|
|
|
import android.support.v4.app.NotificationCompat;
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.ConversationListActivity;
|
2019-07-24 12:30:23 +10:00
|
|
|
import network.loki.messenger.R;
|
2017-09-21 10:03:05 -07:00
|
|
|
import org.thoughtcrime.securesms.preferences.widgets.NotificationPrivacyPreference;
|
2015-07-31 15:05:24 -07:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
2017-04-21 23:04:54 -07:00
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
2015-07-31 15:05:24 -07:00
|
|
|
import org.thoughtcrime.securesms.util.Util;
|
|
|
|
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
public class MultipleRecipientNotificationBuilder extends AbstractNotificationBuilder {
|
|
|
|
|
|
|
|
private final List<CharSequence> messageBodies = new LinkedList<>();
|
|
|
|
|
|
|
|
public MultipleRecipientNotificationBuilder(Context context, NotificationPrivacyPreference privacy) {
|
|
|
|
super(context, privacy);
|
|
|
|
|
|
|
|
setColor(context.getResources().getColor(R.color.textsecure_primary));
|
2019-07-24 09:51:09 +10:00
|
|
|
setSmallIcon(R.drawable.ic_notification);
|
2015-07-31 15:05:24 -07:00
|
|
|
setContentTitle(context.getString(R.string.app_name));
|
|
|
|
setContentIntent(PendingIntent.getActivity(context, 0, new Intent(context, ConversationListActivity.class), 0));
|
|
|
|
setCategory(NotificationCompat.CATEGORY_MESSAGE);
|
2016-12-25 15:27:59 -08:00
|
|
|
setGroupSummary(true);
|
2018-08-15 12:11:10 -07:00
|
|
|
|
|
|
|
if (!NotificationChannels.supported()) {
|
|
|
|
setPriority(TextSecurePreferences.getNotificationPriority(context));
|
|
|
|
}
|
2015-07-31 15:05:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setMessageCount(int messageCount, int threadCount) {
|
|
|
|
setSubText(context.getString(R.string.MessageNotifier_d_new_messages_in_d_conversations,
|
|
|
|
messageCount, threadCount));
|
|
|
|
setContentInfo(String.valueOf(messageCount));
|
|
|
|
setNumber(messageCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setMostRecentSender(Recipient recipient) {
|
|
|
|
if (privacy.isDisplayContact()) {
|
|
|
|
setContentText(context.getString(R.string.MessageNotifier_most_recent_from_s,
|
|
|
|
recipient.toShortString()));
|
|
|
|
}
|
2018-09-04 16:57:55 -07:00
|
|
|
|
|
|
|
if (recipient.getNotificationChannel() != null) {
|
|
|
|
setChannelId(recipient.getNotificationChannel());
|
|
|
|
}
|
2015-07-31 15:05:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public void addActions(PendingIntent markAsReadIntent) {
|
|
|
|
NotificationCompat.Action markAllAsReadAction = new NotificationCompat.Action(R.drawable.check,
|
|
|
|
context.getString(R.string.MessageNotifier_mark_all_as_read),
|
|
|
|
markAsReadIntent);
|
|
|
|
addAction(markAllAsReadAction);
|
|
|
|
extend(new NotificationCompat.WearableExtender().addAction(markAllAsReadAction));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addMessageBody(@NonNull Recipient sender, @Nullable CharSequence body) {
|
|
|
|
if (privacy.isDisplayMessage()) {
|
|
|
|
messageBodies.add(getStyledMessage(sender, body));
|
|
|
|
} else if (privacy.isDisplayContact()) {
|
|
|
|
messageBodies.add(Util.getBoldedString(sender.toShortString()));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (privacy.isDisplayContact() && sender.getContactUri() != null) {
|
|
|
|
addPerson(sender.getContactUri().toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Notification build() {
|
|
|
|
if (privacy.isDisplayMessage() || privacy.isDisplayContact()) {
|
|
|
|
NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();
|
|
|
|
|
|
|
|
for (CharSequence body : messageBodies) {
|
2019-04-12 17:49:22 -04:00
|
|
|
style.addLine(trimToDisplayLength(body));
|
2015-07-31 15:05:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
setStyle(style);
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.build();
|
|
|
|
}
|
|
|
|
}
|