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));
});
}
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());
}
}
}
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;
}
Aggregations