Search in sources :

Example 1 with NotificationEvent

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

the class NotificationEvents method parseWebSocketEvent.

public NotificationEvent parseWebSocketEvent(Matcher matcher) {
    NotificationEvent wsEvent = null;
    if (matcher.find()) {
        wsEvent = new NotificationEvent();
        switch(matcher.group(3)) {
            case NotificationEvent.SRC_TYPE_THEME:
                wsEvent.setSource(NotificationEvent.Source.THEME);
                break;
            case NotificationEvent.SRC_TYPE_SITE:
                wsEvent.setSource(NotificationEvent.Source.SITE);
                break;
            case NotificationEvent.SRC_TYPE_QMS:
                wsEvent.setSource(NotificationEvent.Source.QMS);
                break;
            default:
                // // TODO: 02.10.17 сделать обратку нотификации форума
                return null;
        }
        wsEvent.setSourceId(Integer.parseInt(matcher.group(4)));
        switch(Integer.parseInt(matcher.group(5))) {
            case NotificationEvent.SRC_EVENT_NEW:
                wsEvent.setType(NotificationEvent.Type.NEW);
                break;
            case NotificationEvent.SRC_EVENT_READ:
                wsEvent.setType(NotificationEvent.Type.READ);
                break;
            case NotificationEvent.SRC_EVENT_MENTION:
                wsEvent.setType(NotificationEvent.Type.MENTION);
                break;
            case NotificationEvent.SRC_EVENT_HAT_EDITED:
                wsEvent.setType(NotificationEvent.Type.HAT_EDITED);
                break;
        }
        wsEvent.setMessageId(Integer.parseInt(matcher.group(6)));
    }
    return wsEvent;
}
Also used : NotificationEvent(forpdateam.ru.forpda.api.events.models.NotificationEvent)

Example 2 with NotificationEvent

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

the class NotificationEvents method getFavoritesEvents.

public List<NotificationEvent> getFavoritesEvents(String response) {
    List<NotificationEvent> events = new ArrayList<>();
    Matcher matcher = inspectorFavoritesPattern.matcher(response);
    while (matcher.find()) {
        NotificationEvent event = getFavoritesEvent(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 3 with NotificationEvent

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

the class NotificationEvents method getFavoritesEvent.

public NotificationEvent getFavoritesEvent(Matcher matcher) {
    NotificationEvent event = new NotificationEvent();
    event.setSourceEventText(matcher.group());
    event.setSource(NotificationEvent.Source.THEME);
    event.setType(NotificationEvent.Type.NEW);
    event.setSourceId(Integer.parseInt(matcher.group(1)));
    event.setSourceTitle(ApiUtils.fromHtml(matcher.group(2)));
    event.setMsgCount(Integer.parseInt(matcher.group(3)));
    event.setUserId(Integer.parseInt(matcher.group(4)));
    event.setUserNick(ApiUtils.fromHtml(matcher.group(5)));
    event.setTimeStamp(Integer.parseInt(matcher.group(6)));
    event.setLastTimeStamp(Integer.parseInt(matcher.group(7)));
    event.setImportant(matcher.group(8).equals("1"));
    return event;
}
Also used : NotificationEvent(forpdateam.ru.forpda.api.events.models.NotificationEvent)

Example 4 with NotificationEvent

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

the class QmsContactsFragment method handleEvent.

private void handleEvent(TabNotification event) {
    bindView();
    if (true)
        return;
    SparseIntArray sparseArray = new SparseIntArray();
    if (realm.isClosed())
        return;
    results = realm.where(QmsContactBd.class).findAll();
    ArrayList<QmsContact> currentItems = new ArrayList<>();
    for (QmsContactBd qmsContactBd : results) {
        QmsContact contact = new QmsContact(qmsContactBd);
        currentItems.add(contact);
    }
    for (NotificationEvent loadedEvent : event.getLoadedEvents()) {
        int count = sparseArray.get(loadedEvent.getUserId());
        count += loadedEvent.getMsgCount();
        sparseArray.put(loadedEvent.getUserId(), count);
    }
    for (int i = sparseArray.size() - 1; i >= 0; i--) {
        int id = sparseArray.keyAt(i);
        int count = sparseArray.valueAt(i);
        for (QmsContact item : currentItems) {
            if (item.getId() == id) {
                item.setCount(count);
                Collections.swap(currentItems, currentItems.indexOf(item), 0);
                break;
            }
        }
    }
    if (realm.isClosed())
        return;
    realm.executeTransactionAsync(r -> {
        r.delete(QmsContactBd.class);
        List<QmsContactBd> bdList = new ArrayList<>();
        for (QmsContact qmsContact : currentItems) {
            bdList.add(new QmsContactBd(qmsContact));
        }
        r.copyToRealmOrUpdate(bdList);
        bdList.clear();
    }, this::bindView);
// adapter.notifyDataSetChanged();
/*ArrayList<IFavItem> newItems = new ArrayList<>();
        newItems.addAll(currentItems);
        refreshList(newItems);*/
}
Also used : SparseIntArray(android.util.SparseIntArray) ArrayList(java.util.ArrayList) NotificationEvent(forpdateam.ru.forpda.api.events.models.NotificationEvent) IQmsContact(forpdateam.ru.forpda.api.qms.interfaces.IQmsContact) QmsContact(forpdateam.ru.forpda.api.qms.models.QmsContact) QmsContactBd(forpdateam.ru.forpda.data.realm.qms.QmsContactBd)

Example 5 with NotificationEvent

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

the class QmsHelper method handleEvent.

private void handleEvent(TabNotification event) {
    Realm realm = Realm.getDefaultInstance();
    RealmResults<QmsThemesBd> themes = realm.where(QmsThemesBd.class).findAll();
    QmsThemeBd targetTheme = null;
    QmsThemesBd targetDialog = null;
    for (QmsThemesBd dialog : themes) {
        for (QmsThemeBd theme : dialog.getThemes()) {
            if (theme.getId() == event.getEvent().getSourceId()) {
                targetDialog = dialog;
                targetTheme = theme;
                break;
            }
        }
        if (targetTheme != null) {
            break;
        }
    }
    if (targetTheme != null) {
        QmsThemeBd finalTargetTheme = targetTheme;
        QmsThemesBd finalTargetDialog = targetDialog;
        realm.executeTransaction(realm1 -> {
            if (event.isWebSocket()) {
                if (NotificationEvent.isRead(event.getType())) {
                    finalTargetTheme.setCountNew(0);
                }
            } else {
                if (NotificationEvent.isNew(event.getType())) {
                    finalTargetTheme.setCountNew(event.getEvent().getMsgCount());
                }
            }
            QmsContactBd contact = realm1.where(QmsContactBd.class).equalTo("id", finalTargetDialog.getUserId()).findFirst();
            if (contact != null) {
                int count = 0;
                for (QmsThemeBd theme : finalTargetDialog.getThemes()) {
                    count += theme.getCountNew();
                }
                contact.setCount(count);
            }
        });
    }
    int globalCount = 0;
    for (NotificationEvent ev : event.getLoadedEvents()) {
        globalCount += ev.getMsgCount();
    }
    ClientHelper.setQmsCount(globalCount);
    ClientHelper.get().notifyCountsChanged();
    realm.close();
    notifyQms(event);
}
Also used : QmsThemesBd(forpdateam.ru.forpda.data.realm.qms.QmsThemesBd) QmsThemeBd(forpdateam.ru.forpda.data.realm.qms.QmsThemeBd) NotificationEvent(forpdateam.ru.forpda.api.events.models.NotificationEvent) Realm(io.realm.Realm) QmsContactBd(forpdateam.ru.forpda.data.realm.qms.QmsContactBd)

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