Пример #1
0
  private void update(ArrayList<Category> newItems) {
    ArrayList<Category> arrayForRemoving = new ArrayList<>();
    for (int i = 0; i < publishItems.size(); i++) {
      Category category = publishItems.get(i);
      if (!newItems.contains(category)) {
        arrayForRemoving.add(category);
      }
    }
    for (Category category : arrayForRemoving) {
      publishItems.remove(category);
    }

    for (Category category : newItems) {
      if (publishItems.indexOf(category) == SortedList.INVALID_POSITION) {
        publishItems.add(category);
      }
    }
    if (publishItems.size() == 0) {
      if (currentFilter.equals(FILTER_ALL)) {
        callback.onEmpty(
            R.string.empty_no_categories_restart_app,
            R.drawable.ic_menu_gallery,
            R.string.button_restart_app,
            null);
      } else {
        callback.onEmpty(
            R.string.empty_no_favorite_categories,
            R.drawable.ic_menu_gallery,
            R.string.button_show_all_categories,
            null);
      }
    }
  }