use of com.meisolsson.githubsdk.model.NotificationThread in project PocketHub by pockethub.
the class NotificationListFragment method updateHeaders.
private void updateHeaders(final List<Item> notifications) {
if (notifications.isEmpty()) {
return;
}
Collections.sort(notifications, (i1, i2) -> {
Repository r1 = ((NotificationItem) i1).getNotificationThread().repository();
Repository r2 = ((NotificationItem) i2).getNotificationThread().repository();
return r1.fullName().compareToIgnoreCase(r2.fullName());
});
Repository repoFound = null;
for (int i = 0; i < notifications.size(); i++) {
NotificationItem item = (NotificationItem) notifications.get(i);
NotificationThread thread = item.getNotificationThread();
String fullName = thread.repository().fullName();
if (repoFound == null || !fullName.equals(repoFound.fullName())) {
notifications.add(i, new NotificationHeaderItem(thread.repository(), this));
}
repoFound = thread.repository();
}
}
use of com.meisolsson.githubsdk.model.NotificationThread in project gh4a by slapperwan.
the class NotificationListFragment method unsubscribe.
@Override
public void unsubscribe(NotificationHolder notificationHolder) {
NotificationThread notification = notificationHolder.notification;
NotificationService service = ServiceFactory.get(NotificationService.class, false);
SubscriptionRequest request = SubscriptionRequest.builder().subscribed(false).build();
service.setNotificationThreadSubscription(notification.id(), request).map(ApiHelpers::throwOnFailure).compose(RxUtils::doInBackground).subscribe(result -> handleMarkAsRead(null, notification));
}
use of com.meisolsson.githubsdk.model.NotificationThread in project gh4a by slapperwan.
the class SingleFactory method notificationsToResult.
private static NotificationListLoadResult notificationsToResult(List<NotificationThread> notifications) {
// group notifications by repo
final HashMap<Repository, ArrayList<NotificationThread>> notificationsByRepo = new HashMap<>();
for (NotificationThread n : notifications) {
ArrayList<NotificationThread> list = notificationsByRepo.get(n.repository());
if (list == null) {
list = new ArrayList<>();
notificationsByRepo.put(n.repository(), list);
}
list.add(n);
}
// sort each group by updatedAt
for (ArrayList<NotificationThread> list : notificationsByRepo.values()) {
Collections.sort(list, (lhs, rhs) -> rhs.updatedAt().compareTo(lhs.updatedAt()));
}
// sort groups by updatedAt of top notification
ArrayList<Repository> reposByTimestamp = new ArrayList<>(notificationsByRepo.keySet());
Collections.sort(reposByTimestamp, (lhs, rhs) -> {
NotificationThread lhsNotification = notificationsByRepo.get(lhs).get(0);
NotificationThread rhsNotification = notificationsByRepo.get(rhs).get(0);
return rhsNotification.updatedAt().compareTo(lhsNotification.updatedAt());
});
// add to list
List<NotificationHolder> result = new ArrayList<>();
for (Repository repo : reposByTimestamp) {
ArrayList<NotificationThread> notifsForRepo = notificationsByRepo.get(repo);
boolean hasUnread = false;
int count = notifsForRepo.size();
NotificationHolder repoItem = new NotificationHolder(repo);
result.add(repoItem);
for (int i = 0; i < count; i++) {
NotificationHolder item = new NotificationHolder(notifsForRepo.get(i));
hasUnread |= item.notification.unread();
item.setIsLastRepositoryNotification(i == count - 1);
result.add(item);
}
repoItem.setIsRead(!hasUnread);
}
return new NotificationListLoadResult(result);
}
use of com.meisolsson.githubsdk.model.NotificationThread in project gh4a by slapperwan.
the class NotificationsJob method showSummaryNotification.
private void showSummaryNotification(NotificationManagerCompat nm, List<List<NotificationThread>> notificationsPerRepo, boolean hasNewNotification) {
int totalCount = 0;
for (List<NotificationThread> list : notificationsPerRepo) {
totalCount += list.size();
}
String title = getContext().getString(R.string.unread_notifications_summary_title);
String text = getContext().getResources().getQuantityString(R.plurals.unread_notifications_summary_text, totalCount, totalCount);
Notification publicVersion = makeBaseBuilder().setContentTitle(title).setContentText(text).setNumber(totalCount).setVisibility(NotificationCompat.VISIBILITY_PUBLIC).build();
PendingIntent contentIntent = PendingIntent.getActivity(getContext(), 0, HomeActivity.makeIntent(getContext(), R.id.notifications), 0);
PendingIntent deleteIntent = PendingIntent.getService(getContext(), 0, NotificationHandlingService.makeMarkNotificationsSeenIntent(getContext()), 0);
NotificationCompat.Builder builder = makeBaseBuilder().setGroup(GROUP_ID_GITHUB).setGroupSummary(true).setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_SUMMARY).setContentIntent(contentIntent).setDeleteIntent(deleteIntent).setContentTitle(title).setContentText(text).setPublicVersion(publicVersion).setVisibility(NotificationCompat.VISIBILITY_PRIVATE).setDefaults(NotificationCompat.DEFAULT_ALL).setNumber(totalCount);
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(builder).setBigContentTitle(text);
for (List<NotificationThread> list : notificationsPerRepo) {
Repository repository = list.get(0).repository();
String repoName = repository.owner().login() + "/" + repository.name();
final TextAppearanceSpan notificationPrimarySpan = new TextAppearanceSpan(getContext(), R.style.TextAppearance_NotificationEmphasized);
final int emphasisEnd;
SpannableStringBuilder line = new SpannableStringBuilder(repoName).append(" ");
if (list.size() == 1) {
NotificationThread n = list.get(0);
line.append(determineNotificationTypeLabel(n));
emphasisEnd = line.length();
line.append(" ").append(n.subject().title());
} else {
emphasisEnd = line.length();
line.append(getContext().getResources().getQuantityString(R.plurals.notification, list.size(), list.size()));
}
line.setSpan(notificationPrimarySpan, 0, emphasisEnd, SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
inboxStyle.addLine(line);
}
builder.setStyle(inboxStyle);
if (!hasNewNotification) {
builder.setOnlyAlertOnce(true);
}
nm.notify(0, builder.build());
}
use of com.meisolsson.githubsdk.model.NotificationThread in project PocketHub by pockethub.
the class NotificationListFragment method onItemClick.
@Override
public void onItemClick(@NonNull Item item, @NonNull View view) {
if (item instanceof NotificationItem) {
NotificationThread thread = ((NotificationItem) item).getNotificationThread();
String url = thread.subject().url();
Issue issue = IssueUriMatcher.getApiIssue(url);
if (issue != null) {
Intent intent = IssuesViewActivity.createIntent(issue, thread.repository());
startActivity(intent);
} else {
ToastUtils.show(getActivity(), R.string.releases_not_yet_in_app);
}
}
}
Aggregations