Skip to content

Commit 2f2580a

Browse files
handle task notification prioritization
1 parent d94f7ba commit 2f2580a

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/main/java/org/medicmobile/webapp/mobile/AppNotificationManager.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,15 @@ private void showMultipleTaskNotifications(JSONArray dataArray) throws JSONExcep
117117
long maxNotifications = appDataStore.getLongBlocking(MAX_NOTIFICATIONS_TO_SHOW_KEY, 8L);
118118
long latestStoredTimestamp = getLatestStoredTimestamp(getStartOfDay());
119119
int counter = 0;
120+
long latestReadyAt = 0;
120121
for (int i = 0; i < dataArray.length(); i++) {
121122
JSONObject notification = dataArray.getJSONObject(i);
122123
long readyAt = notification.getLong("readyAt");
124+
latestReadyAt = Math.max(latestReadyAt, readyAt);
125+
if (counter >= maxNotifications) {
126+
continue;
127+
}
128+
123129
long endDate = notification.getLong("endDate");
124130
long dueDate = notification.getLong("dueDate");
125131
if (isValidNotification(latestStoredTimestamp, readyAt, dueDate, endDate)) {
@@ -129,11 +135,8 @@ private void showMultipleTaskNotifications(JSONArray dataArray) throws JSONExcep
129135
showNotification(intent, notificationId, title, contentText);
130136
counter++;
131137
}
132-
if (counter >= maxNotifications) {
133-
break;
134-
}
135138
}
136-
saveLatestNotificationTimestamp(dataArray.getJSONObject(0).getLong("readyAt"));
139+
saveLatestNotificationTimestamp(latestReadyAt);
137140
}
138141

139142
private boolean isValidNotification(long latestStoredTimestamp, long readyAt, long dueDate, long endDate) {

0 commit comments

Comments
 (0)