add shortcut info only for 'messages' channel
This commit is contained in:
parent
1cfc5d426e
commit
617dd76d2f
|
@ -115,6 +115,7 @@ public class NotificationService {
|
||||||
private long mLastNotification;
|
private long mLastNotification;
|
||||||
|
|
||||||
private static final String INCOMING_CALLS_NOTIFICATION_CHANNEL = "incoming_calls_channel";
|
private static final String INCOMING_CALLS_NOTIFICATION_CHANNEL = "incoming_calls_channel";
|
||||||
|
private static final String MESSAGES_NOTIFICATION_CHANNEL = "messages";
|
||||||
private Ringtone currentlyPlayingRingtone = null;
|
private Ringtone currentlyPlayingRingtone = null;
|
||||||
private ScheduledFuture<?> vibrationFuture;
|
private ScheduledFuture<?> vibrationFuture;
|
||||||
|
|
||||||
|
@ -244,7 +245,7 @@ public class NotificationService {
|
||||||
|
|
||||||
final NotificationChannel messagesChannel =
|
final NotificationChannel messagesChannel =
|
||||||
new NotificationChannel(
|
new NotificationChannel(
|
||||||
"messages",
|
MESSAGES_NOTIFICATION_CHANNEL,
|
||||||
c.getString(R.string.messages_channel_name),
|
c.getString(R.string.messages_channel_name),
|
||||||
NotificationManager.IMPORTANCE_HIGH);
|
NotificationManager.IMPORTANCE_HIGH);
|
||||||
messagesChannel.setShowBadge(true);
|
messagesChannel.setShowBadge(true);
|
||||||
|
@ -1112,7 +1113,7 @@ public class NotificationService {
|
||||||
final Builder mBuilder =
|
final Builder mBuilder =
|
||||||
new NotificationCompat.Builder(
|
new NotificationCompat.Builder(
|
||||||
mXmppConnectionService,
|
mXmppConnectionService,
|
||||||
quietHours ? "quiet_hours" : (notify ? "messages" : "silent_messages"));
|
quietHours ? "quiet_hours" : (notify ? MESSAGES_NOTIFICATION_CHANNEL : "silent_messages"));
|
||||||
final NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();
|
final NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();
|
||||||
style.setBigContentTitle(
|
style.setBigContentTitle(
|
||||||
mXmppConnectionService
|
mXmppConnectionService
|
||||||
|
@ -1178,39 +1179,37 @@ public class NotificationService {
|
||||||
|
|
||||||
private Builder buildSingleConversations(
|
private Builder buildSingleConversations(
|
||||||
final ArrayList<Message> messages, final boolean notify, final boolean quietHours) {
|
final ArrayList<Message> messages, final boolean notify, final boolean quietHours) {
|
||||||
final Builder mBuilder =
|
final var channel = quietHours ? "quiet_hours" : (notify ? MESSAGES_NOTIFICATION_CHANNEL : "silent_messages");
|
||||||
new NotificationCompat.Builder(
|
final Builder notificationBuilder =
|
||||||
mXmppConnectionService,
|
new NotificationCompat.Builder(mXmppConnectionService, channel);
|
||||||
quietHours ? "quiet_hours" : (notify ? "messages" : "silent_messages"));
|
if (messages.isEmpty()) {
|
||||||
if (messages.size() >= 1) {
|
return notificationBuilder;
|
||||||
|
}
|
||||||
final Conversation conversation = (Conversation) messages.get(0).getConversation();
|
final Conversation conversation = (Conversation) messages.get(0).getConversation();
|
||||||
mBuilder.setLargeIcon(
|
notificationBuilder.setLargeIcon(
|
||||||
mXmppConnectionService
|
mXmppConnectionService
|
||||||
.getAvatarService()
|
.getAvatarService()
|
||||||
.get(
|
.get(
|
||||||
conversation,
|
conversation,
|
||||||
AvatarService.getSystemUiAvatarSize(mXmppConnectionService)));
|
AvatarService.getSystemUiAvatarSize(mXmppConnectionService)));
|
||||||
mBuilder.setContentTitle(conversation.getName());
|
notificationBuilder.setContentTitle(conversation.getName());
|
||||||
if (Config.HIDE_MESSAGE_TEXT_IN_NOTIFICATION) {
|
if (Config.HIDE_MESSAGE_TEXT_IN_NOTIFICATION) {
|
||||||
int count = messages.size();
|
int count = messages.size();
|
||||||
mBuilder.setContentText(
|
notificationBuilder.setContentText(
|
||||||
mXmppConnectionService
|
mXmppConnectionService
|
||||||
.getResources()
|
.getResources()
|
||||||
.getQuantityString(R.plurals.x_messages, count, count));
|
.getQuantityString(R.plurals.x_messages, count, count));
|
||||||
} else {
|
} else {
|
||||||
Message message;
|
final Message message;
|
||||||
// TODO starting with Android 9 we might want to put images in MessageStyle
|
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P
|
||||||
&& (message = getImage(messages)) != null) {
|
&& (message = getImage(messages)) != null) {
|
||||||
modifyForImage(mBuilder, message, messages);
|
modifyForImage(notificationBuilder, message, messages);
|
||||||
} else {
|
} else {
|
||||||
modifyForTextOnly(mBuilder, messages);
|
modifyForTextOnly(notificationBuilder, messages);
|
||||||
}
|
}
|
||||||
RemoteInput remoteInput =
|
RemoteInput remoteInput =
|
||||||
new RemoteInput.Builder("text_reply")
|
new RemoteInput.Builder("text_reply")
|
||||||
.setLabel(
|
.setLabel(UIHelper.getMessageHint(mXmppConnectionService, conversation))
|
||||||
UIHelper.getMessageHint(
|
|
||||||
mXmppConnectionService, conversation))
|
|
||||||
.build();
|
.build();
|
||||||
PendingIntent markAsReadPendingIntent = createReadPendingIntent(conversation);
|
PendingIntent markAsReadPendingIntent = createReadPendingIntent(conversation);
|
||||||
NotificationCompat.Action markReadAction =
|
NotificationCompat.Action markReadAction =
|
||||||
|
@ -1240,12 +1239,12 @@ public class NotificationService {
|
||||||
createReplyIntent(conversation, lastMessageUuid, true))
|
createReplyIntent(conversation, lastMessageUuid, true))
|
||||||
.addRemoteInput(remoteInput)
|
.addRemoteInput(remoteInput)
|
||||||
.build();
|
.build();
|
||||||
mBuilder.extend(
|
notificationBuilder.extend(
|
||||||
new NotificationCompat.WearableExtender().addAction(wearReplyAction));
|
new NotificationCompat.WearableExtender().addAction(wearReplyAction));
|
||||||
int addedActionsCount = 1;
|
int addedActionsCount = 1;
|
||||||
mBuilder.addAction(markReadAction);
|
notificationBuilder.addAction(markReadAction);
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
mBuilder.addAction(replyAction);
|
notificationBuilder.addAction(replyAction);
|
||||||
++addedActionsCount;
|
++addedActionsCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1258,7 +1257,7 @@ public class NotificationService {
|
||||||
label,
|
label,
|
||||||
pendingSnoozeIntent)
|
pendingSnoozeIntent)
|
||||||
.build();
|
.build();
|
||||||
mBuilder.addAction(snoozeAction);
|
notificationBuilder.addAction(snoozeAction);
|
||||||
++addedActionsCount;
|
++addedActionsCount;
|
||||||
}
|
}
|
||||||
if (addedActionsCount < 3) {
|
if (addedActionsCount < 3) {
|
||||||
|
@ -1277,7 +1276,7 @@ public class NotificationService {
|
||||||
label,
|
label,
|
||||||
pendingShowLocationIntent)
|
pendingShowLocationIntent)
|
||||||
.build();
|
.build();
|
||||||
mBuilder.addAction(locationAction);
|
notificationBuilder.addAction(locationAction);
|
||||||
++addedActionsCount;
|
++addedActionsCount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1301,7 +1300,7 @@ public class NotificationService {
|
||||||
label,
|
label,
|
||||||
pendingDownloadIntent)
|
pendingDownloadIntent)
|
||||||
.build();
|
.build();
|
||||||
mBuilder.addAction(downloadAction);
|
notificationBuilder.addAction(downloadAction);
|
||||||
++addedActionsCount;
|
++addedActionsCount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1311,7 +1310,7 @@ public class NotificationService {
|
||||||
final Contact contact = conversation.getContact();
|
final Contact contact = conversation.getContact();
|
||||||
final Uri systemAccount = contact.getSystemAccount();
|
final Uri systemAccount = contact.getSystemAccount();
|
||||||
if (systemAccount != null) {
|
if (systemAccount != null) {
|
||||||
mBuilder.addPerson(systemAccount.toString());
|
notificationBuilder.addPerson(systemAccount.toString());
|
||||||
}
|
}
|
||||||
info = mXmppConnectionService.getShortcutService().getShortcutInfoCompat(contact);
|
info = mXmppConnectionService.getShortcutService().getShortcutInfoCompat(contact);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1320,18 +1319,21 @@ public class NotificationService {
|
||||||
.getShortcutService()
|
.getShortcutService()
|
||||||
.getShortcutInfoCompat(conversation.getMucOptions());
|
.getShortcutInfoCompat(conversation.getMucOptions());
|
||||||
}
|
}
|
||||||
mBuilder.setWhen(conversation.getLatestMessage().getTimeSent());
|
notificationBuilder.setWhen(conversation.getLatestMessage().getTimeSent());
|
||||||
mBuilder.setSmallIcon(R.drawable.ic_notification);
|
notificationBuilder.setSmallIcon(R.drawable.ic_notification);
|
||||||
mBuilder.setDeleteIntent(createDeleteIntent(conversation));
|
notificationBuilder.setDeleteIntent(createDeleteIntent(conversation));
|
||||||
mBuilder.setContentIntent(createContentIntent(conversation));
|
notificationBuilder.setContentIntent(createContentIntent(conversation));
|
||||||
mBuilder.setShortcutInfo(info);
|
if (channel.equals(MESSAGES_NOTIFICATION_CHANNEL)) {
|
||||||
|
// when do not want 'customized' notifications for silent notifications in their
|
||||||
|
// respective channels
|
||||||
|
notificationBuilder.setShortcutInfo(info);
|
||||||
if (Build.VERSION.SDK_INT >= 30) {
|
if (Build.VERSION.SDK_INT >= 30) {
|
||||||
mXmppConnectionService
|
mXmppConnectionService
|
||||||
.getSystemService(ShortcutManager.class)
|
.getSystemService(ShortcutManager.class)
|
||||||
.pushDynamicShortcut(info.toShortcutInfo());
|
.pushDynamicShortcut(info.toShortcutInfo());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return mBuilder;
|
return notificationBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void modifyForImage(
|
private void modifyForImage(
|
||||||
|
|
Loading…
Reference in a new issue