private ArrayList<BlogPost> getItems() {
   ArrayList<BlogPost> allItems = new ArrayList<BlogPost>();
   for (int i = 0; i < adapter.getItemCount(); i++) {
     if (!adapter.isGroupHeader(i)) {
       allItems.add((BlogPost) adapter.getItem(i));
     }
   }
   return allItems;
 }
  private void showBlogPostView(boolean show) {
    if (this.isWideScreen) {
      return;
    }
    if (show) {
      this.exampleMainContent.setVisibility(View.INVISIBLE);
      this.selectedBlogPostView.setVisibility(View.VISIBLE);

      actionModeTitleView.setText("");
      long id = adapter.getCurrentItemId();
      int position = adapter.getPosition(id);
      getActivity().startActionMode(new BlogPostViewCallback(position));
    } else {
      this.exampleMainContent.setVisibility(View.VISIBLE);
      this.selectedBlogPostView.setVisibility(View.GONE);
    }
  }
  @Override
  public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);

    if (listView == null) {
      return;
    }

    adapter.clearFilterDescriptors();
    ArrayList<BlogPost> allItems = getItems();
    outState.putParcelableArrayList("allItems", allItems);

    outState.putBoolean("isInReorder", reorderBehavior.isInProgress());
    outState.putBoolean("isAllSelected", menuSelection == menuItemAll);

    outState.putLong("currentItemId", adapter.getCurrentItemId());
    outState.putBoolean(
        "isFullScreen", !isWideScreen && exampleMainContent.getVisibility() != View.VISIBLE);
  }
  private void enterReorderMode() {
    if (swipeExecuteBehavior.isInProgress()) {
      swipeExecuteBehavior.endExecute();
    }
    this.listView.addBehavior(reorderBehavior);
    this.listView.removeBehavior(swipeExecuteBehavior);
    this.listView.removeBehavior(selectionBehavior);

    this.adapter.enterReorderMode();

    if (isWideScreen) {
      adapter.setShowCurrent(false);
    }

    this.changeMenuIsEnabled(false);

    this.actionModeTitleView.setText(this.reorderModeHeader);
    this.getActivity().startActionMode(new ReorderModeCallback());
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

    final View rootView = inflater.inflate(R.layout.fragment_list_view_selection, container, false);

    this.adapter = new BlogPostAdapter(new ArrayList<BlogPost>());

    this.listView = (RadListView) rootView.findViewById(R.id.listView);
    this.listView.setAdapter(this.adapter);
    this.listView.addItemClickListener(new ListViewClickListener());

    this.reorderBehavior = new ReorderWithHandlesBehavior(R.id.imgReorder);

    this.swipeExecuteBehavior = new SwipeExecuteBehavior();
    this.swipeExecuteBehavior.addListener(new SwipeListener());
    this.swipeExecuteBehavior.setAutoDissolve(false);
    this.listView.addBehavior(this.swipeExecuteBehavior);

    this.selectionBehavior = new SelectionBehavior();

    this.selectionBehavior.addListener(new ListViewSelectionListener());
    this.listView.addBehavior(this.selectionBehavior);

    this.collapsibleGroupsBehavior = new CollapsibleGroupsBehavior();
    this.listView.addBehavior(collapsibleGroupsBehavior);

    this.initExampleSettings(rootView);
    boolean isAllSelected = true;
    boolean isInReorder = false;

    List<BlogPost> allItems = null;
    if (savedInstanceState != null) {
      allItems = savedInstanceState.getParcelableArrayList("allItems");
      bindListView(allItems);

      isInReorder = savedInstanceState.getBoolean("isInReorder");
      isAllSelected = savedInstanceState.getBoolean("isAllSelected");

      long currentId = savedInstanceState.getLong("currentItemId");
      boolean wasFullScreen = savedInstanceState.getBoolean("isFullScreen");

      int position = adapter.getPosition(currentId);
      if (position < 0) {
        loadBlogPostContent();
      } else {
        loadBlogPostContent(position);
      }

      if (!isWideScreen && currentId != INVALID_ID && wasFullScreen) {
        showBlogPostView(true);
      }
    }

    if (allItems == null || allItems.size() == 0) {
      this.initMenu(rootView, true);
      BlogPostLoaderTask blogPostsLoader = new BlogPostLoaderTask();
      blogPostsLoader.execute();
    } else {
      this.initMenu(rootView, isAllSelected);
      if (!isAllSelected) {
        switchFilter(true);
      }

      if (isInReorder) {
        enterReorderMode();
      }
    }

    return rootView;
  }