Skip to content

Commit 789e1ae

Browse files
author
menelike
committed
- be able to add lines from the payload when using inbox style
- use separate inbox per notId
1 parent e5370c4 commit 789e1ae

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

src/android/com/adobe/phonegap/push/FCMService.java

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ public class FCMService extends FirebaseMessagingService implements PushConstant
5555
private static HashMap<Integer, ArrayList<String>> messageMap = new HashMap<Integer, ArrayList<String>>();
5656

5757
public void setNotification(int notId, String message) {
58-
ArrayList<String> messageList = messageMap.get(notId);
59-
if (messageList == null) {
60-
messageList = new ArrayList<String>();
61-
messageMap.put(notId, messageList);
62-
}
6358

6459
if (message.isEmpty()) {
65-
messageList.clear();
60+
messageMap.remove(notId);
6661
} else {
62+
ArrayList<String> messageList = messageMap.get(notId);
63+
if (messageList == null) {
64+
messageList = new ArrayList<String>();
65+
messageMap.put(notId, messageList);
66+
}
6767
messageList.add(message);
6868
}
6969
}
@@ -659,13 +659,35 @@ private void setNotificationOngoing(Bundle extras, NotificationCompat.Builder mB
659659

660660
private void setNotificationMessage(int notId, Bundle extras, NotificationCompat.Builder mBuilder) {
661661
String message = extras.getString(MESSAGE);
662+
String lines = extras.getString(LINES);
662663
String style = extras.getString(STYLE, STYLE_TEXT);
663664
if (STYLE_INBOX.equals(style)) {
664665
setNotification(notId, message);
665666

666667
mBuilder.setContentText(fromHtml(message));
667668

668-
ArrayList<String> messageList = messageMap.get(notId);
669+
ArrayList<String> messageList = new ArrayList<String>();
670+
if (lines != null) {
671+
setNotification(notId, "");
672+
try {
673+
JSONArray linesList = new JSONArray(lines);
674+
if (linesList.length() != 0) {
675+
for (int i = 0; i < linesList.length(); i++) {
676+
messageList.add(linesList.optString(i));
677+
setNotification(notId, linesList.optString(i));
678+
}
679+
}
680+
} catch (JSONException e) {
681+
// nope
682+
}
683+
} else {
684+
ArrayList<String> cachedMessages = messageMap.get(notId);
685+
messageList.add(message);
686+
for (int i = 0; i < cachedMessages.size(); i++) {
687+
messageList.addAll(cachedMessages);
688+
}
689+
}
690+
669691
Integer sizeList = messageList.size();
670692
if (sizeList > 1) {
671693
String sizeListMessage = sizeList.toString();
@@ -677,7 +699,7 @@ private void setNotificationMessage(int notId, Bundle extras, NotificationCompat
677699
NotificationCompat.InboxStyle notificationInbox = new NotificationCompat.InboxStyle()
678700
.setBigContentTitle(fromHtml(extras.getString(TITLE))).setSummaryText(fromHtml(stacking));
679701

680-
for (int i = messageList.size() - 1; i >= 0; i--) {
702+
for (int i=0; i<messageList.size(); i++) {
681703
notificationInbox.addLine(fromHtml(messageList.get(i)));
682704
}
683705

src/android/com/adobe/phonegap/push/PushConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,5 @@ public interface PushConstants {
102102
public static final String ONGOING = "ongoing";
103103
public static final String LIST_CHANNELS = "listChannels";
104104
public static final String CLEAR_NOTIFICATION = "clearNotification";
105+
public static final String LINES = "lines";
105106
}

0 commit comments

Comments
 (0)