public void onCategorySelected(
      String categoryId, String categoryOptionId, String categoryOptionName) {
    for (CategoryState state : mState.getCategoryStates()) {
      if (state.getCategoryId().equals(categoryId)) {
        state.setCategoryOptionId(categoryOptionId);
        state.setCategoryOptionName(categoryOptionName);
        break;
      }
    }

    onCategoriesSelected(mState.getCategoryStates());
  }
  private boolean areAllCategoriesChosen() {
    List<CategoryState> categoryStates = mState.getCategoryStates();

    if (categoryStates == null || categoryStates.isEmpty()) {
      return false;
    }
    for (CategoryState categoryState : categoryStates) {
      if (!categoryState.isCategoryOptionSelected()) {
        return false;
      }
    }
    return true;
  }
  public void onRestoreInstanceState() {
    AggregateReportFragmentState backedUpState = new AggregateReportFragmentState(mState);
    if (!backedUpState.isOrgUnitEmpty()) {
      onUnitSelected(backedUpState.getOrgUnitId(), backedUpState.getOrgUnitLabel());

      if (!backedUpState.isDataSetEmpty()) {
        onDataSetSelected(
            backedUpState.getDataSetId(),
            backedUpState.getDataSetLabel(),
            backedUpState.getDataSetCategoryComboId());

        if (!backedUpState.isPeriodEmpty()) {
          onPeriodSelected(backedUpState.getPeriod(), false);

          if (!backedUpState.areCategoryStatesEmpty()) {
            onCategoriesSelected(backedUpState.getCategoryStates());
          }
        }
      }
    }
  }