some display correction of recursive events
This commit is contained in:
parent
c0dd90d8fc
commit
85b124bf87
2 changed files with 22 additions and 14 deletions
|
@ -162,17 +162,11 @@ public class DBHelper extends SQLiteOpenHelper {
|
||||||
|
|
||||||
public void getEvents(int fromTS, int toTS) {
|
public void getEvents(int fromTS, int toTS) {
|
||||||
List<Event> events = new ArrayList<>();
|
List<Event> events = new ArrayList<>();
|
||||||
for (int ts = fromTS; ts < toTS; ts += Constants.DAY) {
|
if (fromTS == toTS) {
|
||||||
final int dayExclusive = Constants.DAY - 1;
|
events.addAll(getEventsFor(fromTS));
|
||||||
final String selection = "(? - " + COL_REPEAT_START + ") % " + COL_REPEAT_INTERVAL + " BETWEEN 0 AND " + dayExclusive;
|
} else {
|
||||||
final String[] selectionArgs = {String.valueOf(ts)};
|
for (int ts = fromTS; ts <= toTS; ts += Constants.DAY) {
|
||||||
final Cursor cursor = getEventsCursor(selection, selectionArgs);
|
events.addAll(getEventsFor(ts));
|
||||||
if (cursor != null) {
|
|
||||||
final List<Event> newEvents = fillEvents(cursor);
|
|
||||||
for (Event e : newEvents) {
|
|
||||||
updateEventTimes(e, ts);
|
|
||||||
}
|
|
||||||
events.addAll(newEvents);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,6 +181,21 @@ public class DBHelper extends SQLiteOpenHelper {
|
||||||
mCallback.gotEvents(events);
|
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) {
|
private void updateEventTimes(Event e, int ts) {
|
||||||
final int periods = (ts - e.getStartTS()) / e.getRepeatInterval();
|
final int periods = (ts - e.getStartTS()) / e.getRepeatInterval();
|
||||||
DateTime currStart = new DateTime(e.getStartTS() * 1000L, DateTimeZone.getDefault());
|
DateTime currStart = new DateTime(e.getStartTS() * 1000L, DateTimeZone.getDefault());
|
||||||
|
|
|
@ -25,10 +25,10 @@ import android.widget.TextView;
|
||||||
|
|
||||||
import com.simplemobiletools.calendar.Constants;
|
import com.simplemobiletools.calendar.Constants;
|
||||||
import com.simplemobiletools.calendar.DBHelper;
|
import com.simplemobiletools.calendar.DBHelper;
|
||||||
import com.simplemobiletools.calendar.adapters.EventsAdapter;
|
|
||||||
import com.simplemobiletools.calendar.Formatter;
|
import com.simplemobiletools.calendar.Formatter;
|
||||||
import com.simplemobiletools.calendar.R;
|
import com.simplemobiletools.calendar.R;
|
||||||
import com.simplemobiletools.calendar.Utils;
|
import com.simplemobiletools.calendar.Utils;
|
||||||
|
import com.simplemobiletools.calendar.adapters.EventsAdapter;
|
||||||
import com.simplemobiletools.calendar.models.Event;
|
import com.simplemobiletools.calendar.models.Event;
|
||||||
|
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
|
@ -164,9 +164,8 @@ public class DayActivity extends SimpleActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkEvents() {
|
private void checkEvents() {
|
||||||
final int startTS = Formatter.getDayStartTS(mDayCode);
|
|
||||||
final int endTS = Formatter.getDayEndTS(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) {
|
private void updateEvents(List<Event> events) {
|
||||||
|
|
Loading…
Reference in a new issue