From 85b124bf872c0d623f056bff5f95889e88823853 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 11 Sep 2016 19:07:20 +0200 Subject: [PATCH] some display correction of recursive events --- .../simplemobiletools/calendar/DBHelper.java | 31 ++++++++++++------- .../calendar/activities/DayActivity.java | 5 ++- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/simplemobiletools/calendar/DBHelper.java b/app/src/main/java/com/simplemobiletools/calendar/DBHelper.java index bc1f09fc3..8d4d5e667 100644 --- a/app/src/main/java/com/simplemobiletools/calendar/DBHelper.java +++ b/app/src/main/java/com/simplemobiletools/calendar/DBHelper.java @@ -162,17 +162,11 @@ public class DBHelper extends SQLiteOpenHelper { public void getEvents(int fromTS, int toTS) { List 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 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 getEventsFor(int ts) { + List 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()); diff --git a/app/src/main/java/com/simplemobiletools/calendar/activities/DayActivity.java b/app/src/main/java/com/simplemobiletools/calendar/activities/DayActivity.java index d1342b67d..99bf42891 100644 --- a/app/src/main/java/com/simplemobiletools/calendar/activities/DayActivity.java +++ b/app/src/main/java/com/simplemobiletools/calendar/activities/DayActivity.java @@ -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 events) {