Map Gotify message priorities to notification channels
This commit is contained in:
@@ -117,9 +117,11 @@ public class WebSocketService extends Service {
|
||||
}
|
||||
|
||||
private void onGroupedMessages(List<Message> messages) {
|
||||
long highestPriority = 0;
|
||||
for (Message message : messages) {
|
||||
if (lastReceivedMessage.get() < message.getId()) {
|
||||
lastReceivedMessage.set(message.getId());
|
||||
highestPriority = Math.max(highestPriority, message.getPriority());
|
||||
}
|
||||
broadcast(message);
|
||||
}
|
||||
@@ -127,7 +129,8 @@ public class WebSocketService extends Service {
|
||||
showNotification(
|
||||
NotificationSupport.ID.GROUPED,
|
||||
getString(R.string.missed_messages),
|
||||
getString(R.string.grouped_message, size));
|
||||
getString(R.string.grouped_message, size),
|
||||
highestPriority);
|
||||
}
|
||||
|
||||
private void onMessage(Message message) {
|
||||
@@ -135,7 +138,7 @@ public class WebSocketService extends Service {
|
||||
lastReceivedMessage.set(message.getId());
|
||||
}
|
||||
broadcast(message);
|
||||
showNotification(message.getId(), message.getTitle(), message.getMessage());
|
||||
showNotification(message.getId(), message.getTitle(), message.getMessage(), message.getPriority());
|
||||
}
|
||||
|
||||
private void broadcast(Message message) {
|
||||
@@ -172,16 +175,16 @@ public class WebSocketService extends Service {
|
||||
startForeground(NotificationSupport.ID.FOREGROUND, notification);
|
||||
}
|
||||
|
||||
private void showNotification(int id, String title, String message) {
|
||||
private void showNotification(int id, String title, String message, long priority) {
|
||||
Intent intent = new Intent(this, MessagesActivity.class);
|
||||
PendingIntent contentIntent =
|
||||
PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
|
||||
NotificationCompat.Builder b =
|
||||
new NotificationCompat.Builder(this, NotificationSupport.Channel.MESSAGES);
|
||||
new NotificationCompat.Builder(this, NotificationSupport.convertPriorityToChannel(priority));
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
showNotificationGroup();
|
||||
showNotificationGroup(priority);
|
||||
}
|
||||
|
||||
b.setAutoCancel(true)
|
||||
@@ -204,13 +207,13 @@ public class WebSocketService extends Service {
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.N)
|
||||
public void showNotificationGroup() {
|
||||
public void showNotificationGroup(long priority) {
|
||||
Intent intent = new Intent(this, MessagesActivity.class);
|
||||
PendingIntent contentIntent =
|
||||
PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
|
||||
NotificationCompat.Builder b =
|
||||
new NotificationCompat.Builder(this, NotificationSupport.Channel.MESSAGES);
|
||||
new NotificationCompat.Builder(this, NotificationSupport.convertPriorityToChannel(priority));
|
||||
|
||||
b.setAutoCancel(true)
|
||||
.setDefaults(Notification.DEFAULT_ALL)
|
||||
|
||||
Reference in New Issue
Block a user