Skip to content

Commit

Permalink
Use Hashmap instead of ConcurrentHashmap as Notifications storage (#2847
Browse files Browse the repository at this point in the history
)
  • Loading branch information
keianhzo committed Feb 24, 2020
1 parent f354bf0 commit eebab02
Showing 1 changed file with 15 additions and 11 deletions.
Expand Up @@ -14,15 +14,15 @@
import org.mozilla.vrbrowser.ui.views.UIButton;
import org.mozilla.vrbrowser.ui.widgets.NotificationManager.Notification.NotificationPosition;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class NotificationManager {

private static final int DEFAULT_DURATION = 3000;

private static ConcurrentHashMap<Integer, NotificationData> mData = new ConcurrentHashMap<>();
private static HashMap<Integer, NotificationData> mData = new HashMap<>();

private static class NotificationData {

Expand Down Expand Up @@ -178,22 +178,26 @@ public static void hide(int notificationId) {

NotificationData data = mData.get(notificationId);
if (data != null && data.mNotificationView.isVisible()) {
ThreadUtils.removeCallbacksFromUiThread(data.mHideTask);

data.mNotificationView.hide(UIWidget.REMOVE_WIDGET);

if (data.mNotification.mView instanceof UIButton) {
((UIButton)data.mNotification.mView).setNotificationMode(false);
}

hideNotification(data);
mData.remove(notificationId);
}
}

public static void hideAll() {
Iterator<Map.Entry<Integer, NotificationData>> it = mData.entrySet().iterator();
while (it.hasNext()) {
hide(it.next().getKey());
hideNotification(it.next().getValue());
it.remove();
}
}

private static void hideNotification(@NonNull NotificationData data) {
ThreadUtils.removeCallbacksFromUiThread(data.mHideTask);

data.mNotificationView.hide(UIWidget.REMOVE_WIDGET);

if (data.mNotification.mView instanceof UIButton) {
((UIButton)data.mNotification.mView).setNotificationMode(false);
}
}

Expand Down

0 comments on commit eebab02

Please sign in to comment.