save monthly and yearly events a bit differently
This commit is contained in:
parent
82225ae58d
commit
24ef5e9ac6
|
@ -11,7 +11,6 @@ import android.text.TextUtils;
|
||||||
import com.simplemobiletools.calendar.models.Event;
|
import com.simplemobiletools.calendar.models.Event;
|
||||||
|
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.DateTimeZone;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -35,6 +34,8 @@ public class DBHelper extends SQLiteOpenHelper {
|
||||||
private static final String COL_EVENT_ID = "event_id";
|
private static final String COL_EVENT_ID = "event_id";
|
||||||
private static final String COL_REPEAT_START = "repeat_start";
|
private static final String COL_REPEAT_START = "repeat_start";
|
||||||
private static final String COL_REPEAT_INTERVAL = "repeat_interval";
|
private static final String COL_REPEAT_INTERVAL = "repeat_interval";
|
||||||
|
private static final String COL_REPEAT_MONTH = "repeat_month";
|
||||||
|
private static final String COL_REPEAT_DAY = "repeat_day";
|
||||||
|
|
||||||
public static DBHelper newInstance(Context context, DBOperationsListener callback) {
|
public static DBHelper newInstance(Context context, DBOperationsListener callback) {
|
||||||
mCallback = callback;
|
mCallback = callback;
|
||||||
|
@ -76,7 +77,9 @@ public class DBHelper extends SQLiteOpenHelper {
|
||||||
COL_ID + " INTEGER PRIMARY KEY, " +
|
COL_ID + " INTEGER PRIMARY KEY, " +
|
||||||
COL_EVENT_ID + " INTEGER UNIQUE, " +
|
COL_EVENT_ID + " INTEGER UNIQUE, " +
|
||||||
COL_REPEAT_START + " INTEGER, " +
|
COL_REPEAT_START + " INTEGER, " +
|
||||||
COL_REPEAT_INTERVAL + " INTEGER " +
|
COL_REPEAT_INTERVAL + " INTEGER, " +
|
||||||
|
COL_REPEAT_MONTH + " INTEGER, " +
|
||||||
|
COL_REPEAT_DAY + " INTEGER" +
|
||||||
")");
|
")");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,10 +125,21 @@ public class DBHelper extends SQLiteOpenHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
private ContentValues fillMetaValues(Event event) {
|
private ContentValues fillMetaValues(Event event) {
|
||||||
|
final int repeatInterval = event.getRepeatInterval();
|
||||||
final ContentValues values = new ContentValues();
|
final ContentValues values = new ContentValues();
|
||||||
values.put(COL_EVENT_ID, event.getId());
|
values.put(COL_EVENT_ID, event.getId());
|
||||||
values.put(COL_REPEAT_START, event.getStartTS());
|
values.put(COL_REPEAT_START, event.getStartTS());
|
||||||
values.put(COL_REPEAT_INTERVAL, event.getRepeatInterval());
|
values.put(COL_REPEAT_INTERVAL, repeatInterval);
|
||||||
|
final DateTime dateTime = Formatter.getDateTimeFromTS(event.getStartTS());
|
||||||
|
|
||||||
|
if (repeatInterval == Constants.MONTH || repeatInterval == Constants.YEAR) {
|
||||||
|
values.put(COL_REPEAT_DAY, dateTime.getDayOfMonth());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (repeatInterval == Constants.YEAR) {
|
||||||
|
values.put(COL_REPEAT_MONTH, dateTime.getMonthOfYear());
|
||||||
|
}
|
||||||
|
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,7 +208,7 @@ public class DBHelper extends SQLiteOpenHelper {
|
||||||
|
|
||||||
private void updateEventTimes(Event e, int ts) {
|
private void updateEventTimes(Event e, int ts) {
|
||||||
final int periods = (ts - e.getStartTS() + Constants.DAY) / e.getRepeatInterval();
|
final int periods = (ts - e.getStartTS() + Constants.DAY) / e.getRepeatInterval();
|
||||||
DateTime currStart = new DateTime(e.getStartTS() * 1000L, DateTimeZone.getDefault());
|
DateTime currStart = Formatter.getDateTimeFromTS(e.getStartTS());
|
||||||
DateTime newStart;
|
DateTime newStart;
|
||||||
if (e.getRepeatInterval() == Constants.DAY) {
|
if (e.getRepeatInterval() == Constants.DAY) {
|
||||||
newStart = currStart.plusDays(periods);
|
newStart = currStart.plusDays(periods);
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class Formatter {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getTime(int ts) {
|
public static String getTime(int ts) {
|
||||||
final DateTime dateTime = new DateTime(ts * 1000L, DateTimeZone.getDefault());
|
final DateTime dateTime = getDateTimeFromTS(ts);
|
||||||
return getEventTime(dateTime);
|
return getEventTime(dateTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ public class Formatter {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getDayCodeFromTS(int ts) {
|
public static String getDayCodeFromTS(int ts) {
|
||||||
final DateTime dateTime = new DateTime(ts * 1000L, DateTimeZone.getDefault());
|
final DateTime dateTime = getDateTimeFromTS(ts);
|
||||||
return dateTime.toString(Formatter.DAYCODE_PATTERN);
|
return dateTime.toString(Formatter.DAYCODE_PATTERN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,6 +69,10 @@ public class Formatter {
|
||||||
return dateTime.toString(Formatter.DAYCODE_PATTERN);
|
return dateTime.toString(Formatter.DAYCODE_PATTERN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static DateTime getDateTimeFromTS(int ts) {
|
||||||
|
return new DateTime(ts * 1000L, DateTimeZone.getDefault());
|
||||||
|
}
|
||||||
|
|
||||||
// use manually translated month names, as DateFormat and Joda have issues with a lot of languages
|
// use manually translated month names, as DateFormat and Joda have issues with a lot of languages
|
||||||
public static String getMonthName(Context context, int id) {
|
public static String getMonthName(Context context, int id) {
|
||||||
return context.getResources().getStringArray(R.array.months)[id];
|
return context.getResources().getStringArray(R.array.months)[id];
|
||||||
|
|
|
@ -88,8 +88,8 @@ public class EventActivity extends SimpleActivity implements DBHelper.DBOperatio
|
||||||
|
|
||||||
private void setupEditEvent() {
|
private void setupEditEvent() {
|
||||||
setTitle(getResources().getString(R.string.edit_event));
|
setTitle(getResources().getString(R.string.edit_event));
|
||||||
mEventStartDateTime = new DateTime(mEvent.getStartTS() * 1000L, DateTimeZone.getDefault());
|
mEventStartDateTime = Formatter.getDateTimeFromTS(mEvent.getStartTS());
|
||||||
mEventEndDateTime = new DateTime(mEvent.getEndTS() * 1000L, DateTimeZone.getDefault());
|
mEventEndDateTime = Formatter.getDateTimeFromTS(mEvent.getEndTS());
|
||||||
mTitleET.setText(mEvent.getTitle());
|
mTitleET.setText(mEvent.getTitle());
|
||||||
mDescriptionET.setText(mEvent.getDescription());
|
mDescriptionET.setText(mEvent.getDescription());
|
||||||
hideKeyboard();
|
hideKeyboard();
|
||||||
|
|
Loading…
Reference in New Issue