@Override
 protected void refreshStories() {
   Uri storiesUri = FeedProvider.FEED_STORIES_URI.buildUpon().appendPath(feedId).build();
   Cursor cursor =
       contentResolver.query(
           storiesUri,
           null,
           DatabaseConstants.getStorySelectionFromState(currentState),
           null,
           DatabaseConstants.getStorySortOrder(storyOrder));
   adapter.swapCursor(cursor);
 }
 @Override
 public Loader<Cursor> onCreateLoader(int loaderId, Bundle bundle) {
   Uri uri = FeedProvider.FEED_STORIES_URI.buildUpon().appendPath(feedId).build();
   CursorLoader cursorLoader =
       new CursorLoader(
           getActivity(),
           uri,
           null,
           DatabaseConstants.getStorySelectionFromState(currentState),
           null,
           DatabaseConstants.getStorySortOrder(storyOrder));
   return cursorLoader;
 }
Exemple #3
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;
    }
  }
Exemple #4
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;
    }
  }
Exemple #5
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;
    }
  }
Exemple #6
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;
    }
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_itemlist, null);
    ListView itemList = (ListView) v.findViewById(R.id.itemlistfragment_list);

    itemList.setEmptyView(v.findViewById(R.id.empty_view));

    contentResolver = getActivity().getContentResolver();
    Uri storiesUri = FeedProvider.FEED_STORIES_URI.buildUpon().appendPath(feedId).build();
    Cursor storiesCursor =
        contentResolver.query(
            storiesUri,
            null,
            DatabaseConstants.getStorySelectionFromState(currentState),
            null,
            DatabaseConstants.getStorySortOrder(storyOrder));
    Uri feedUri = FeedProvider.FEEDS_URI.buildUpon().appendPath(feedId).build();
    Cursor feedCursor = contentResolver.query(feedUri, null, null, null, null);

    if (feedCursor.getCount() < 1) {
      // This shouldn't happen, but crash reports indicate that it does (very rarely).
      // If we are told to create an item list for a feed, but then can't find that feed ID in the
      // DB,
      // something is very wrong, and we won't be able to recover, so just force the user back to
      // the
      // feed list until we have a better understanding of how to prevent this.
      Log.w(this.getClass().getName(), "Feed not found in DB, can't create item list.");
      getActivity().finish();
      return v;
    }

    feedCursor.moveToFirst();
    Feed feed = Feed.fromCursor(feedCursor);

    String[] groupFrom =
        new String[] {
          DatabaseConstants.STORY_TITLE,
          DatabaseConstants.STORY_AUTHORS,
          DatabaseConstants.STORY_READ,
          DatabaseConstants.STORY_SHORTDATE,
          DatabaseConstants.STORY_INTELLIGENCE_AUTHORS
        };
    int[] groupTo =
        new int[] {
          R.id.row_item_title,
          R.id.row_item_author,
          R.id.row_item_title,
          R.id.row_item_date,
          R.id.row_item_sidebar
        };

    // create the adapter before starting the loader, since the callback updates the adapter
    adapter =
        new FeedItemsAdapter(
            getActivity(),
            feed,
            R.layout.row_item,
            storiesCursor,
            groupFrom,
            groupTo,
            CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);

    getLoaderManager().initLoader(ITEMLIST_LOADER, null, this);

    itemList.setOnScrollListener(this);

    adapter.setViewBinder(new FeedItemViewBinder(getActivity()));
    itemList.setAdapter(adapter);
    itemList.setOnItemClickListener(this);
    itemList.setOnCreateContextMenuListener(this);

    return v;
  }