/** Adds a block-out time to the ArrayList stored by the activity. */
  public void addBlockoutTime(View view) {

    TimeShort newStartTime, newEndTime;

    newStartTime = getTime(startTimePicker);
    newEndTime = getTime(endTimePicker);

    ArrayList<Day> newDayList = getDays();
    if (!(newDayList.size() > 0)) {
      AlertDialog.Builder noDaysErrorDialog = new AlertDialog.Builder(SelectBlockoutTimes.this);
      noDaysErrorDialog.setTitle("Can't block out a time with no days");
      // noDaysErrorDialog.setPositiveButton("OKAY", null);
      noDaysErrorDialog.show();
      return;
    }

    String blockoutTimeName = nameBlockoutTime.getText().toString();
    if (blockoutTimeName.equals("")) {
      nameBlockoutTime.setError("Please give this a name");
      nameBlockoutTime.requestFocus();
      return;
    } else {
      nameBlockoutTime.setError(null);
      nameBlockoutTime.setText("");
    }

    if (workRadioButton.isChecked()) {
      type = BlockType.WORK;
    } else if (commuteRadioButton.isChecked()) {
      type = BlockType.COMMUTE;
    } else if (sleepRadioButton.isChecked()) {
      type = BlockType.SLEEP;
    } else if (studyRadioButton.isChecked()) {
      type = BlockType.STUDY;
    } else if (otherRadioButton.isChecked()) {
      type = BlockType.OTHER;
    }

    Course newBlockoutCourse = new Course("BLOCKOUT", "BLOCKOUT", "BLOCKOUT");
    Section newBlockoutTime =
        new Section(
            Integer.parseInt(type.toString()),
            blockoutTimeName,
            "",
            newStartTime,
            newEndTime,
            newDayList,
            ClassStatus.OPEN,
            newBlockoutCourse);
    newBlockoutCourse.addSection(newBlockoutTime);

    currentBlockoutTimes.add(newBlockoutTime);
    blockoutTimesListAdapter.notifyDataSetChanged();
  }
  @Override
  protected void onStart() {
    super.onStart();

    workRadioButton.setChecked(true);
    currentBlockoutTimes = new ArrayList<>();

    blockoutTimesListAdapter =
        new SectionArrayAdapter(
            SelectBlockoutTimes.this, R.layout.section_list_display, currentBlockoutTimes);
    blockoutTimesListAdapter.setDeleteButtonVisibility(true);
    blockoutTimesListAdapter.setNotifyOnChange(true);
    sectionListView.setAdapter(blockoutTimesListAdapter);

    // Set buttons to toggle colors. These can all be discarded if a proper style is setup and used
    // for buttons.
    sundayToggleButton.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
              buttonView.setBackgroundColor(getResources().getColor(R.color.utaOrange));
            } else
              buttonView.setBackgroundColor(getResources().getColor(R.color.button_material_light));
          }
        });
    mondayToggleButton.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
              buttonView.setBackgroundColor(getResources().getColor(R.color.utaOrange));
            } else
              buttonView.setBackgroundColor(getResources().getColor(R.color.button_material_light));
          }
        });

    tuesdayToggleButton.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
              buttonView.setBackgroundColor(getResources().getColor(R.color.utaOrange));
            } else
              buttonView.setBackgroundColor(getResources().getColor(R.color.button_material_light));
          }
        });

    wednesdayToggleButton.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
              buttonView.setBackgroundColor(getResources().getColor(R.color.utaOrange));
            } else
              buttonView.setBackgroundColor(getResources().getColor(R.color.button_material_light));
          }
        });

    thursdayToggleButton.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
              buttonView.setBackgroundColor(getResources().getColor(R.color.utaOrange));
            } else
              buttonView.setBackgroundColor(getResources().getColor(R.color.button_material_light));
          }
        });

    fridayToggleButton.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
              buttonView.setBackgroundColor(getResources().getColor(R.color.utaOrange));
            } else
              buttonView.setBackgroundColor(getResources().getColor(R.color.button_material_light));
          }
        });

    saturdayToggleButton.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
              buttonView.setBackgroundColor(getResources().getColor(R.color.utaOrange));
            } else
              buttonView.setBackgroundColor(getResources().getColor(R.color.button_material_light));
          }
        });

    // Check to see if creating intent had blocout times stored in it.
    Intent intent = getIntent();
    if (intent.hasExtra("BLOCKOUT TIMES")) {
      String blockOutTimes = intent.getStringExtra("BLOCKOUT TIMES");
      try {
        JSONObject jsonObject = new JSONObject(blockOutTimes);
        Course course = new Course(jsonObject);
        for (Section section : course.getSectionList()) {
          currentBlockoutTimes.add(section);
        }
      } catch (JSONException e) {
        e.printStackTrace();
      }

      blockoutTimesListAdapter.notifyDataSetChanged();
    }
  }