Search in sources :

Example 1 with NotificationEvent

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());
}
Also used : NotificationManager(android.app.NotificationManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) NotificationEvent(forpdateam.ru.forpda.entity.remote.events.NotificationEvent) SuppressLint(android.annotation.SuppressLint) NotificationChannel(android.app.NotificationChannel) NotificationCompat(androidx.core.app.NotificationCompat) PendingIntent(android.app.PendingIntent)

Example 2 with NotificationEvent

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;
}
Also used : NotificationEvent(forpdateam.ru.forpda.entity.remote.events.NotificationEvent)

Example 3 with NotificationEvent

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;
}
Also used : NotificationEvent(forpdateam.ru.forpda.entity.remote.events.NotificationEvent)

Example 4 with NotificationEvent

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;
}
Also used : Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) NotificationEvent(forpdateam.ru.forpda.entity.remote.events.NotificationEvent)

Example 5 with NotificationEvent

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;
}
Also used : NotificationEvent(forpdateam.ru.forpda.entity.remote.events.NotificationEvent)

Aggregations

NotificationEvent (forpdateam.ru.forpda.entity.remote.events.NotificationEvent)8 SuppressLint (android.annotation.SuppressLint)3 NotificationChannel (android.app.NotificationChannel)2 NotificationManager (android.app.NotificationManager)2 PendingIntent (android.app.PendingIntent)2 Intent (android.content.Intent)2 NotificationCompat (androidx.core.app.NotificationCompat)2 ArrayList (java.util.ArrayList)2 Matcher (java.util.regex.Matcher)2 AlarmManager (android.app.AlarmManager)1 Service (android.app.Service)1 Context (android.content.Context)1 Resources (android.content.res.Resources)1 Bitmap (android.graphics.Bitmap)1 Uri (android.net.Uri)1 Build (android.os.Build)1 Handler (android.os.Handler)1 IBinder (android.os.IBinder)1 Message (android.os.Message)1 Messenger (android.os.Messenger)1