Search in sources :

Example 11 with NotificationEvent

use of forpdateam.ru.forpda.api.events.models.NotificationEvent in project ForPDA by RadiationX.

the class NotificationEvents method getQmsEvents.

public List<NotificationEvent> getQmsEvents(String response) {
    List<NotificationEvent> events = new ArrayList<>();
    Matcher matcher = inspectorQmsPattern.matcher(response);
    while (matcher.find()) {
        NotificationEvent event = getQmsEvent(matcher);
        events.add(event);
    }
    return events;
}
Also used : Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) NotificationEvent(forpdateam.ru.forpda.api.events.models.NotificationEvent)

Example 12 with NotificationEvent

use of forpdateam.ru.forpda.api.events.models.NotificationEvent in project ForPDA by RadiationX.

the class NotificationsService method checkOldEvent.

private void checkOldEvent(NotificationEvent event) {
    NotificationEvent oldEvent = eventsHistory.get(event.notifyId(NotificationEvent.Type.NEW));
    boolean delete = false;
    if (event.fromTheme()) {
        // Убираем уведомления избранного
        if (oldEvent != null && event.getMessageId() >= oldEvent.getMessageId()) {
            mNotificationManager.cancel(oldEvent.notifyId());
            delete = true;
        }
        // Убираем уведомление упоминаний
        oldEvent = eventsHistory.get(event.notifyId(NotificationEvent.Type.MENTION));
        if (oldEvent != null) {
            mNotificationManager.cancel(oldEvent.notifyId());
            delete = true;
        }
    } else if (event.fromQms()) {
        // Убираем уведомление кумыса
        if (oldEvent != null) {
            mNotificationManager.cancel(oldEvent.notifyId());
            delete = true;
        }
    }
    if (delete) {
        eventsHistory.remove(event.notifyId(NotificationEvent.Type.NEW));
    }
}
Also used : NotificationEvent(forpdateam.ru.forpda.api.events.models.NotificationEvent)

Example 13 with NotificationEvent

use of forpdateam.ru.forpda.api.events.models.NotificationEvent 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 14 with NotificationEvent

use of forpdateam.ru.forpda.api.events.models.NotificationEvent in project ForPDA by RadiationX.

the class NotificationsService method createStackedContent.

private CharSequence createStackedContent(List<NotificationEvent> events) {
    StringBuilder content = new StringBuilder();
    int size = Math.min(events.size(), STACKED_MAX);
    for (int i = 0; i < size; i++) {
        NotificationEvent event = events.get(i);
        if (event.fromQms()) {
            String nick = event.getUserNick();
            if (nick == null || nick.isEmpty())
                nick = "Сообщения 4PDA";
            content.append("<b>").append(nick).append("</b>");
            content.append(": ").append(event.getSourceTitle());
        } else if (event.fromTheme()) {
            content.append(event.getSourceTitle());
        }
        if (i < size - 1) {
            content.append("<br>");
        }
    }
    if (events.size() > size) {
        content.append("<br>");
        content.append("...и еще ").append(events.size() - size);
    }
    return ApiUtils.spannedFromHtml(content.toString());
}
Also used : NotificationEvent(forpdateam.ru.forpda.api.events.models.NotificationEvent) SuppressLint(android.annotation.SuppressLint)

Example 15 with NotificationEvent

use of forpdateam.ru.forpda.api.events.models.NotificationEvent 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)

Aggregations

NotificationEvent (forpdateam.ru.forpda.api.events.models.NotificationEvent)18 ArrayList (java.util.ArrayList)10 SuppressLint (android.annotation.SuppressLint)4 TabNotification (forpdateam.ru.forpda.data.models.TabNotification)3 SparseIntArray (android.util.SparseIntArray)2 QmsContactBd (forpdateam.ru.forpda.data.realm.qms.QmsContactBd)2 QmsThemeBd (forpdateam.ru.forpda.data.realm.qms.QmsThemeBd)2 QmsThemesBd (forpdateam.ru.forpda.data.realm.qms.QmsThemesBd)2 Matcher (java.util.regex.Matcher)2 NotificationChannel (android.app.NotificationChannel)1 NotificationManager (android.app.NotificationManager)1 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 NotificationCompat (android.support.v4.app.NotificationCompat)1 ArraySet (android.support.v4.util.ArraySet)1 IFavItem (forpdateam.ru.forpda.api.favorites.interfaces.IFavItem)1 FavItem (forpdateam.ru.forpda.api.favorites.models.FavItem)1 IQmsContact (forpdateam.ru.forpda.api.qms.interfaces.IQmsContact)1 IQmsTheme (forpdateam.ru.forpda.api.qms.interfaces.IQmsTheme)1 QmsContact (forpdateam.ru.forpda.api.qms.models.QmsContact)1