private void deleteAdvies(int[] reverseSortedPositions) {
    AdviesDataSource dataSource = new AdviesDataSource(getActivity());
    dataSource.open();

    for (int position : reverseSortedPositions) {
      CardItemAdvies card = cardsAdvies.get(position);
      long id = card.getId();
      AdviesItem item = new AdviesItem();
      item.setId(id);

      dataSource.deleteAdviesItem(item);

      cardsAdvies.remove(position);
      adapterAdvies.notifyItemRemoved(position);
    }

    dataSource.close();
    adapterAdvies.notifyDataSetChanged();
  }
    @Override
    protected void onPostExecute(JSONArray jsonArray) {
      if (jsonArray != null) {

        AdviesDataSource adviesDataSource = new AdviesDataSource(getActivity());
        adviesDataSource.open();

        for (int i = 0; i < jsonArray.length(); i++) {
          JSONObject row;
          int adviceId = 0;
          String adviceTitle = null;
          String adviceContent = null;
          int adviceCategory = 0;

          try {
            row = jsonArray.getJSONObject(i);
            adviceId = row.getInt("AdviceId");
            adviceTitle = row.getString("AdviceTitle");
            adviceContent = row.getString("AdviceContent");
            adviceCategory = row.getInt("AdviceCategory");
          } catch (JSONException e) {
            e.printStackTrace();
          }

          if (!adviesDataSource.adviceExistInDb(adviceId)) {
            AdviesItem adviesItem = new AdviesItem();
            adviesItem.setId(adviceId);
            adviesItem.setTitel(adviceTitle);
            adviesItem.setContent(adviceContent);
            adviesItem.setCategoryId(adviceCategory);

            adviesDataSource.createAdviesItem(adviesItem);
          }
        }

        adviesDataSource.close();

        updateView();
      }
    }
  private void updateView() {
    AdviesDataSource dataSource = new AdviesDataSource(getActivity());
    dataSource.open();

    List<AdviesItem> adviezen = dataSource.getAllAdviesItems();

    cardsAdvies.clear();

    for (int i = 0; i < adviezen.size(); i++) {
      AdviesItem advies = adviezen.get(i);
      long id = advies.getId();
      String title = advies.getTitel();
      String content = advies.getContent();
      long categoryId = advies.getCategoryId();
      CardItemAdvies card = new CardItemAdvies(id, title, content, drawables[(int) categoryId - 1]);
      cardsAdvies.add(card);
    }

    adapterAdvies.notifyDataSetChanged();
    iv_refresh.clearAnimation();

    dataSource.close();
  }