use of forpdateam.ru.forpda.api.events.models.NotificationEvent 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);
}
use of forpdateam.ru.forpda.api.events.models.NotificationEvent in project ForPDA by RadiationX.
the class NotificationsService method sendNotifications.
public void sendNotifications(List<NotificationEvent> events, NotificationEvent.Source tSource) {
if (events.isEmpty()) {
return;
}
if (events.size() <= STACKED_MAX) {
for (NotificationEvent event : events) {
sendNotification(event);
}
return;
}
if (!checkNotify(null, tSource)) {
return;
}
String title = createStackedTitle(events);
CharSequence text = createStackedContent(events);
String summaryText = createStackedSummary(events);
NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
bigTextStyle.setBigContentTitle(title);
bigTextStyle.bigText(text);
bigTextStyle.setSummaryText(summaryText);
String channelId = getChannelId(events.get(0));
String channelName = getChannelName(events.get(0));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_DEFAULT);
getSystemService(NotificationManager.class).createNotificationChannel(channel);
}
NotificationCompat.Builder builder;
builder = new NotificationCompat.Builder(this);
builder.setSmallIcon(createStackedSmallIcon(events));
builder.setContentTitle(title);
builder.setContentText(text);
builder.setStyle(bigTextStyle);
builder.setChannelId(channelId);
Intent notifyIntent = new Intent(this, MainActivity.class);
notifyIntent.setData(Uri.parse(createStackedIntentUrl(events)));
notifyIntent.setAction(Intent.ACTION_VIEW);
PendingIntent notifyPendingIntent = PendingIntent.getActivity(this, 0, notifyIntent, 0);
builder.setContentIntent(notifyPendingIntent);
configureNotification(builder);
int id = 0;
NotificationEvent event = events.get(0);
if (event.fromQms()) {
id = NOTIFY_STACKED_QMS_ID;
} else if (event.fromTheme()) {
id = NOTIFY_STACKED_FAV_ID;
}
mNotificationManager.notify(id, builder.build());
}
use of forpdateam.ru.forpda.api.events.models.NotificationEvent in project ForPDA by RadiationX.
the class NotificationsService method handlePendingEvents.
private void handlePendingEvents(NotificationEvent.Source source) {
SparseArray<NotificationEvent> pending = pendingEvents.get(source);
if (pending != null && pending.size() > 0) {
List<NotificationEvent> events = new ArrayList<>();
for (int i = 0; i < pending.size(); i++) {
events.add(pending.valueAt(i));
}
hardHandleEvent(events, source);
pending.clear();
}
}
use of forpdateam.ru.forpda.api.events.models.NotificationEvent in project ForPDA by RadiationX.
the class NotificationsService method saveEvents.
private void saveEvents(List<NotificationEvent> loadedEvents, NotificationEvent.Source source) {
String prefKey = "";
if (NotificationEvent.fromQms(source)) {
prefKey = Preferences.Notifications.Data.QMS_EVENTS;
} else if (NotificationEvent.fromTheme(source)) {
prefKey = Preferences.Notifications.Data.FAVORITES_EVENTS;
}
Set<String> savedEvents = new ArraySet<>();
for (NotificationEvent event : loadedEvents) {
savedEvents.add(event.getSourceEventText());
}
App.get().getPreferences().edit().putStringSet(prefKey, savedEvents).apply();
}
use of forpdateam.ru.forpda.api.events.models.NotificationEvent in project ForPDA by RadiationX.
the class NotificationEvents method getQmsEvent.
public NotificationEvent getQmsEvent(Matcher matcher) {
NotificationEvent event = new NotificationEvent();
event.setSourceEventText(matcher.group());
event.setSource(NotificationEvent.Source.QMS);
event.setType(NotificationEvent.Type.NEW);
event.setSourceId(Integer.parseInt(matcher.group(1)));
event.setSourceTitle(ApiUtils.fromHtml(matcher.group(2)));
event.setUserId(Integer.parseInt(matcher.group(3)));
event.setUserNick(ApiUtils.fromHtml(matcher.group(4)));
event.setTimeStamp(Integer.parseInt(matcher.group(5)));
event.setMsgCount(Integer.parseInt(matcher.group(6)));
if (event.getUserNick().isEmpty() && event.getSourceId() == 0) {
event.setUserNick("Сообщения 4PDA");
}
return event;
}
Aggregations