示例#1
0
  public void setSuggestions(List<SnippetArticle> suggestions, @CategoryStatusEnum int status) {
    copyThumbnails(suggestions);

    int itemCountBefore = getItemCount();
    setStatusInternal(status);

    mSuggestions.clear();
    mSuggestions.addAll(suggestions);

    if (mMoreButton != null) {
      mMoreButton.setPosition(mSuggestions.size());
      mMoreButton.setDismissable(mSuggestions.isEmpty());
    }
    resetChildren();
    notifySectionChanged(itemCountBefore);
  }
示例#2
0
  public void removeSuggestion(SnippetArticle suggestion) {
    int removedIndex = mSuggestions.indexOf(suggestion);
    if (removedIndex == -1) return;

    mSuggestions.remove(removedIndex);
    if (mMoreButton != null) mMoreButton.setDismissable(!hasSuggestions());

    resetChildren();

    // Note: Keep this coherent with getItems()
    int globalRemovedIndex = removedIndex + 1; // Header has index 0 in the section.
    notifyItemRemoved(globalRemovedIndex);

    // If we still have some suggestions, we are done. Otherwise, we'll have to notify about the
    // status-related items that are now present.
    if (hasSuggestions()) return;
    notifyItemInserted(globalRemovedIndex); // Status card.
    if (!mCategoryInfo.hasMoreButton()) {
      notifyItemInserted(globalRemovedIndex + 1); // Action card.
    }
    notifyItemInserted(globalRemovedIndex + 2); // Progress indicator.
  }