mark repeating events on main monthly calendar
This commit is contained in:
parent
f11dd4dd2e
commit
a70c14b389
|
@ -7,6 +7,10 @@ public class Constants {
|
|||
public static final String DAY_CODE = "day_code";
|
||||
public static final String EVENT = "event";
|
||||
|
||||
public static final int DAY = 86400;
|
||||
public static final int WEEK = 604800;
|
||||
public static final int YEAR = 31536000;
|
||||
|
||||
// Shared Preferences
|
||||
public static final String PREFS_KEY = "Calendar";
|
||||
public static final String IS_FIRST_RUN = "is_first_run";
|
||||
|
|
|
@ -161,12 +161,26 @@ 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) {
|
||||
final int periods = (ts - e.getStartTS()) / e.getRepeatInterval();
|
||||
e.setStartTS(e.getStartTS() + periods * e.getRepeatInterval());
|
||||
}
|
||||
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 = fillEvents(cursor);
|
||||
events.addAll(fillEvents(cursor));
|
||||
}
|
||||
|
||||
if (mCallback != null)
|
||||
|
@ -205,10 +219,10 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||
final int id = cursor.getInt(cursor.getColumnIndex(COL_ID));
|
||||
final int startTS = cursor.getInt(cursor.getColumnIndex(COL_START_TS));
|
||||
final int endTS = cursor.getInt(cursor.getColumnIndex(COL_END_TS));
|
||||
final String title = cursor.getString(cursor.getColumnIndex(COL_TITLE));
|
||||
final String description = cursor.getString(cursor.getColumnIndex(COL_DESCRIPTION));
|
||||
final int reminderMinutes = cursor.getInt(cursor.getColumnIndex(COL_REMINDER_MINUTES));
|
||||
final int repeatInterval = cursor.getInt(cursor.getColumnIndex(COL_REPEAT_INTERVAL));
|
||||
final String title = cursor.getString(cursor.getColumnIndex(COL_TITLE));
|
||||
final String description = cursor.getString(cursor.getColumnIndex(COL_DESCRIPTION));
|
||||
events.add(new Event(id, startTS, endTS, title, description, reminderMinutes, repeatInterval));
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
|
|
|
@ -34,10 +34,6 @@ import butterknife.OnClick;
|
|||
import butterknife.OnItemSelected;
|
||||
|
||||
public class EventActivity extends SimpleActivity implements DBHelper.DBOperationsListener {
|
||||
private static final int DAILY = 86400;
|
||||
private static final int WEEKLY = 604800;
|
||||
private static final int YEARLY = 31536000;
|
||||
|
||||
@BindView(R.id.event_start_date) TextView mStartDate;
|
||||
@BindView(R.id.event_start_time) TextView mStartTime;
|
||||
@BindView(R.id.event_end_date) TextView mEndDate;
|
||||
|
@ -132,13 +128,13 @@ public class EventActivity extends SimpleActivity implements DBHelper.DBOperatio
|
|||
|
||||
private void setupRepetition() {
|
||||
switch (mEvent.getRepeatInterval()) {
|
||||
case DAILY:
|
||||
case Constants.DAY:
|
||||
mRepetition.setSelection(1);
|
||||
break;
|
||||
case WEEKLY:
|
||||
case Constants.WEEK:
|
||||
mRepetition.setSelection(2);
|
||||
break;
|
||||
case YEARLY:
|
||||
case Constants.YEAR:
|
||||
mRepetition.setSelection(3);
|
||||
break;
|
||||
default:
|
||||
|
@ -244,11 +240,11 @@ public class EventActivity extends SimpleActivity implements DBHelper.DBOperatio
|
|||
private int getRepeatInterval() {
|
||||
switch (mRepetition.getSelectedItemPosition()) {
|
||||
case 1:
|
||||
return DAILY;
|
||||
return Constants.DAY;
|
||||
case 2:
|
||||
return WEEKLY;
|
||||
return Constants.WEEK;
|
||||
case 3:
|
||||
return YEARLY;
|
||||
return Constants.YEAR;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue