Minor cleanup / refactor of repeats

pull/14/head
Tim Su 13 years ago
parent bbd943f0a8
commit dfaa14a289

@ -62,32 +62,8 @@ public class RepeatDetailExposer extends BroadcastReceiver {
} catch (ParseException e) {
return null;
}
String interval;
switch(rrule.getFreq()) {
case HOURLY:
interval = r.getQuantityString(R.plurals.DUt_hours, rrule.getInterval(),
rrule.getInterval());
break;
case DAILY:
interval = r.getQuantityString(R.plurals.DUt_days, rrule.getInterval(),
rrule.getInterval());
break;
case WEEKLY:
interval = r.getQuantityString(R.plurals.DUt_weeks, rrule.getInterval(),
rrule.getInterval());
break;
case MONTHLY:
interval = r.getQuantityString(R.plurals.DUt_months, rrule.getInterval(),
rrule.getInterval());
break;
case YEARLY:
interval = r.getQuantityString(R.plurals.DUt_years, rrule.getInterval(),
rrule.getInterval());
break;
default:
// not designed to be used, only a fail-safe
interval = rrule.getInterval() + "-" + rrule.getFreq().name(); //$NON-NLS-1$
}
String interval = getIntervalFor(r, rrule);
interval = "<b>" + interval + "</b>"; //$NON-NLS-1$//$NON-NLS-2$
List<WeekdayNum> byDay = rrule.getByDay();
@ -117,6 +93,29 @@ public class RepeatDetailExposer extends BroadcastReceiver {
return null;
}
private String getIntervalFor(Resources r, RRule rrule) {
int plural;
switch(rrule.getFreq()) {
case MINUTELY:
plural = R.plurals.DUt_minutes; break;
case HOURLY:
plural = R.plurals.DUt_hours; break;
case DAILY:
plural = R.plurals.DUt_days; break;
case WEEKLY:
plural = R.plurals.DUt_weeks; break;
case MONTHLY:
plural = R.plurals.DUt_months; break;
case YEARLY:
plural = R.plurals.DUt_years; break;
default:
// not designed to be used, only a fail-safe
return rrule.getInterval() + "-" + rrule.getFreq().name(); //$NON-NLS-1$
}
return r.getQuantityString(plural, rrule.getInterval(), rrule.getInterval());
}
public String getPluginIdentifier() {
return RepeatsPlugin.IDENTIFIER;
}

@ -96,9 +96,9 @@ public class RepeatTaskCompleteListener extends BroadcastReceiver {
DateValue startDateAsDV = setUpStartDateAsDV(task, rrule, original, repeatAfterCompletion);
if(rrule.getFreq() == Frequency.HOURLY)
return handleHourlyRepeat(original, rrule);
return handleSubdayRepeat(original, rrule, DateUtilities.ONE_HOUR);
else if(rrule.getFreq() == Frequency.MINUTELY)
return handleMinutelyRepeat(original, rrule);
return handleSubdayRepeat(original, rrule, DateUtilities.ONE_MINUTE);
else
return invokeRecurrence(rrule, original, startDateAsDV);
}
@ -194,17 +194,10 @@ public class RepeatTaskCompleteListener extends BroadcastReceiver {
startDate.getMonth() + 1, startDate.getDate());
}
private static long handleHourlyRepeat(Date startDate, RRule rrule) {
private static long handleSubdayRepeat(Date startDate, RRule rrule, long millis) {
long newDueDate;
newDueDate = Task.createDueDate(Task.URGENCY_SPECIFIC_DAY_TIME,
startDate.getTime() + DateUtilities.ONE_HOUR * rrule.getInterval());
return newDueDate;
}
private static long handleMinutelyRepeat(Date startDate, RRule rrule) {
long newDueDate;
newDueDate = Task.createDueDate(Task.URGENCY_SPECIFIC_DAY_TIME,
startDate.getTime() + DateUtilities.ONE_MINUTE * rrule.getInterval());
startDate.getTime() + millis * rrule.getInterval());
return newDueDate;
}

Loading…
Cancel
Save