move event time updating into a separate function

This commit is contained in:
tibbi 2016-09-11 16:06:29 +02:00
parent ffc6d3535e
commit c0dd90d8fc
1 changed files with 19 additions and 15 deletions

View File

@ -170,6 +170,24 @@ public class DBHelper extends SQLiteOpenHelper {
if (cursor != null) {
final List<Event> newEvents = fillEvents(cursor);
for (Event e : newEvents) {
updateEventTimes(e, ts);
}
events.addAll(newEvents);
}
}
final String selection = COL_START_TS + " <= ? AND " + COL_END_TS + " >= ?";
final String[] selectionArgs = {String.valueOf(toTS), String.valueOf(fromTS)};
final Cursor cursor = getEventsCursor(selection, selectionArgs);
if (cursor != null) {
events.addAll(fillEvents(cursor));
}
if (mCallback != null)
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;
@ -186,20 +204,6 @@ public class DBHelper extends SQLiteOpenHelper {
e.setStartTS(newStartTS);
e.setEndTS(newEndTS);
}
events.addAll(newEvents);
}
}
final String selection = COL_START_TS + " <= ? AND " + COL_END_TS + " >= ?";
final String[] selectionArgs = {String.valueOf(toTS), String.valueOf(fromTS)};
final Cursor cursor = getEventsCursor(selection, selectionArgs);
if (cursor != null) {
events.addAll(fillEvents(cursor));
}
if (mCallback != null)
mCallback.gotEvents(events);
}
public List<Event> getEventsAtReboot() {
List<Event> events = new ArrayList<>();