From 4ba7ab7d1ae91210b71c6a0405da7752f3e9473c Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 4 Jun 2017 22:21:59 +0200 Subject: [PATCH] store current time offset at inserting/updating event --- .../simplemobiletools/calendar/activities/EventActivity.kt | 1 + .../com/simplemobiletools/calendar/extensions/Context.kt | 5 +++++ .../com/simplemobiletools/calendar/helpers/DBHelper.kt | 6 ++++-- .../kotlin/com/simplemobiletools/calendar/models/Event.kt | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt index d3ac909d1..7b2948825 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt @@ -452,6 +452,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener { repeatLimit = if (repeatInterval == 0) 0 else mRepeatLimit repeatRule = mRepeatRule eventType = mEventTypeId + offset = getCurrentOffset() } if (mEvent.id == 0) { diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt index 074b2a243..50c143470 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt @@ -16,6 +16,7 @@ import android.support.v7.app.NotificationCompat import com.simplemobiletools.calendar.R import com.simplemobiletools.calendar.activities.EventActivity import com.simplemobiletools.calendar.helpers.* +import com.simplemobiletools.calendar.helpers.Formatter import com.simplemobiletools.calendar.models.Event import com.simplemobiletools.calendar.receivers.NotificationReceiver import com.simplemobiletools.calendar.services.SnoozeService @@ -24,6 +25,8 @@ import com.simplemobiletools.commons.extensions.isKitkatPlus import com.simplemobiletools.commons.extensions.isLollipopPlus import org.joda.time.DateTime import org.joda.time.DateTimeZone +import java.text.SimpleDateFormat +import java.util.* fun Context.updateWidgets() { val widgetsCnt = AppWidgetManager.getInstance(this).getAppWidgetIds(ComponentName(this, MyWidgetMonthlyProvider::class.java)) @@ -220,6 +223,8 @@ fun Context.launchNewEventIntent(startNewTask: Boolean = false, today: Boolean = fun Context.getNewEventTimestampFromCode(dayCode: String) = Formatter.getLocalDateTimeFromCode(dayCode).withTime(13, 0, 0, 0).seconds() +fun Context.getCurrentOffset() = SimpleDateFormat("Z", Locale.getDefault()).format(Date()) + val Context.config: Config get() = Config.newInstance(this) val Context.dbHelper: DBHelper get() = DBHelper.newInstance(this) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt index 864e48148..ca622eee6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt @@ -204,6 +204,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont put(COL_FLAGS, event.flags) put(COL_EVENT_TYPE, event.eventType) put(COL_PARENT_EVENT_ID, 0) + put(COL_OFFSET, event.offset) } } @@ -537,7 +538,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont private val allColumns: Array get() = arrayOf("$MAIN_TABLE_NAME.$COL_ID", COL_START_TS, COL_END_TS, COL_TITLE, COL_DESCRIPTION, COL_REMINDER_MINUTES, COL_REMINDER_MINUTES_2, - COL_REMINDER_MINUTES_3, COL_REPEAT_INTERVAL, COL_REPEAT_RULE, COL_IMPORT_ID, COL_FLAGS, COL_REPEAT_LIMIT, COL_EVENT_TYPE) + COL_REMINDER_MINUTES_3, COL_REPEAT_INTERVAL, COL_REPEAT_RULE, COL_IMPORT_ID, COL_FLAGS, COL_REPEAT_LIMIT, COL_EVENT_TYPE, COL_OFFSET) private fun fillEvents(cursor: Cursor?): List { val events = ArrayList() @@ -558,6 +559,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont val flags = cursor.getIntValue(COL_FLAGS) val repeatLimit = cursor.getIntValue(COL_REPEAT_LIMIT) val eventType = cursor.getIntValue(COL_EVENT_TYPE) + val offset = cursor.getStringValue(COL_OFFSET) val ignoreEventOccurrences = if (repeatInterval != 0) { getIgnoredOccurrences(id) @@ -570,7 +572,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont } val event = Event(id, startTS, endTS, title, description, reminder1Minutes, reminder2Minutes, reminder3Minutes, - repeatInterval, importId, flags, repeatLimit, repeatRule, eventType, ignoreEventOccurrences) + repeatInterval, importId, flags, repeatLimit, repeatRule, eventType, ignoreEventOccurrences, offset) events.add(event) } while (cursor.moveToNext()) } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/models/Event.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/models/Event.kt index d6be28a0d..1a693bf14 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/models/Event.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/models/Event.kt @@ -10,7 +10,7 @@ import java.util.* data class Event(var id: Int = 0, var startTS: Int = 0, var endTS: Int = 0, var title: String = "", var description: String = "", var reminder1Minutes: Int = -1, var reminder2Minutes: Int = -1, var reminder3Minutes: Int = -1, var repeatInterval: Int = 0, var importId: String? = "", var flags: Int = 0, var repeatLimit: Int = 0, var repeatRule: Int = 0, - var eventType: Int = DBHelper.REGULAR_EVENT_TYPE_ID, var ignoreEventOccurrences: ArrayList = ArrayList()) : Serializable { + var eventType: Int = DBHelper.REGULAR_EVENT_TYPE_ID, var ignoreEventOccurrences: ArrayList = ArrayList(), var offset: String = "") : Serializable { companion object { private val serialVersionUID = -32456795132345616L