Search in sources :

Example 1 with NotificationService

use of com.meisolsson.githubsdk.service.activity.NotificationService 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 2 with NotificationService

use of com.meisolsson.githubsdk.service.activity.NotificationService in project gh4a by slapperwan.

the class HomeActivity method loadNotificationIndicator.

private void loadNotificationIndicator(boolean force) {
    NotificationService service = ServiceFactory.get(NotificationService.class, force, null, null, 1);
    HashMap<String, Object> options = new HashMap<>();
    options.put("all", false);
    options.put("participating", false);
    service.getNotifications(options, 1).map(ApiHelpers::throwOnFailure).map(result -> !result.items().isEmpty()).compose(makeLoaderSingle(ID_LOADER_NOTIFICATIONS_INDICATOR, force)).subscribe(this::setNotificationsIndicatorVisible, this::handleLoadFailure);
}
Also used : HashMap(java.util.HashMap) NotificationService(com.meisolsson.githubsdk.service.activity.NotificationService)

Example 3 with NotificationService

use of com.meisolsson.githubsdk.service.activity.NotificationService in project gh4a by slapperwan.

the class SingleFactory method getNotifications.

public static Single<NotificationListLoadResult> getNotifications(boolean all, boolean participating, boolean bypassCache) {
    final NotificationService service = ServiceFactory.get(NotificationService.class, bypassCache);
    final Map<String, Object> options = new HashMap<>();
    options.put("all", all);
    options.put("participating", participating);
    return ApiHelpers.PageIterator.toSingle(page -> service.getNotifications(options, page)).map(SingleFactory::notificationsToResult);
}
Also used : Repository(com.meisolsson.githubsdk.model.Repository) NotificationHolder(com.gh4a.model.NotificationHolder) Date(java.util.Date) TrendService(com.gh4a.model.TrendService) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) NotificationThread(com.meisolsson.githubsdk.model.NotificationThread) Single(io.reactivex.Single) Transform(org.simpleframework.xml.transform.Transform) RxJava2CallAdapterFactory(retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory) ArrayList(java.util.ArrayList) Feed(com.gh4a.model.Feed) SimpleXmlConverterFactory(retrofit2.converter.simplexml.SimpleXmlConverterFactory) RegistryMatcher(org.simpleframework.xml.transform.RegistryMatcher) Locale(java.util.Locale) Map(java.util.Map) ServiceGenerator(com.meisolsson.githubsdk.core.ServiceGenerator) NotificationService(com.meisolsson.githubsdk.service.activity.NotificationService) RepositoryCollaboratorService(com.meisolsson.githubsdk.service.repositories.RepositoryCollaboratorService) DateFormat(java.text.DateFormat) NotificationListLoadResult(com.gh4a.model.NotificationListLoadResult) GitHubFeedService(com.gh4a.model.GitHubFeedService) Retrofit(retrofit2.Retrofit) Trend(com.gh4a.model.Trend) List(java.util.List) OkHttpClient(okhttp3.OkHttpClient) Gh4Application(com.gh4a.Gh4Application) MoshiConverterFactory(retrofit2.converter.moshi.MoshiConverterFactory) ServiceFactory(com.gh4a.ServiceFactory) Persister(org.simpleframework.xml.core.Persister) Collections(java.util.Collections) HashMap(java.util.HashMap) NotificationService(com.meisolsson.githubsdk.service.activity.NotificationService)

Example 4 with NotificationService

use of com.meisolsson.githubsdk.service.activity.NotificationService in project gh4a by slapperwan.

the class NotificationHandlingService method markNotificationAsRead.

private void markNotificationAsRead(String repoOwner, String repoName, long timestamp) {
    NotificationService service = ServiceFactory.get(NotificationService.class, false);
    NotificationReadRequest request = NotificationReadRequest.builder().lastReadAt(new Date(timestamp)).build();
    try {
        service.markAllRepositoryNotificationsRead(repoOwner, repoName, request).blockingGet();
    } catch (Exception e) {
        Log.w(Gh4Application.LOG_TAG, "Could not mark repo \"" + repoOwner + "/" + repoName + "\" as read", e);
    }
}
Also used : NotificationReadRequest(com.meisolsson.githubsdk.model.request.NotificationReadRequest) NotificationService(com.meisolsson.githubsdk.service.activity.NotificationService) Date(java.util.Date)

Example 5 with NotificationService

use of com.meisolsson.githubsdk.service.activity.NotificationService in project gh4a by slapperwan.

the class NotificationListFragment method markAsRead.

private void markAsRead(Repository repository, NotificationThread notification) {
    NotificationService service = ServiceFactory.get(NotificationService.class, false);
    final Single<Response<Void>> responseSingle;
    if (notification != null) {
        responseSingle = service.markNotificationRead(notification.id());
    } else {
        NotificationReadRequest request = NotificationReadRequest.builder().lastReadAt(mNotificationsLoadTime).build();
        if (repository != null) {
            responseSingle = service.markAllRepositoryNotificationsRead(repository.owner().login(), repository.name(), request);
        } else {
            responseSingle = service.markAllNotificationsRead(request);
        }
    }
    responseSingle.map(ApiHelpers::mapToBooleanOrThrowOnFailure).compose(RxUtils::doInBackground).subscribe(result -> handleMarkAsRead(repository, notification), error -> handleActionFailure("Mark notifications as read failed", error));
}
Also used : Response(retrofit2.Response) NotificationReadRequest(com.meisolsson.githubsdk.model.request.NotificationReadRequest) ApiHelpers(com.gh4a.utils.ApiHelpers) NotificationService(com.meisolsson.githubsdk.service.activity.NotificationService)

Aggregations

NotificationService (com.meisolsson.githubsdk.service.activity.NotificationService)5 ApiHelpers (com.gh4a.utils.ApiHelpers)2 NotificationThread (com.meisolsson.githubsdk.model.NotificationThread)2 NotificationReadRequest (com.meisolsson.githubsdk.model.request.NotificationReadRequest)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 Gh4Application (com.gh4a.Gh4Application)1 ServiceFactory (com.gh4a.ServiceFactory)1 Feed (com.gh4a.model.Feed)1 GitHubFeedService (com.gh4a.model.GitHubFeedService)1 NotificationHolder (com.gh4a.model.NotificationHolder)1 NotificationListLoadResult (com.gh4a.model.NotificationListLoadResult)1 Trend (com.gh4a.model.Trend)1 TrendService (com.gh4a.model.TrendService)1 ServiceGenerator (com.meisolsson.githubsdk.core.ServiceGenerator)1 Repository (com.meisolsson.githubsdk.model.Repository)1 SubscriptionRequest (com.meisolsson.githubsdk.model.request.activity.SubscriptionRequest)1 RepositoryCollaboratorService (com.meisolsson.githubsdk.service.repositories.RepositoryCollaboratorService)1 Single (io.reactivex.Single)1 DateFormat (java.text.DateFormat)1