/** Set the subtitle of the toolbar. */
  private void updateSubtitle() {
    CrimeLab crimeLab = CrimeLab.getInstance(getActivity());
    int crimeCount = crimeLab.getCrimes().size();
    String subtitle = getString(R.string.subtitle_format, crimeCount);

    if (!mSubtitleVisible) {
      subtitle = null;
    }

    AppCompatActivity activity = (AppCompatActivity) getActivity();
    activity.getSupportActionBar().setSubtitle(subtitle);
  }
  /** Update the list. */
  private void updateUI() {
    CrimeLab crimeLab = CrimeLab.getInstance(getActivity());
    List<Crime> crimes = crimeLab.getCrimes();

    if (mAdapter == null) {
      mAdapter = new CrimeAdapter(crimes);
      mRecyclerViewCrime.setAdapter(mAdapter);
    } else {
      // mCrimes is gone. So the List<Crime> returned by getCrimes()
      // is a snapshot of the Crimes at one point in time.
      // we need to update the List<Crime> in the adapter in case user has edited a crime
      mAdapter.setCrimes(crimes);
      mAdapter.notifyDataSetChanged();
    }

    // update subtitle after rotation
    updateSubtitle();
  }
  /**
   * Response to add crime action button.
   *
   * <p>Toggling the action item subtitle.
   *
   * @param item
   * @return
   */
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
      case R.id.menu_item_new_crime:
        Crime crime = new Crime();
        CrimeLab.getInstance(getActivity()).addCrime(crime);
        Intent intent = CrimePagerActivity.newIntent(getActivity(), crime.getId());
        startActivity(intent);
        return true;

      case R.id.menu_item_show_subtitle:
        mSubtitleVisible = !mSubtitleVisible;
        getActivity().invalidateOptionsMenu();
        updateSubtitle();
        return true;

      default:
        return super.onOptionsItemSelected(item);
    }
  }