use of forpdateam.ru.forpda.entity.remote.events.NotificationEvent in project ForPDA by RadiationX.
the class NotificationsService method sendNotifications.
public void sendNotifications(List<NotificationEvent> events) {
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);
NotificationManager manager = getSystemService(NotificationManager.class);
if (manager != null) {
manager.createNotificationChannel(channel);
}
}
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, channelId);
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;
}
getNotificationManager().notify(id, builder.build());
}
use of forpdateam.ru.forpda.entity.remote.events.NotificationEvent in project ForPDA by RadiationX.
the class NotificationEventsApi method parseWebSocketEvent.
public NotificationEvent parseWebSocketEvent(Matcher matcher) {
NotificationEvent wsEvent = null;
if (matcher.find()) {
wsEvent = new NotificationEvent(NotificationEvent.Type.NEW, NotificationEvent.Source.THEME);
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;
}
use of forpdateam.ru.forpda.entity.remote.events.NotificationEvent in project ForPDA by RadiationX.
the class NotificationEventsApi method getFavoritesEvent.
public NotificationEvent getFavoritesEvent(Matcher matcher) {
NotificationEvent event = new NotificationEvent(NotificationEvent.Type.NEW, NotificationEvent.Source.THEME);
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;
}
use of forpdateam.ru.forpda.entity.remote.events.NotificationEvent in project ForPDA by RadiationX.
the class NotificationEventsApi 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;
}
use of forpdateam.ru.forpda.entity.remote.events.NotificationEvent in project ForPDA by RadiationX.
the class NotificationEventsApi method getQmsEvent.
public NotificationEvent getQmsEvent(Matcher matcher) {
NotificationEvent event = new NotificationEvent(NotificationEvent.Type.NEW, NotificationEvent.Source.QMS);
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