some display correction of recursive events

This commit is contained in:
tibbi 2016-09-11 19:07:20 +02:00
parent c0dd90d8fc
commit 85b124bf87
2 changed files with 22 additions and 14 deletions

View file

@ -162,17 +162,11 @@ public class DBHelper extends SQLiteOpenHelper {
public void getEvents(int fromTS, int toTS) {
List<Event> events = new ArrayList<>();
for (int ts = fromTS; ts < toTS; ts += Constants.DAY) {
final int dayExclusive = Constants.DAY - 1;
final String selection = "(? - " + COL_REPEAT_START + ") % " + COL_REPEAT_INTERVAL + " BETWEEN 0 AND " + dayExclusive;
final String[] selectionArgs = {String.valueOf(ts)};
final Cursor cursor = getEventsCursor(selection, selectionArgs);
if (cursor != null) {
final List<Event> newEvents = fillEvents(cursor);
for (Event e : newEvents) {
updateEventTimes(e, ts);
}
events.addAll(newEvents);
if (fromTS == toTS) {
events.addAll(getEventsFor(fromTS));
} else {
for (int ts = fromTS; ts <= toTS; ts += Constants.DAY) {
events.addAll(getEventsFor(ts));
}
}
@ -187,6 +181,21 @@ public class DBHelper extends SQLiteOpenHelper {
mCallback.gotEvents(events);
}
private List<Event> getEventsFor(int ts) {
List<Event> newEvents = new ArrayList<>();
final int dayExclusive = Constants.DAY;
final String selection = "(? - " + COL_REPEAT_START + ") % " + COL_REPEAT_INTERVAL + " BETWEEN 0 AND " + dayExclusive;
final String[] selectionArgs = {String.valueOf(ts)};
final Cursor cursor = getEventsCursor(selection, selectionArgs);
if (cursor != null) {
newEvents = fillEvents(cursor);
for (Event e : newEvents) {
updateEventTimes(e, ts);
}
}
return newEvents;
}
private void updateEventTimes(Event e, int ts) {
final int periods = (ts - e.getStartTS()) / e.getRepeatInterval();
DateTime currStart = new DateTime(e.getStartTS() * 1000L, DateTimeZone.getDefault());

View file

@ -25,10 +25,10 @@ import android.widget.TextView;
import com.simplemobiletools.calendar.Constants;
import com.simplemobiletools.calendar.DBHelper;
import com.simplemobiletools.calendar.adapters.EventsAdapter;
import com.simplemobiletools.calendar.Formatter;
import com.simplemobiletools.calendar.R;
import com.simplemobiletools.calendar.Utils;
import com.simplemobiletools.calendar.adapters.EventsAdapter;
import com.simplemobiletools.calendar.models.Event;
import org.joda.time.DateTime;
@ -164,9 +164,8 @@ public class DayActivity extends SimpleActivity
}
private void checkEvents() {
final int startTS = Formatter.getDayStartTS(mDayCode);
final int endTS = Formatter.getDayEndTS(mDayCode);
DBHelper.newInstance(getApplicationContext(), this).getEvents(startTS, endTS);
DBHelper.newInstance(getApplicationContext(), this).getEvents(endTS, endTS);
}
private void updateEvents(List<Event> events) {