move event time updating into a separate function
This commit is contained in:
parent
ffc6d3535e
commit
c0dd90d8fc
1 changed files with 19 additions and 15 deletions
|
@ -170,21 +170,7 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||
if (cursor != null) {
|
||||
final List<Event> newEvents = fillEvents(cursor);
|
||||
for (Event e : newEvents) {
|
||||
final int periods = (ts - e.getStartTS()) / e.getRepeatInterval();
|
||||
DateTime currStart = new DateTime(e.getStartTS() * 1000L, DateTimeZone.getDefault());
|
||||
DateTime newStart;
|
||||
if (e.getRepeatInterval() == Constants.DAY) {
|
||||
newStart = currStart.plusDays(periods);
|
||||
} else if (e.getRepeatInterval() == Constants.WEEK) {
|
||||
newStart = currStart.plusWeeks(periods);
|
||||
} else {
|
||||
newStart = currStart.plusYears(periods);
|
||||
}
|
||||
|
||||
final int newStartTS = (int) (newStart.getMillis() / 1000);
|
||||
final int newEndTS = newStartTS + (e.getEndTS() - e.getStartTS());
|
||||
e.setStartTS(newStartTS);
|
||||
e.setEndTS(newEndTS);
|
||||
updateEventTimes(e, ts);
|
||||
}
|
||||
events.addAll(newEvents);
|
||||
}
|
||||
|
@ -201,6 +187,24 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||
mCallback.gotEvents(events);
|
||||
}
|
||||
|
||||
private void updateEventTimes(Event e, int ts) {
|
||||
final int periods = (ts - e.getStartTS()) / e.getRepeatInterval();
|
||||
DateTime currStart = new DateTime(e.getStartTS() * 1000L, DateTimeZone.getDefault());
|
||||
DateTime newStart;
|
||||
if (e.getRepeatInterval() == Constants.DAY) {
|
||||
newStart = currStart.plusDays(periods);
|
||||
} else if (e.getRepeatInterval() == Constants.WEEK) {
|
||||
newStart = currStart.plusWeeks(periods);
|
||||
} else {
|
||||
newStart = currStart.plusYears(periods);
|
||||
}
|
||||
|
||||
final int newStartTS = (int) (newStart.getMillis() / 1000);
|
||||
final int newEndTS = newStartTS + (e.getEndTS() - e.getStartTS());
|
||||
e.setStartTS(newStartTS);
|
||||
e.setEndTS(newEndTS);
|
||||
}
|
||||
|
||||
public List<Event> getEventsAtReboot() {
|
||||
List<Event> events = new ArrayList<>();
|
||||
final String selection = COL_START_TS + " > ? AND " + COL_REMINDER_MINUTES + " != ?";
|
||||
|
|
Loading…
Reference in a new issue