Search in sources :

Example 1 with TabNotification

use of forpdateam.ru.forpda.data.models.TabNotification in project ForPDA by RadiationX.

the class NotificationsService method hardHandleEvent.

private void hardHandleEvent(List<NotificationEvent> events, NotificationEvent.Source source) {
    Log.d("SUKA", "hardHandleEvent " + events.size() + " : " + source);
    if (NotificationEvent.fromSite(source)) {
        if (Preferences.Notifications.Mentions.isEnabled(getApplicationContext())) {
            for (NotificationEvent event : events) {
                sendNotification(event);
            }
        }
        return;
    }
    loadEvents(loadedEvents -> {
        List<NotificationEvent> savedEvents = getSavedEvents(source);
        // savedEvents = new ArrayList<>();
        saveEvents(loadedEvents, source);
        List<NotificationEvent> newEvents = compareEvents(savedEvents, loadedEvents, events, source);
        List<NotificationEvent> stackedNewEvents = new ArrayList<>(newEvents);
        checkOldEvents(loadedEvents, source);
        // Удаляем из общего уведомления текущие уведомление
        for (NotificationEvent event : events) {
            for (NotificationEvent newEvent : newEvents) {
                if (newEvent.getSourceId() == event.getSourceId()) {
                    stackedNewEvents.remove(newEvent);
                    newEvent.setType(event.getType());
                    newEvent.setMessageId(event.getMessageId());
                    TabNotification tabNotification = new TabNotification();
                    tabNotification.setType(newEvent.getType());
                    tabNotification.setSource(newEvent.getSource());
                    tabNotification.setEvent(newEvent);
                    tabNotification.getLoadedEvents().addAll(loadedEvents);
                    tabNotification.getNewEvents().addAll(newEvents);
                    tabNotification.setWebSocket(false);
                    notifyTabs(tabNotification);
                    sendNotification(newEvent);
                } else if (event.isMention() && !Preferences.Notifications.Favorites.isEnabled(getApplicationContext())) {
                    stackedNewEvents.remove(newEvent);
                }
            }
        }
        sendNotifications(stackedNewEvents, source);
    }, source);
}
Also used : TabNotification(forpdateam.ru.forpda.data.models.TabNotification) ArrayList(java.util.ArrayList) NotificationEvent(forpdateam.ru.forpda.api.events.models.NotificationEvent)

Example 2 with TabNotification

use of forpdateam.ru.forpda.data.models.TabNotification in project ForPDA by RadiationX.

the class NotificationsService method handleWebSocketEvent.

private void handleWebSocketEvent(NotificationEvent event) {
    TabNotification tabNotification = new TabNotification();
    tabNotification.setType(event.getType());
    tabNotification.setSource(event.getSource());
    tabNotification.setEvent(event);
    tabNotification.setWebSocket(true);
    notifyTabs(tabNotification);
    if (event.isRead()) {
        checkOldEvent(event);
        return;
    }
    List<NotificationEvent> events = new ArrayList<>();
    events.add(event);
    handleEvent(events, event.getSource());
}
Also used : TabNotification(forpdateam.ru.forpda.data.models.TabNotification) ArrayList(java.util.ArrayList) NotificationEvent(forpdateam.ru.forpda.api.events.models.NotificationEvent)

Example 3 with TabNotification

use of forpdateam.ru.forpda.data.models.TabNotification in project ForPDA by RadiationX.

the class NotificationsService method checkOldEvents.

private void checkOldEvents(List<NotificationEvent> loadedEvents, NotificationEvent.Source source) {
    List<NotificationEvent> oldEvents = new ArrayList<>();
    for (int i = 0; i < eventsHistory.size(); i++) {
        NotificationEvent event = eventsHistory.valueAt(i);
        if (event.getSource() == source) {
            oldEvents.add(event);
        }
    }
    for (NotificationEvent oldEvent : oldEvents) {
        boolean exist = false;
        for (NotificationEvent loadedEvent : loadedEvents) {
            if (oldEvent.getSourceId() == loadedEvent.getSourceId()) {
                exist = true;
                break;
            }
        }
        if (!exist) {
            mNotificationManager.cancel(oldEvent.notifyId());
            eventsHistory.remove(oldEvent.notifyId(NotificationEvent.Type.NEW));
            TabNotification tabNotification = new TabNotification();
            tabNotification.setSource(oldEvent.getSource());
            tabNotification.setEvent(oldEvent);
            tabNotification.setType(NotificationEvent.Type.READ);
            tabNotification.setWebSocket(true);
            notifyTabs(tabNotification);
        }
    }
}
Also used : TabNotification(forpdateam.ru.forpda.data.models.TabNotification) ArrayList(java.util.ArrayList) NotificationEvent(forpdateam.ru.forpda.api.events.models.NotificationEvent) SuppressLint(android.annotation.SuppressLint)

Aggregations

NotificationEvent (forpdateam.ru.forpda.api.events.models.NotificationEvent)3 TabNotification (forpdateam.ru.forpda.data.models.TabNotification)3 ArrayList (java.util.ArrayList)3 SuppressLint (android.annotation.SuppressLint)1