Search in sources :

Example 1 with MarkReadNewsArticleResponse

use of POGOProtos.Networking.Responses.MarkReadNewsArticleResponseOuterClass.MarkReadNewsArticleResponse in project PokeGOAPI-Java by Grover-c13.

the class News method markUnreadNews.

/**
 * Mark Unread News to read
 */
public void markUnreadNews() {
    if (currentNews == null || currentNews.getNewsArticlesCount() <= 0) {
        // do nothing
        return;
    }
    // Stored enabled and un-read article
    List<String> unReadNewsList = new ArrayList<>();
    for (NewsArticle newsArticle : currentNews.getNewsArticlesList()) {
        if (newsArticle.getEnabled() && !newsArticle.getArticleRead())
            unReadNewsList.add(newsArticle.getId());
    }
    Log.i(TAG, "markUnreadNews total Article count:" + unReadNewsList.size());
    if (unReadNewsList.size() > 0) {
        MarkReadNewsArticleMessage msg = MarkReadNewsArticleMessage.newBuilder().addAllNewsIds(unReadNewsList).build();
        ServerRequest request = new ServerRequest(RequestTypeOuterClass.RequestType.MARK_READ_NEWS_ARTICLE, msg);
        ServerRequestEnvelope envelope = ServerRequestEnvelope.create(request);
        try {
            api.requestHandler.sendServerRequests(envelope);
            MarkReadNewsArticleResponse response = MarkReadNewsArticleResponse.parseFrom(request.getData());
            if (response.getResult() == MarkReadNewsArticleResponse.Result.SUCCESS) {
                Log.i(TAG, "Mark News Article -> success");
            } else {
                Log.w(TAG, "Mark News Article -> !success");
            }
        } catch (RequestFailedException e) {
            e.printStackTrace();
            Log.e(TAG, "RequestFailedException: cause:" + e.getCause() + " message:" + e.getMessage());
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
            Log.e(TAG, "InvalidProtocolBufferException: cause:" + e.getCause() + " message:" + e.getMessage());
        }
    } else {
        Log.i(TAG, "no unmarked news found -> skipped");
    }
}
Also used : ServerRequestEnvelope(com.pokegoapi.main.ServerRequestEnvelope) NewsArticle(POGOProtos.Data.News.NewsArticleOuterClass.NewsArticle) MarkReadNewsArticleMessage(POGOProtos.Networking.Requests.Messages.MarkReadNewsArticleMessageOuterClass.MarkReadNewsArticleMessage) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) ArrayList(java.util.ArrayList) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ServerRequest(com.pokegoapi.main.ServerRequest) MarkReadNewsArticleResponse(POGOProtos.Networking.Responses.MarkReadNewsArticleResponseOuterClass.MarkReadNewsArticleResponse)

Aggregations

NewsArticle (POGOProtos.Data.News.NewsArticleOuterClass.NewsArticle)1 MarkReadNewsArticleMessage (POGOProtos.Networking.Requests.Messages.MarkReadNewsArticleMessageOuterClass.MarkReadNewsArticleMessage)1 MarkReadNewsArticleResponse (POGOProtos.Networking.Responses.MarkReadNewsArticleResponseOuterClass.MarkReadNewsArticleResponse)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 RequestFailedException (com.pokegoapi.exceptions.request.RequestFailedException)1 ServerRequest (com.pokegoapi.main.ServerRequest)1 ServerRequestEnvelope (com.pokegoapi.main.ServerRequestEnvelope)1 ArrayList (java.util.ArrayList)1