// Implements android.widget.RadioGroup.OnCheckedChangeListener interface
 // Month repeat by radio buttons
 @Override
 public void onCheckedChanged(RadioGroup group, int checkedId) {
   if (checkedId == R.id.repeatMonthlyByNthDayOfMonth) {
     mModel.monthlyRepeat = RecurrenceModel.MONTHLY_BY_DATE;
   } else if (checkedId == R.id.repeatMonthlyByNthDayOfTheWeek) {
     mModel.monthlyRepeat = RecurrenceModel.MONTHLY_BY_NTH_DAY_OF_WEEK;
   }
   updateDialog();
 }
  // TODO don't lose data when getting data that our UI can't handle
  private static void copyEventRecurrenceToModel(final EventRecurrence er, RecurrenceModel model) {
    // Freq:
    switch (er.freq) {
      case EventRecurrence.HOURLY:
        model.freq = RecurrenceModel.FREQ_HOURLY;
        break;
      case EventRecurrence.DAILY:
        model.freq = RecurrenceModel.FREQ_DAILY;
        break;
      case EventRecurrence.MONTHLY:
        model.freq = RecurrenceModel.FREQ_MONTHLY;
        break;
      case EventRecurrence.YEARLY:
        model.freq = RecurrenceModel.FREQ_YEARLY;
        break;
      case EventRecurrence.WEEKLY:
        model.freq = RecurrenceModel.FREQ_WEEKLY;
        break;
      default:
        throw new IllegalStateException("freq=" + er.freq);
    }

    // Interval:
    if (er.interval > 0) {
      model.interval = er.interval;
    }

    // End:
    // End by count:
    model.endCount = er.count;
    if (model.endCount > 0) {
      model.end = RecurrenceModel.END_BY_COUNT;
    }

    // End by date:
    if (!TextUtils.isEmpty(er.until)) {
      if (model.endDate == null) {
        model.endDate = new Time();
      }

      try {
        model.endDate.parse(er.until);
      } catch (TimeFormatException e) {
        model.endDate = null;
      }

      // LIMITATION: The UI can only handle END_BY_DATE or END_BY_COUNT
      if (model.end == RecurrenceModel.END_BY_COUNT && model.endDate != null) {
        throw new IllegalStateException("freq=" + er.freq);
      }

      model.end = RecurrenceModel.END_BY_DATE;
    }

    // Weekly: repeat by day of week or Monthly: repeat by nth day of week
    // in the month
    Arrays.fill(model.weeklyByDayOfWeek, false);
    if (er.bydayCount > 0) {
      int count = 0;
      for (int i = 0; i < er.bydayCount; i++) {
        int dayOfWeek = EventRecurrence.day2TimeDay(er.byday[i]);
        model.weeklyByDayOfWeek[dayOfWeek] = true;

        if (model.freq == RecurrenceModel.FREQ_MONTHLY
            && isSupportedMonthlyByNthDayOfWeek(er.bydayNum[i])) {
          // LIMITATION: Can handle only (one) weekDayNum in nth or last and only
          // when
          // monthly
          model.monthlyByDayOfWeek = dayOfWeek;
          model.monthlyByNthDayOfWeek = er.bydayNum[i];
          model.monthlyRepeat = RecurrenceModel.MONTHLY_BY_NTH_DAY_OF_WEEK;
          count++;
        }
      }

      if (model.freq == RecurrenceModel.FREQ_MONTHLY) {
        if (er.bydayCount != 1) {
          // Can't handle 1st Monday and 2nd Wed
          throw new IllegalStateException("Can handle only 1 byDayOfWeek in monthly");
        }
        if (count != 1) {
          throw new IllegalStateException(
              "Didn't specify which nth day of week to repeat for a monthly");
        }
      }
    }

    // Monthly by day of month
    if (model.freq == RecurrenceModel.FREQ_MONTHLY) {
      if (er.bymonthdayCount == 1) {
        if (model.monthlyRepeat == RecurrenceModel.MONTHLY_BY_NTH_DAY_OF_WEEK) {
          throw new IllegalStateException(
              "Can handle only by monthday or by nth day of week, not both");
        }
        model.monthlyByMonthDay = er.bymonthday[0];
        model.monthlyRepeat = RecurrenceModel.MONTHLY_BY_DATE;
      } else if (er.bymonthCount > 1) {
        // LIMITATION: Can handle only one month day
        throw new IllegalStateException("Can handle only one bymonthday");
      }
    }
  }