adding monthly repetition + some corrections
This commit is contained in:
parent
85b124bf87
commit
82225ae58d
|
@ -9,6 +9,7 @@ public class Constants {
|
|||
|
||||
public static final int DAY = 86400;
|
||||
public static final int WEEK = 604800;
|
||||
public static final int MONTH = 2592000;
|
||||
public static final int YEAR = 31536000;
|
||||
|
||||
// Shared Preferences
|
||||
|
|
|
@ -162,15 +162,11 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||
|
||||
public void getEvents(int fromTS, int toTS) {
|
||||
List<Event> events = new ArrayList<>();
|
||||
if (fromTS == toTS) {
|
||||
events.addAll(getEventsFor(fromTS));
|
||||
} else {
|
||||
for (int ts = fromTS; ts <= toTS; ts += Constants.DAY) {
|
||||
events.addAll(getEventsFor(ts));
|
||||
}
|
||||
for (int ts = fromTS; ts <= toTS; ts += Constants.DAY) {
|
||||
events.addAll(getEventsFor(ts));
|
||||
}
|
||||
|
||||
final String selection = COL_START_TS + " <= ? AND " + COL_END_TS + " >= ?";
|
||||
final String selection = COL_START_TS + " <= ? AND " + COL_END_TS + " >= ? AND " + COL_REPEAT_INTERVAL + " IS NULL";
|
||||
final String[] selectionArgs = {String.valueOf(toTS), String.valueOf(fromTS)};
|
||||
final Cursor cursor = getEventsCursor(selection, selectionArgs);
|
||||
if (cursor != null) {
|
||||
|
@ -183,9 +179,9 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||
|
||||
private List<Event> getEventsFor(int ts) {
|
||||
List<Event> newEvents = new ArrayList<>();
|
||||
final int dayExclusive = 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 String[] selectionArgs = {String.valueOf(ts + 84600)};
|
||||
final Cursor cursor = getEventsCursor(selection, selectionArgs);
|
||||
if (cursor != null) {
|
||||
newEvents = fillEvents(cursor);
|
||||
|
@ -197,13 +193,15 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||
}
|
||||
|
||||
private void updateEventTimes(Event e, int ts) {
|
||||
final int periods = (ts - e.getStartTS()) / e.getRepeatInterval();
|
||||
final int periods = (ts - e.getStartTS() + Constants.DAY) / 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 if (e.getRepeatInterval() == Constants.MONTH) {
|
||||
newStart = currStart.plusMonths(periods);
|
||||
} else {
|
||||
newStart = currStart.plusYears(periods);
|
||||
}
|
||||
|
|
|
@ -164,8 +164,9 @@ 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(endTS, endTS);
|
||||
DBHelper.newInstance(getApplicationContext(), this).getEvents(startTS, endTS);
|
||||
}
|
||||
|
||||
private void updateEvents(List<Event> events) {
|
||||
|
|
|
@ -134,9 +134,12 @@ public class EventActivity extends SimpleActivity implements DBHelper.DBOperatio
|
|||
case Constants.WEEK:
|
||||
mRepetition.setSelection(2);
|
||||
break;
|
||||
case Constants.YEAR:
|
||||
case Constants.MONTH:
|
||||
mRepetition.setSelection(3);
|
||||
break;
|
||||
case Constants.YEAR:
|
||||
mRepetition.setSelection(4);
|
||||
break;
|
||||
default:
|
||||
mRepetition.setSelection(0);
|
||||
break;
|
||||
|
@ -244,6 +247,8 @@ public class EventActivity extends SimpleActivity implements DBHelper.DBOperatio
|
|||
case 2:
|
||||
return Constants.WEEK;
|
||||
case 3:
|
||||
return Constants.MONTH;
|
||||
case 4:
|
||||
return Constants.YEAR;
|
||||
default:
|
||||
return 0;
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
<string name="none">None</string>
|
||||
<string name="daily">Daily</string>
|
||||
<string name="weekly">Weekly</string>
|
||||
<string name="monthly">Monthly</string>
|
||||
<string name="yearly">Yearly</string>
|
||||
|
||||
<!-- Day details -->
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
<string name="none">None</string>
|
||||
<string name="daily">Daily</string>
|
||||
<string name="weekly">Weekly</string>
|
||||
<string name="monthly">Monthly</string>
|
||||
<string name="yearly">Yearly</string>
|
||||
|
||||
<!-- Day details -->
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
<string name="none">None</string>
|
||||
<string name="daily">Daily</string>
|
||||
<string name="weekly">Weekly</string>
|
||||
<string name="monthly">Monthly</string>
|
||||
<string name="yearly">Yearly</string>
|
||||
|
||||
<!-- Day details -->
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
<string name="none">None</string>
|
||||
<string name="daily">Daily</string>
|
||||
<string name="weekly">Weekly</string>
|
||||
<string name="monthly">Monthly</string>
|
||||
<string name="yearly">Yearly</string>
|
||||
|
||||
<!-- Day details -->
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
<item>@string/none</item>
|
||||
<item>@string/daily</item>
|
||||
<item>@string/weekly</item>
|
||||
<item>@string/monthly</item>
|
||||
<item>@string/yearly</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
<string name="none">None</string>
|
||||
<string name="daily">Daily</string>
|
||||
<string name="weekly">Weekly</string>
|
||||
<string name="monthly">Monthly</string>
|
||||
<string name="yearly">Yearly</string>
|
||||
|
||||
<!-- Day details -->
|
||||
|
|
Loading…
Reference in New Issue