Skip to content

Commit

Permalink
Handle unclearable notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
italankin committed May 23, 2022
1 parent fa56167 commit 88c1bd4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -445,12 +445,7 @@ private List<DescriptorUi> concatNotifications(

private AppDescriptorUi concatAppNotifications(
AppDescriptorUi item, @Nullable NotificationBag bag) {
boolean badgeVisible = false;
if (bag != null) {
boolean showOngoing = preferences.get(Preferences.NOTIFICATION_DOT_ONGOING);
// bag will never be empty here
badgeVisible = showOngoing || bag.getCount() != bag.getOngoingCount();
}
boolean badgeVisible = isBadgeVisible(bag);
if (badgeVisible != item.isBadgeVisible()) {
// create a copy of AppDescriptorUi to update state correctly
AppDescriptorUi newApp = new AppDescriptorUi(item);
Expand All @@ -464,13 +459,9 @@ private AppDescriptorUi concatAppNotifications(
private FolderDescriptorUi concatFolderNotifications(
NotificationBagContainer notificationBagContainer, FolderDescriptorUi item) {
boolean badgeVisible = false;
boolean showOngoing = preferences.get(Preferences.NOTIFICATION_DOT_ONGOING);
for (String descriptorId : item.items) {
NotificationBag bag = notificationBagContainer.get(descriptorId);
if (bag == null) {
continue;
}
badgeVisible = showOngoing || bag.getCount() != bag.getOngoingCount();
badgeVisible = isBadgeVisible(bag);
if (badgeVisible) {
break;
}
Expand All @@ -485,6 +476,15 @@ private FolderDescriptorUi concatFolderNotifications(
}
}

private boolean isBadgeVisible(@Nullable NotificationBag bag) {
if (bag != null) {
// bag will never be empty here
boolean showDotOngoing = preferences.get(Preferences.NOTIFICATION_DOT_ONGOING);
return showDotOngoing || bag.getClearableCount() > 0;
}
return false;
}

private Observable<UserPrefs> observeUserPrefs() {
return preferences.observe()
.filter(UserPrefs.PREFERENCES::contains)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private static StatusBarNotification findSummary(List<StatusBarNotification> sbn
}

private static boolean ignore(StatusBarNotification sbn) {
if (sbn.isOngoing()) {
if (!sbn.isClearable()) {
return true;
}
Notification n = sbn.getNotification();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public int getMovementFlags(@NonNull RecyclerView recyclerView, @NonNull Recycle
return NON_MOVABLE_FLAGS;
}
AppNotificationUi item = ((AppNotificationUiAdapter.ViewHolder) viewHolder).item;
if (item.sbn.isOngoing()) {
if (!item.sbn.isClearable()) {
return NON_MOVABLE_FLAGS;
}
return MOVABLE_FLAGS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class NotificationBag {

final AppDescriptor descriptor;
final List<StatusBarNotification> sbns;
private final int ongoingCount;
private final int clearableCount;
private final int hashCode;

NotificationBag(AppDescriptor descriptor, StatusBarNotification sbn) {
Expand All @@ -24,15 +24,15 @@ public class NotificationBag {
this.descriptor = descriptor;
this.sbns = Collections.unmodifiableList(sbns);
int h = descriptor.hashCode();
int ongoingCount = 0;
int clearableCount = 0;
for (StatusBarNotification sbn : sbns) {
h = h * 31 + (sbn.getId() + 131);
if (sbn.isOngoing()) {
ongoingCount++;
if (sbn.isClearable()) {
clearableCount++;
}
}
this.hashCode = h;
this.ongoingCount = ongoingCount;
this.clearableCount = clearableCount;
}

public List<StatusBarNotification> getNotifications() {
Expand All @@ -43,8 +43,8 @@ public int getCount() {
return sbns.size();
}

public int getOngoingCount() {
return ongoingCount;
public int getClearableCount() {
return clearableCount;
}

@Override
Expand Down

0 comments on commit 88c1bd4

Please sign in to comment.