use of forpdateam.ru.forpda.api.favorites.interfaces.IFavItem in project ForPDA by RadiationX.
the class FavoritesPresenter method handleEvent.
@Override
public void handleEvent(TabNotification event, Sorting sorting, int count) {
if (event.isWebSocket() && event.getEvent().isNew())
return;
RealmResults<FavItemBd> results = realm.where(FavItemBd.class).findAll();
ArrayList<IFavItem> currentItems = new ArrayList<>();
for (FavItemBd itemBd : results) {
currentItems.add(new FavItem(itemBd));
}
NotificationEvent loadedEvent = event.getEvent();
int id = loadedEvent.getSourceId();
boolean isRead = loadedEvent.isRead();
if (isRead) {
count--;
for (IFavItem item : currentItems) {
if (item.getTopicId() == id) {
item.setNew(false);
break;
}
}
} else {
count = event.getLoadedEvents().size();
for (IFavItem item : currentItems) {
if (item.getTopicId() == id) {
if (item.getLastUserId() != ClientHelper.getUserId())
item.setNew(true);
item.setLastUserNick(loadedEvent.getUserNick());
item.setLastUserId(loadedEvent.getUserId());
item.setPin(loadedEvent.isImportant());
break;
}
}
if (sorting.getKey().equals(Sorting.Key.TITLE)) {
Collections.sort(currentItems, (o1, o2) -> {
if (sorting.getOrder().equals(Sorting.Order.ASC))
return o1.getTopicTitle().compareToIgnoreCase(o2.getTopicTitle());
return o2.getTopicTitle().compareToIgnoreCase(o1.getTopicTitle());
});
}
if (sorting.getKey().equals(Sorting.Key.LAST_POST)) {
for (IFavItem item : currentItems) {
if (item.getTopicId() == id) {
currentItems.remove(item);
int index = 0;
if (sorting.getOrder().equals(Sorting.Order.ASC)) {
index = currentItems.size();
}
currentItems.add(index, item);
break;
}
}
}
}
view.onHandleEvent(count);
}
Aggregations