Skip to content

Commit

Permalink
Merge pull request #580 from Tunous/notification-mark-fix
Browse files Browse the repository at this point in the history
Mark repository as read when marking last unread notification
  • Loading branch information
slapperwan authored Apr 15, 2017
2 parents b47bc45 + 5062586 commit c656758
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/com/gh4a/adapter/NotificationAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public NotificationAdapter(Context context, OnNotificationActionCallback actionC

public void markAsRead(@Nullable Repository repository, @Nullable Notification notification) {
NotificationHolder previousRepoItem = null;
int notificationsInSameRepoCount = 0;
int unreadNotificationsInSameRepoCount = 0;

boolean isMarkingSingleNotification = repository == null && notification != null;

Expand All @@ -63,24 +63,24 @@ public void markAsRead(@Nullable Repository repository, @Nullable Notification n
}

// When marking single notification as read also mark the repository if it contained
// only 1 notification
// only 1 unread notification
if (isMarkingSingleNotification) {
if (item.notification == null) {
if (previousRepoItem != null && notificationsInSameRepoCount == 1
if (previousRepoItem != null && unreadNotificationsInSameRepoCount == 0
&& previousRepoItem.repository.equals(notification.getRepository())) {
previousRepoItem.setIsRead(true);
}
previousRepoItem = item;
notificationsInSameRepoCount = 0;
} else {
notificationsInSameRepoCount += 1;
unreadNotificationsInSameRepoCount = 0;
} else if (!item.isRead()) {
unreadNotificationsInSameRepoCount += 1;
}
}
}

// Additional check for the very last notification
if (isMarkingSingleNotification && previousRepoItem != null
&& notificationsInSameRepoCount == 1
&& unreadNotificationsInSameRepoCount == 0
&& previousRepoItem.repository.equals(notification.getRepository())) {
previousRepoItem.setIsRead(true);
}
Expand Down

0 comments on commit c656758

Please sign in to comment.