Search in sources :

Example 1 with SchedulersProvider

use of forpdateam.ru.forpda.model.SchedulersProvider 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)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 AlarmManager (android.app.AlarmManager)1 NotificationChannel (android.app.NotificationChannel)1 NotificationManager (android.app.NotificationManager)1 PendingIntent (android.app.PendingIntent)1 Service (android.app.Service)1 Context (android.content.Context)1 Intent (android.content.Intent)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 Log (android.util.Log)1 Toast (android.widget.Toast)1 DrawableRes (androidx.annotation.DrawableRes)1 NotificationCompat (androidx.core.app.NotificationCompat)1