Search in sources :

Example 6 with NotificationEvent

use of forpdateam.ru.forpda.entity.remote.events.NotificationEvent in project ForPDA by RadiationX.

the class NotificationsService method createStackedContent.

private CharSequence createStackedContent(List<NotificationEvent> events) {
    StringBuilder content = new StringBuilder();
    int size = Math.min(events.size(), STACKED_MAX);
    for (int i = 0; i < size; i++) {
        NotificationEvent event = events.get(i);
        if (event.fromQms()) {
            String nick = event.getUserNick();
            if (nick == null || nick.isEmpty())
                nick = "Сообщения 4PDA";
            content.append("<b>").append(nick).append("</b>");
            content.append(": ").append(event.getSourceTitle());
        } else if (event.fromTheme()) {
            content.append(event.getSourceTitle());
        }
        if (i < size - 1) {
            content.append("<br>");
        }
    }
    if (events.size() > size) {
        content.append("<br>");
        content.append("...и еще ").append(events.size() - size);
    }
    return ApiUtils.spannedFromHtml(content.toString());
}
Also used : NotificationEvent(forpdateam.ru.forpda.entity.remote.events.NotificationEvent) SuppressLint(android.annotation.SuppressLint)

Example 7 with NotificationEvent

use of forpdateam.ru.forpda.entity.remote.events.NotificationEvent in project ForPDA by RadiationX.

the class NotificationsService method sendNotification.

public void sendNotification(NotificationEvent event) {
    Log.e("kulolo", "sendNotification " + event.notifyId());
    if (notificationPreferencesHolder.getMainAvatarsEnabled()) {
        SchedulersProvider schedulers = App.get().Di().getSchedulers();
        Disposable disposable = avatarRepository.getAvatar(event.getUserId(), event.getUserNick()).flatMap((Function<String, SingleSource<Bitmap>>) s -> {
            return Single.fromCallable(() -> ImageLoader.getInstance().loadImageSync(s)).subscribeOn(schedulers.io()).observeOn(schedulers.ui());
        }).onErrorReturn(throwable -> ImageLoader.getInstance().loadImageSync("assets://av.png")).map(bitmap -> {
            if (bitmap != null) {
                Resources res = App.getContext().getResources();
                int height = (int) res.getDimension(android.R.dimen.notification_large_icon_height);
                int width = (int) res.getDimension(android.R.dimen.notification_large_icon_width);
                boolean isCircle = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
                bitmap = BitmapUtils.centerCrop(bitmap, width, height, 1.0f);
                bitmap = BitmapUtils.createAvatar(bitmap, width, height, isCircle);
            }
            return bitmap;
        }).subscribe(avatar -> sendNotification(event, avatar), Throwable::printStackTrace);
        addToDisposable(disposable);
    } else {
        sendNotification(event, null);
    }
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) Context(android.content.Context) SingleSource(io.reactivex.SingleSource) NotificationCompat(androidx.core.app.NotificationCompat) Uri(android.net.Uri) Intent(android.content.Intent) BitmapUtils(forpdateam.ru.forpda.common.BitmapUtils) PendingIntent(android.app.PendingIntent) DrawableRes(androidx.annotation.DrawableRes) EventsRepository(forpdateam.ru.forpda.model.repository.events.EventsRepository) Single(io.reactivex.Single) IBinder(android.os.IBinder) SuppressLint(android.annotation.SuppressLint) Handler(android.os.Handler) Toast(android.widget.Toast) NotificationChannel(android.app.NotificationChannel) NotificationManagerCompat(androidx.core.app.NotificationManagerCompat) Build(android.os.Build) Log(android.util.Log) NotificationPreferencesHolder(forpdateam.ru.forpda.model.preferences.NotificationPreferencesHolder) NotificationManager(android.app.NotificationManager) AlarmManager(android.app.AlarmManager) Service(android.app.Service) Messenger(android.os.Messenger) ImageLoader(com.nostra13.universalimageloader.core.ImageLoader) NotificationEvent(forpdateam.ru.forpda.entity.remote.events.NotificationEvent) SchedulersProvider(forpdateam.ru.forpda.model.SchedulersProvider) List(java.util.List) MainActivity(forpdateam.ru.forpda.ui.activities.MainActivity) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) ApiUtils(forpdateam.ru.forpda.model.data.remote.api.ApiUtils) Message(android.os.Message) Bitmap(android.graphics.Bitmap) Function(io.reactivex.functions.Function) AvatarRepository(forpdateam.ru.forpda.model.repository.avatar.AvatarRepository) App(forpdateam.ru.forpda.App) R(forpdateam.ru.forpda.R) Resources(android.content.res.Resources) Function(io.reactivex.functions.Function) Bitmap(android.graphics.Bitmap) SchedulersProvider(forpdateam.ru.forpda.model.SchedulersProvider) Resources(android.content.res.Resources)

Example 8 with NotificationEvent

use of forpdateam.ru.forpda.entity.remote.events.NotificationEvent in project ForPDA by RadiationX.

the class NotificationEventsApi method getFavoritesEvents.

public List<NotificationEvent> getFavoritesEvents(String response) {
    List<NotificationEvent> events = new ArrayList<>();
    Matcher matcher = inspectorFavoritesPattern.matcher(response);
    while (matcher.find()) {
        // Log.e("events_lalala", "Matcher add event: " + matcher.group());
        NotificationEvent event = getFavoritesEvent(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)

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