mangstadt / biweekly

biweekly is an iCalendar library written in Java.
BSD 2-Clause "Simplified" License
323 stars 44 forks source link

How to set up VEvent according to user choice #111

Closed GXSZone closed 3 years ago

GXSZone commented 3 years ago

I need to dynamically set count(), until() or interval() according to the user's choice For example, according to the user's choice of end date or until when This kind of chain writing cannot be applied

              VEvent event = new VEvent();

              switch (mRepeatEntity.getFreqUnit()) {
                    case UNIT_DAY:
                        event.setRecurrenceRule(new Recurrence.Builder(Frequency.DAILY)
                                .interval(mRepeatEntity.getFreqInterval())
                                .build());
                        switch (mRepeatEntity.getFinishUnit()) {
                            case TodoConst.FINISH_DATE:
                                // `until()`
                                break;
                            case TodoConst.FINISH_CONUT:
                                // `count()`
                                break;
                            default:
                                break;
                        }
                        break;
mangstadt commented 3 years ago

Store the builder object in its own variable.

Recurrence.Builder builder = new Recurrence.Builder(Frequency.DAILY).interval(mRepeatEntity.getFreqInterval());
switch (mRepeatEntity.getFinishUnit()) {
  case TodoConst.FINISH_DATE:
    builder.until(...);
    break;
}
GXSZone commented 3 years ago

Thinks