From 88c1bd46ec870ca4004ab4f795e828516c796425 Mon Sep 17 00:00:00 2001 From: Igor Talankin Date: Mon, 23 May 2022 20:54:21 +0500 Subject: [PATCH] Handle unclearable notifications --- .../lnch/feature/home/apps/AppsPresenter.java | 22 +++++++++---------- .../notifications/AppNotificationFactory.java | 2 +- .../NotificationSwipeCallback.java | 2 +- .../notifications/NotificationBag.java | 14 ++++++------ 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/launcher/src/main/java/com/italankin/lnch/feature/home/apps/AppsPresenter.java b/launcher/src/main/java/com/italankin/lnch/feature/home/apps/AppsPresenter.java index 367c7592..1cc65b6e 100644 --- a/launcher/src/main/java/com/italankin/lnch/feature/home/apps/AppsPresenter.java +++ b/launcher/src/main/java/com/italankin/lnch/feature/home/apps/AppsPresenter.java @@ -445,12 +445,7 @@ private List 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); @@ -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; } @@ -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 observeUserPrefs() { return preferences.observe() .filter(UserPrefs.PREFERENCES::contains) diff --git a/launcher/src/main/java/com/italankin/lnch/feature/home/apps/popup/notifications/AppNotificationFactory.java b/launcher/src/main/java/com/italankin/lnch/feature/home/apps/popup/notifications/AppNotificationFactory.java index fe5fa827..c8bf7ffc 100644 --- a/launcher/src/main/java/com/italankin/lnch/feature/home/apps/popup/notifications/AppNotificationFactory.java +++ b/launcher/src/main/java/com/italankin/lnch/feature/home/apps/popup/notifications/AppNotificationFactory.java @@ -79,7 +79,7 @@ private static StatusBarNotification findSummary(List sbn } private static boolean ignore(StatusBarNotification sbn) { - if (sbn.isOngoing()) { + if (!sbn.isClearable()) { return true; } Notification n = sbn.getNotification(); diff --git a/launcher/src/main/java/com/italankin/lnch/feature/home/apps/popup/notifications/NotificationSwipeCallback.java b/launcher/src/main/java/com/italankin/lnch/feature/home/apps/popup/notifications/NotificationSwipeCallback.java index 484b3e5f..c3b1adf7 100644 --- a/launcher/src/main/java/com/italankin/lnch/feature/home/apps/popup/notifications/NotificationSwipeCallback.java +++ b/launcher/src/main/java/com/italankin/lnch/feature/home/apps/popup/notifications/NotificationSwipeCallback.java @@ -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; diff --git a/launcher/src/main/java/com/italankin/lnch/model/repository/notifications/NotificationBag.java b/launcher/src/main/java/com/italankin/lnch/model/repository/notifications/NotificationBag.java index 7fdb9ce9..167aefde 100644 --- a/launcher/src/main/java/com/italankin/lnch/model/repository/notifications/NotificationBag.java +++ b/launcher/src/main/java/com/italankin/lnch/model/repository/notifications/NotificationBag.java @@ -13,7 +13,7 @@ public class NotificationBag { final AppDescriptor descriptor; final List sbns; - private final int ongoingCount; + private final int clearableCount; private final int hashCode; NotificationBag(AppDescriptor descriptor, StatusBarNotification sbn) { @@ -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 getNotifications() { @@ -43,8 +43,8 @@ public int getCount() { return sbns.size(); } - public int getOngoingCount() { - return ongoingCount; + public int getClearableCount() { + return clearableCount; } @Override