Esempio n. 1
0
  public StoriesResponse getStarredStories(String pageNumber) {
    final APIClient client = new APIClient(context);
    final ValueMultimap values = new ValueMultimap();
    if (!TextUtils.isEmpty(pageNumber)) {
      values.put(APIConstants.PARAMETER_PAGE_NUMBER, "" + pageNumber);
    }
    final APIResponse response = client.get(APIConstants.URL_STARRED_STORIES, values);

    StoriesResponse storiesResponse = gson.fromJson(response.responseString, StoriesResponse.class);
    if (response.responseCode == HttpStatus.SC_OK && !response.hasRedirected) {
      if (TextUtils.equals(pageNumber, "1")) {
        contentResolver.delete(FeedProvider.STARRED_STORIES_URI, null, null);
      }
      for (Story story : storiesResponse.stories) {
        contentResolver.insert(FeedProvider.STARRED_STORIES_URI, story.getValues());
        insertComments(story);
      }
      for (UserProfile user : storiesResponse.users) {
        contentResolver.insert(FeedProvider.USERS_URI, user.getValues());
      }
      return storiesResponse;
    } else {
      return null;
    }
  }
Esempio n. 2
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;
    }
  }
Esempio n. 3
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;
    }
  }
Esempio n. 4
0
  public StoriesResponse getStoriesForFeed(
      String feedId, String pageNumber, StoryOrder order, ReadFilter filter) {
    final APIClient client = new APIClient(context);
    final ContentValues values = new ContentValues();
    Uri feedUri = Uri.parse(APIConstants.URL_FEED_STORIES).buildUpon().appendPath(feedId).build();
    values.put(APIConstants.PARAMETER_FEEDS, feedId);
    values.put(APIConstants.PARAMETER_PAGE_NUMBER, pageNumber);
    values.put(APIConstants.PARAMETER_ORDER, order.getParameterValue());
    values.put(APIConstants.PARAMETER_READ_FILTER, filter.getParameterValue());

    final APIResponse response = client.get(feedUri.toString(), values);
    Uri storyUri = FeedProvider.FEED_STORIES_URI.buildUpon().appendPath(feedId).build();

    if (response.responseCode == HttpStatus.SC_OK && !response.hasRedirected) {
      if (TextUtils.equals(pageNumber, "1")) {
        contentResolver.delete(storyUri, null, null);
      }
      StoriesResponse storiesResponse =
          gson.fromJson(response.responseString, StoriesResponse.class);

      Uri classifierUri = FeedProvider.CLASSIFIER_URI.buildUpon().appendPath(feedId).build();

      contentResolver.delete(classifierUri, null, null);

      for (ContentValues classifierValues : storiesResponse.classifiers.getContentValues()) {
        contentResolver.insert(classifierUri, classifierValues);
      }

      for (Story story : storiesResponse.stories) {
        contentResolver.insert(storyUri, story.getValues());
        insertComments(story);
      }

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

      return storiesResponse;
    } else {
      return null;
    }
  }
Esempio n. 5
0
  public StoriesResponse getStoriesForFeeds(
      String[] feedIds, String pageNumber, StoryOrder order, ReadFilter filter) {
    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);
    }
    values.put(APIConstants.PARAMETER_ORDER, order.getParameterValue());
    values.put(APIConstants.PARAMETER_READ_FILTER, filter.getParameterValue());
    final APIResponse response = client.get(APIConstants.URL_RIVER_STORIES, values);

    StoriesResponse storiesResponse = gson.fromJson(response.responseString, StoriesResponse.class);
    if (response.responseCode == HttpStatus.SC_OK && !response.hasRedirected) {
      if (TextUtils.equals(pageNumber, "1")) {
        Uri storyUri = FeedProvider.ALL_STORIES_URI;
        contentResolver.delete(storyUri, null, null);
      }

      for (Story story : storiesResponse.stories) {
        Uri storyUri = FeedProvider.FEED_STORIES_URI.buildUpon().appendPath(story.feedId).build();
        contentResolver.insert(storyUri, story.getValues());
        insertComments(story);
      }

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

      return storiesResponse;
    } else {
      return null;
    }
  }