Ejemplo n.º 1
0
  public SocialFeedResponse getSharedStoriesForFeeds(String[] feedIds, String pageNumber) {
    final APIClient client = new APIClient(context);
    final ValueMultimap values = new ValueMultimap();
    for (String feedId : feedIds) {
      values.put(APIConstants.PARAMETER_FEEDS, feedId);
    }
    if (!TextUtils.isEmpty(pageNumber)) {
      values.put(APIConstants.PARAMETER_PAGE_NUMBER, "" + pageNumber);
    }

    final APIResponse response = client.get(APIConstants.URL_SHARED_RIVER_STORIES, values);

    SocialFeedResponse storiesResponse =
        gson.fromJson(response.responseString, SocialFeedResponse.class);
    if (response.responseCode == HttpStatus.SC_OK && !response.hasRedirected) {

      // If we've successfully retrieved the latest stories for all shared feeds (the first page),
      // delete all previous shared feeds
      if (TextUtils.equals(pageNumber, "1")) {
        Uri storyUri = FeedProvider.ALL_STORIES_URI;
        contentResolver.delete(storyUri, null, null);
      }

      for (Story story : storiesResponse.stories) {
        for (String userId : story.sharedUserIds) {
          Uri storySocialUri =
              FeedProvider.SOCIALFEED_STORIES_URI.buildUpon().appendPath(userId).build();
          contentResolver.insert(storySocialUri, story.getValues());
        }

        Uri storyUri = FeedProvider.FEED_STORIES_URI.buildUpon().appendPath(story.feedId).build();
        contentResolver.insert(storyUri, story.getValues());

        insertComments(story);
      }

      for (UserProfile user : storiesResponse.userProfiles) {
        contentResolver.insert(FeedProvider.USERS_URI, user.getValues());
      }

      if (storiesResponse != null && storiesResponse.feeds != null) {
        for (Feed feed : storiesResponse.feeds) {
          contentResolver.insert(FeedProvider.FEEDS_URI, feed.getValues());
        }
      }

      return storiesResponse;
    } else {
      return null;
    }
  }
Ejemplo n.º 2
0
  public SocialFeedResponse getStoriesForSocialFeed(
      String userId, String username, String pageNumber) {
    final APIClient client = new APIClient(context);
    final ContentValues values = new ContentValues();
    values.put(APIConstants.PARAMETER_USER_ID, userId);
    values.put(APIConstants.PARAMETER_USERNAME, username);
    if (!TextUtils.isEmpty(pageNumber)) {
      values.put(APIConstants.PARAMETER_PAGE_NUMBER, "" + pageNumber);
    }
    Uri feedUri =
        Uri.parse(APIConstants.URL_SOCIALFEED_STORIES)
            .buildUpon()
            .appendPath(userId)
            .appendPath(username)
            .build();
    final APIResponse response = client.get(feedUri.toString(), values);
    SocialFeedResponse socialFeedResponse =
        gson.fromJson(response.responseString, SocialFeedResponse.class);
    if (response.responseCode == HttpStatus.SC_OK && !response.hasRedirected) {

      Uri storySocialUri =
          FeedProvider.SOCIALFEED_STORIES_URI.buildUpon().appendPath(userId).build();
      if (TextUtils.equals(pageNumber, "1")) {
        contentResolver.delete(storySocialUri, null, null);
      }

      for (Story story : socialFeedResponse.stories) {
        insertComments(story);

        Uri storyUri = FeedProvider.FEED_STORIES_URI.buildUpon().appendPath(story.feedId).build();
        contentResolver.insert(storyUri, story.getValues());
        contentResolver.insert(storySocialUri, story.getValues());
      }

      if (socialFeedResponse.userProfiles != null) {
        for (UserProfile user : socialFeedResponse.userProfiles) {
          contentResolver.insert(FeedProvider.USERS_URI, user.getValues());
        }
      }

      for (Feed feed : socialFeedResponse.feeds) {
        contentResolver.insert(FeedProvider.FEEDS_URI, feed.getValues());
      }
      return socialFeedResponse;
    } else {
      return null;
    }
  }