@Override
  public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
    // Handle select all/none first, and if it isn't those then don't do anything if we haven't
    // selected any items.
    if (item.getItemId() == R.id.action_select_all) {
      adapter.selectAll();
      return true;
    } else if (item.getItemId() == R.id.action_select_none) {
      adapter.clearSelections();
      return true;
    } else if (adapter.getSelectedItemCount() == 0) return true;

    // Handle actions.
    switch (item.getItemId()) {
      case R.id.action_tag:
        //noinspection unchecked
        TaggingActivity.start(this, adapter.getSelectedRealmObjects());
        return true;
      case R.id.action_rate:
        int initialRating =
            adapter.getSelectedItemCount() == 1
                ? ((RBook) adapter.getSelectedRealmObjects().get(0)).rating
                : 0;
        Dialogs.ratingDialog(getContext(), initialRating);
        return true;
      case R.id.action_mark_as:
        Dialogs.markAsDialog(getActivity());
        return true;
      case R.id.action_add_to_list:
        Dialogs.addToListDialogOrSnack(getActivity(), realm);
        return true;
      case R.id.action_re_import:
        Dialogs.simpleConfirmDialog(
            getContext(),
            R.string.title_re_import_books,
            R.string.prompt_re_import_books,
            R.string.action_re_import,
            R.id.action_re_import);
        return true;
      case R.id.action_remove:
        Dialogs.simpleConfirmDialog(
            getContext(),
            R.string.title_remove_books,
            R.string.prompt_remove_from_recents,
            R.string.action_remove,
            R.id.action_remove);
        return true;
      case R.id.action_delete:
        Dialogs.confirmCheckBoxDialog(
            getContext(),
            R.string.title_delete_books,
            R.string.prompt_delete_books,
            R.string.prompt_delete_from_device_too,
            R.string.action_delete,
            R.id.action_delete);
        return true;
      default:
        return false;
    }
  }
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case R.id.action_card_type:
       Dialogs.cardStyleDialog(getContext(), MainFrag.RECENT);
       return true;
     case R.id.action_clear:
       Dialogs.simpleConfirmDialog(
           getContext(),
           R.string.action_clear_recents,
           R.string.prompt_clear_recents,
           R.string.action_clear,
           R.id.action_clear);
       return true;
     default:
       return super.onOptionsItemSelected(item);
   }
 }