Update notification dismissal system a bit
This commit is contained in:
parent
8a52e991fd
commit
cdde093b31
3 changed files with 37 additions and 3 deletions
|
@ -105,8 +105,9 @@ public final class NotificationManager {
|
|||
* Does nothing if it is already dismissed.
|
||||
* <p>
|
||||
* Note: Dismissing a notification does not
|
||||
* necessarily mean it removes it. Depending
|
||||
* on the {@link Notification#}
|
||||
* necessarily mean removing it. Check
|
||||
* {@link Notification#getDismissalAction()}
|
||||
* first or you might get a surprise.
|
||||
*
|
||||
* @param notification notification to update
|
||||
* @since v1-alpha6
|
||||
|
@ -119,13 +120,37 @@ public final class NotificationManager {
|
|||
case UNREGISTER -> updateNotification(notification, notifications.get(notification), true);
|
||||
case EXECUTE -> notification.dismiss();
|
||||
case EXECUTE_UNREGISTER -> {
|
||||
updateNotification(notification, NotificationState.DISMISSED_ACTIVE, false);
|
||||
notification.dismiss();
|
||||
updateNotification(notification, notifications.get(notification), true);
|
||||
updateNotification(notification, NotificationState.DISMISSED, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Frees the specified notification,
|
||||
* or all if {@code notifications} is empty.
|
||||
* <p>
|
||||
* Only works for dismissed notifications
|
||||
* which require manual freeing. See
|
||||
* {@link #dismiss(Notification)} for more information.
|
||||
*
|
||||
* @param notifications notifications to free, or all if empty
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
public static void freeDismissed(@NotNull Notification @NotNull... notifications) {
|
||||
if (notifications.length == 0)
|
||||
notifications = NotificationManager.getNotifications().keySet().toArray(new Notification[0]);
|
||||
|
||||
for (Notification notification : notifications)
|
||||
if (
|
||||
NotificationManager.getNotifications().containsKey(notification)
|
||||
&& NotificationManager.getNotifications().get(notification) == NotificationState.DISMISSED
|
||||
)
|
||||
updateNotification(notification, NotificationState.DISMISSED, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds or updates the specified notification
|
||||
* in the {@link #notifications} map.
|
||||
|
|
|
@ -237,6 +237,7 @@ public class Notification {
|
|||
* @return linked button map
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
@Setter(value = AccessLevel.NONE)
|
||||
private @NotNull LinkedHashMap<@NotNull String, @NotNull Runnable> buttons = new LinkedHashMap<>();
|
||||
|
||||
/**
|
||||
|
|
|
@ -39,6 +39,14 @@ public enum NotificationState {
|
|||
*/
|
||||
HIDDEN,
|
||||
|
||||
/**
|
||||
* A dismissed notification which
|
||||
* is still executing code.
|
||||
*
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
DISMISSED_ACTIVE,
|
||||
|
||||
/**
|
||||
* A dismissed notification.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue