Search in sources :

Example 1 with NotificationThread

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();
    }
}
Also used : Repository(com.meisolsson.githubsdk.model.Repository) NotificationItem(com.github.pockethub.android.ui.item.notification.NotificationItem) NotificationThread(com.meisolsson.githubsdk.model.NotificationThread) NotificationHeaderItem(com.github.pockethub.android.ui.item.notification.NotificationHeaderItem)

Example 2 with NotificationThread

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));
}
Also used : SubscriptionRequest(com.meisolsson.githubsdk.model.request.activity.SubscriptionRequest) NotificationThread(com.meisolsson.githubsdk.model.NotificationThread) ApiHelpers(com.gh4a.utils.ApiHelpers) NotificationService(com.meisolsson.githubsdk.service.activity.NotificationService)

Example 3 with NotificationThread

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);
}
Also used : NotificationThread(com.meisolsson.githubsdk.model.NotificationThread) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) NotificationHolder(com.gh4a.model.NotificationHolder) Repository(com.meisolsson.githubsdk.model.Repository) NotificationListLoadResult(com.gh4a.model.NotificationListLoadResult)

Example 4 with NotificationThread

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());
}
Also used : Repository(com.meisolsson.githubsdk.model.Repository) NotificationThread(com.meisolsson.githubsdk.model.NotificationThread) TextAppearanceSpan(android.text.style.TextAppearanceSpan) NotificationCompat(android.support.v4.app.NotificationCompat) PendingIntent(android.app.PendingIntent) Paint(android.graphics.Paint) Notification(android.app.Notification) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 5 with NotificationThread

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);
        }
    }
}
Also used : NotificationItem(com.github.pockethub.android.ui.item.notification.NotificationItem) NotificationThread(com.meisolsson.githubsdk.model.NotificationThread) Issue(com.meisolsson.githubsdk.model.Issue) Intent(android.content.Intent)

Aggregations

NotificationThread (com.meisolsson.githubsdk.model.NotificationThread)7 Repository (com.meisolsson.githubsdk.model.Repository)4 Notification (android.app.Notification)2 PendingIntent (android.app.PendingIntent)2 Intent (android.content.Intent)2 Paint (android.graphics.Paint)2 NotificationCompat (android.support.v4.app.NotificationCompat)2 NotificationHolder (com.gh4a.model.NotificationHolder)2 NotificationListLoadResult (com.gh4a.model.NotificationListLoadResult)2 NotificationItem (com.github.pockethub.android.ui.item.notification.NotificationItem)2 ArrayList (java.util.ArrayList)2 SharedPreferences (android.content.SharedPreferences)1 NonNull (android.support.annotation.NonNull)1 NotificationManagerCompat (android.support.v4.app.NotificationManagerCompat)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 TextAppearanceSpan (android.text.style.TextAppearanceSpan)1 ApiRequestException (com.gh4a.ApiRequestException)1 ApiHelpers (com.gh4a.utils.ApiHelpers)1 NotificationHeaderItem (com.github.pockethub.android.ui.item.notification.NotificationHeaderItem)1 Issue (com.meisolsson.githubsdk.model.Issue)1