|
|
|
@ -3,13 +3,14 @@ package com.fr.design.notification;
|
|
|
|
|
|
|
|
|
|
import com.fr.design.notification.ui.NotificationCenterPane; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.Collections; |
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
public class NotificationCenter { |
|
|
|
|
private static NotificationCenter notificationCenter = new NotificationCenter(); |
|
|
|
|
private List<Notification> notifications; |
|
|
|
|
private NotificationCenter(){ |
|
|
|
|
notifications = new ArrayList<>(); |
|
|
|
|
notifications = Collections.synchronizedList(new ArrayList<>()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static NotificationCenter getInstance(){ |
|
|
|
@ -17,8 +18,10 @@ public class NotificationCenter {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void addNotification(Notification message){ |
|
|
|
|
notifications.add(message); |
|
|
|
|
NotificationCenterPane.getNotificationCenterPane().refreshButton(); |
|
|
|
|
synchronized (this) { |
|
|
|
|
notifications.add(message); |
|
|
|
|
NotificationCenterPane.getNotificationCenterPane().refreshButton(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public int getNotificationsCount(){ |
|
|
|
@ -26,17 +29,21 @@ public class NotificationCenter {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void removeNotification(int index){ |
|
|
|
|
notifications.remove(index); |
|
|
|
|
NotificationCenterPane.getNotificationCenterPane().refreshButton(); |
|
|
|
|
synchronized (this) { |
|
|
|
|
notifications.remove(index); |
|
|
|
|
NotificationCenterPane.getNotificationCenterPane().refreshButton(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Notification getNotification(int index){ |
|
|
|
|
return notifications.get(index); |
|
|
|
|
return notifications.get(index); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void clearAllNotifications(){ |
|
|
|
|
notifications.clear(); |
|
|
|
|
NotificationCenterPane.getNotificationCenterPane().refreshButton(); |
|
|
|
|
synchronized (this) { |
|
|
|
|
notifications.clear(); |
|
|
|
|
NotificationCenterPane.getNotificationCenterPane().refreshButton(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|