move event time updating into a separate function
This commit is contained in:
parent
ffc6d3535e
commit
c0dd90d8fc
|
@ -170,21 +170,7 @@ public class DBHelper extends SQLiteOpenHelper {
|
||||||
if (cursor != null) {
|
if (cursor != null) {
|
||||||
final List<Event> newEvents = fillEvents(cursor);
|
final List<Event> newEvents = fillEvents(cursor);
|
||||||
for (Event e : newEvents) {
|
for (Event e : newEvents) {
|
||||||
final int periods = (ts - e.getStartTS()) / e.getRepeatInterval();
|
updateEventTimes(e, ts);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
events.addAll(newEvents);
|
events.addAll(newEvents);
|
||||||
}
|
}
|
||||||
|
@ -201,6 +187,24 @@ public class DBHelper extends SQLiteOpenHelper {
|
||||||
mCallback.gotEvents(events);
|
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() {
|
public List<Event> getEventsAtReboot() {
|
||||||
List<Event> events = new ArrayList<>();
|
List<Event> events = new ArrayList<>();
|
||||||
final String selection = COL_START_TS + " > ? AND " + COL_REMINDER_MINUTES + " != ?";
|
final String selection = COL_START_TS + " > ? AND " + COL_REMINDER_MINUTES + " != ?";
|
||||||
|
|
Loading…
Reference in New Issue