Search in sources :

Example 1 with Notification

use of com.fastaccess.data.dao.model.Notification in project FastHub by k0shk0sh.

the class NotificationSchedulerJobTask method onNotifyUser.

private void onNotifyUser(@NonNull List<Notification> notificationThreadModels, JobParameters job) {
    long count = Stream.of(notificationThreadModels).filter(Notification::isUnread).count();
    if (count == 0) {
        AppHelper.cancelAllNotifications(getApplicationContext());
        finishJob(job);
        return;
    }
    Context context = getApplicationContext();
    int accentColor = ContextCompat.getColor(this, R.color.material_blue_700);
    Notification first = notificationThreadModels.get(0);
    Observable.fromIterable(notificationThreadModels).subscribeOn(Schedulers.io()).filter(notification -> notification.isUnread() && first.getId() != notification.getId() && !NotificationQueue.exists(notification.getId())).take(10).flatMap(notification -> {
        if (notification.getSubject() != null && notification.getSubject().getLatestCommentUrl() != null) {
            return RestProvider.getNotificationService(PrefGetter.isEnterprise()).getComment(notification.getSubject().getLatestCommentUrl()).subscribeOn(Schedulers.io());
        } else {
            return Observable.empty();
        }
    }, (thread, comment) -> {
        CustomNotificationModel customNotificationModel = new CustomNotificationModel();
        String url;
        if (comment != null && comment.getUser() != null) {
            url = comment.getUser().getAvatarUrl();
            if (!InputHelper.isEmpty(thread.getSubject().getLatestCommentUrl())) {
                customNotificationModel.comment = comment;
                customNotificationModel.url = url;
            }
        }
        customNotificationModel.notification = thread;
        return customNotificationModel;
    }).subscribeOn(Schedulers.io()).subscribe(custom -> {
        if (custom.comment != null) {
            getNotificationWithComment(context, accentColor, custom.notification, custom.comment, custom.url);
        } else {
            showNotificationWithoutComment(context, accentColor, custom.notification, custom.url);
        }
    }, throwable -> finishJob(job), () -> {
        if (!NotificationQueue.exists(first.getId())) {
            android.app.Notification grouped = getSummaryGroupNotification(first, accentColor, notificationThreadModels.size() > 1);
            showNotification(first.getId(), grouped);
        }
        NotificationQueue.put(notificationThreadModels).subscribe(aBoolean -> {
        /*do nothing*/
        }, Throwable::printStackTrace, () -> finishJob(job));
    });
}
Also used : Context(android.content.Context) Constraint(com.firebase.jobdispatcher.Constraint) Notification(com.fastaccess.data.dao.model.Notification)

Example 2 with Notification

use of com.fastaccess.data.dao.model.Notification in project FastHub by k0shk0sh.

the class NotificationsViewHolder method bind.

@Override
public void bind(@NonNull GroupedNotificationModel model) {
    Notification thread = model.getNotification();
    if (thread != null && thread.getSubject() != null) {
        title.setText(thread.getSubject().getTitle());
        int cardBackground = ViewHelper.getCardBackground(itemView.getContext());
        int color;
        date.setText(ParseDateFormat.getTimeAgo(thread.getUpdatedAt()));
        markAsRead.setVisibility(thread.isUnread() ? View.VISIBLE : View.GONE);
        // unSubscribe.setImageResource(thread.isIsSubscribed() ? R.drawable.ic_unsubscribe : R.drawable.ic_subscribe);
        if (thread.getSubject().getType() != null) {
            notificationType.setImageResource(thread.getSubject().getType().getDrawableRes());
            notificationType.setContentDescription(thread.getSubject().getType().name());
        } else {
            notificationType.setImageResource(R.drawable.ic_info_outline);
        }
        if (showUnreadState) {
            repoName.setVisibility(View.GONE);
            if (AppHelper.isNightMode(itemView.getResources())) {
                color = ContextCompat.getColor(itemView.getContext(), R.color.material_blue_grey_800);
            } else {
                color = ContextCompat.getColor(itemView.getContext(), R.color.material_blue_grey_200);
            }
            ((CardView) itemView).setCardBackgroundColor(thread.isUnread() ? color : cardBackground);
        } else {
            repoName.setVisibility(View.VISIBLE);
            repoName.setText(thread.getRepository().getFullName());
        }
    }
}
Also used : CardView(android.support.v7.widget.CardView) Notification(com.fastaccess.data.dao.model.Notification)

Example 3 with Notification

use of com.fastaccess.data.dao.model.Notification in project FastHub by k0shk0sh.

the class GroupedNotificationModel method construct.

@NonNull
public static List<GroupedNotificationModel> construct(@Nullable List<Notification> items) {
    List<GroupedNotificationModel> models = new ArrayList<>();
    if (items == null || items.isEmpty())
        return models;
    Map<Repo, List<Notification>> grouped = Stream.of(items).filter(value -> !value.isUnread()).collect(Collectors.groupingBy(Notification::getRepository, LinkedHashMap::new, Collectors.mapping(o -> o, toList())));
    Stream.of(grouped).filter(repoListEntry -> repoListEntry.getValue() != null && !repoListEntry.getValue().isEmpty()).forEach(repoListEntry -> {
        Repo repo = repoListEntry.getKey();
        List<Notification> notifications = repoListEntry.getValue();
        models.add(new GroupedNotificationModel(repo));
        Stream.of(notifications).sorted((o1, o2) -> o2.getUpdatedAt().compareTo(o1.getUpdatedAt())).forEach(notification -> models.add(new GroupedNotificationModel(notification)));
    });
    return models;
}
Also used : Notification(com.fastaccess.data.dao.model.Notification) Setter(lombok.Setter) Collectors(com.annimon.stream.Collectors) Stream(com.annimon.stream.Stream) Getter(lombok.Getter) Repo(com.fastaccess.data.dao.model.Repo) Date(java.util.Date) NonNull(lombok.NonNull) InputHelper(com.fastaccess.helper.InputHelper) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) Collectors.toList(com.annimon.stream.Collectors.toList) Map(java.util.Map) Nullable(android.support.annotation.Nullable) Repo(com.fastaccess.data.dao.model.Repo) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(com.annimon.stream.Collectors.toList) Notification(com.fastaccess.data.dao.model.Notification) NonNull(lombok.NonNull)

Aggregations

Notification (com.fastaccess.data.dao.model.Notification)3 Context (android.content.Context)1 Nullable (android.support.annotation.Nullable)1 CardView (android.support.v7.widget.CardView)1 Collectors (com.annimon.stream.Collectors)1 Collectors.toList (com.annimon.stream.Collectors.toList)1 Stream (com.annimon.stream.Stream)1 Repo (com.fastaccess.data.dao.model.Repo)1 InputHelper (com.fastaccess.helper.InputHelper)1 Constraint (com.firebase.jobdispatcher.Constraint)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Getter (lombok.Getter)1 NonNull (lombok.NonNull)1 Setter (lombok.Setter)1