fix #216, add a Location field

This commit is contained in:
tibbi 2017-10-21 10:13:27 +02:00
parent 146fac537f
commit 1028781bbb
26 changed files with 86 additions and 25 deletions

View file

@ -70,8 +70,9 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
mReminder2Minutes = -1
mReminder3Minutes = -1
val startTS = intent.getIntExtra(NEW_EVENT_START_TS, 0)
if (startTS == 0)
if (startTS == 0) {
return
}
setupNewEvent(Formatter.getDateTimeFromTS(startTS))
}
@ -82,6 +83,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
updateEndTexts()
updateEventType()
updateCalDAVCalendar()
updateLocation()
event_start_date.setOnClickListener { setupStartDate() }
event_start_time.setOnClickListener { setupStartTime() }
@ -115,6 +117,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
mEventStartDateTime = Formatter.getDateTimeFromTS(realStart)
mEventEndDateTime = Formatter.getDateTimeFromTS(realStart + duration)
event_title.setText(mEvent.title)
event_location.setText(mEvent.location)
event_description.setText(mEvent.description)
event_description.movementMethod = LinkMovementMethod.getInstance()
@ -201,18 +204,22 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
}
private fun checkRepetitionLimitText() {
event_repetition_limit.text = if (mRepeatLimit == 0) {
event_repetition_limit.text = when {
mRepeatLimit == 0 -> {
event_repetition_limit_label.text = getString(R.string.repeat)
resources.getString(R.string.forever)
} else if (mRepeatLimit > 0) {
}
mRepeatLimit > 0 -> {
event_repetition_limit_label.text = getString(R.string.repeat_till)
val repeatLimitDateTime = Formatter.getDateTimeFromTS(mRepeatLimit)
Formatter.getFullDate(applicationContext, repeatLimitDateTime)
} else {
}
else -> {
event_repetition_limit_label.text = getString(R.string.repeat)
"${-mRepeatLimit} ${getString(R.string.times)}"
}
}
}
private fun showRepetitionRuleDialog() {
hideKeyboard()
@ -446,6 +453,10 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
}
}
private fun updateLocation() {
event_location.setText(mEvent.location)
}
private fun toggleAllDay(isChecked: Boolean) {
hideKeyboard()
event_start_time.beGoneIf(isChecked)
@ -519,12 +530,11 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
}
val reminders = sortedSetOf(mReminder1Minutes, mReminder2Minutes, mReminder3Minutes).filter { it != REMINDER_OFF }
val newDescription = event_description.value
mEvent.apply {
startTS = newStartTS
endTS = newEndTS
title = newTitle
description = newDescription
description = event_description.value
reminder1Minutes = reminders.elementAtOrElse(0) { REMINDER_OFF }
reminder2Minutes = reminders.elementAtOrElse(1) { REMINDER_OFF }
reminder3Minutes = reminders.elementAtOrElse(2) { REMINDER_OFF }
@ -538,6 +548,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
isDstIncluded = TimeZone.getDefault().inDaylightTime(Date())
lastUpdated = System.currentTimeMillis()
source = newSource
location = event_location.value
}
// recreate the event if it was moved in a different CalDAV calendar

View file

@ -209,7 +209,8 @@ class CalDAVHandler(val context: Context) {
CalendarContract.Events.DTEND,
CalendarContract.Events.DURATION,
CalendarContract.Events.ALL_DAY,
CalendarContract.Events.RRULE)
CalendarContract.Events.RRULE,
CalendarContract.Events.EVENT_LOCATION)
val selection = "${CalendarContract.Events.CALENDAR_ID} = $calendarId"
var cursor: Cursor? = null
@ -224,6 +225,7 @@ class CalDAVHandler(val context: Context) {
var endTS = (cursor.getLongValue(CalendarContract.Events.DTEND) / 1000).toInt()
val allDay = cursor.getIntValue(CalendarContract.Events.ALL_DAY)
val rrule = cursor.getStringValue(CalendarContract.Events.RRULE) ?: ""
val location = cursor.getStringValue(CalendarContract.Events.EVENT_LOCATION) ?: ""
val reminders = getCalDAVEventReminders(id)
if (endTS == 0) {
@ -235,7 +237,8 @@ class CalDAVHandler(val context: Context) {
val repeatRule = Parser().parseRepeatInterval(rrule, startTS)
val event = Event(0, startTS, endTS, title, description, reminders.getOrElse(0, { -1 }),
reminders.getOrElse(1, { -1 }), reminders.getOrElse(2, { -1 }), repeatRule.repeatInterval,
importId, allDay, repeatRule.repeatLimit, repeatRule.repeatRule, eventTypeId, source = "$CALDAV-$calendarId")
importId, allDay, repeatRule.repeatLimit, repeatRule.repeatRule, eventTypeId, source = "$CALDAV-$calendarId",
location = location)
if (event.getIsAllDay() && endTS > startTS) {
event.endTS -= DAY
@ -330,6 +333,7 @@ class CalDAVHandler(val context: Context) {
put(CalendarContract.Events.ALL_DAY, if (event.getIsAllDay()) 1 else 0)
put(CalendarContract.Events.RRULE, Parser().getRepeatCode(event))
put(CalendarContract.Events.EVENT_TIMEZONE, TimeZone.getDefault().toString())
put(CalendarContract.Events.EVENT_LOCATION, event.location)
if (event.getIsAllDay() && event.endTS > event.startTS)
event.endTS += DAY

View file

@ -92,6 +92,7 @@ val STATUS = "STATUS:"
val EXDATE = "EXDATE"
val BYDAY = "BYDAY"
val BYMONTHDAY = "BYMONTHDAY"
val LOCATION = "LOCATION:"
val DISPLAY = "DISPLAY"
val FREQ = "FREQ"

View file

@ -37,6 +37,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
private val COL_IS_DST_INCLUDED = "is_dst_included"
private val COL_LAST_UPDATED = "last_updated"
private val COL_EVENT_SOURCE = "event_source"
private val COL_LOCATION = "location"
private val COL_SOURCE = "source" // deprecated
private val META_TABLE_NAME = "events_meta"
@ -64,7 +65,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
private val mDb: SQLiteDatabase = writableDatabase
companion object {
private val DB_VERSION = 18
private val DB_VERSION = 19
val DB_NAME = "events.db"
val REGULAR_EVENT_TYPE_ID = 1
var dbInstance: DBHelper? = null
@ -84,7 +85,8 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
db.execSQL("CREATE TABLE $MAIN_TABLE_NAME ($COL_ID INTEGER PRIMARY KEY AUTOINCREMENT, $COL_START_TS INTEGER, $COL_END_TS INTEGER, " +
"$COL_TITLE TEXT, $COL_DESCRIPTION TEXT, $COL_REMINDER_MINUTES INTEGER, $COL_REMINDER_MINUTES_2 INTEGER, $COL_REMINDER_MINUTES_3 INTEGER, " +
"$COL_IMPORT_ID TEXT, $COL_FLAGS INTEGER, $COL_EVENT_TYPE INTEGER NOT NULL DEFAULT $REGULAR_EVENT_TYPE_ID, " +
"$COL_PARENT_EVENT_ID INTEGER, $COL_OFFSET TEXT, $COL_IS_DST_INCLUDED INTEGER, $COL_LAST_UPDATED INTEGER, $COL_EVENT_SOURCE TEXT)")
"$COL_PARENT_EVENT_ID INTEGER, $COL_OFFSET TEXT, $COL_IS_DST_INCLUDED INTEGER, $COL_LAST_UPDATED INTEGER, $COL_EVENT_SOURCE TEXT, " +
"$COL_LOCATION TEXT)")
createMetaTable(db)
createTypesTable(db)
@ -170,6 +172,10 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
if (oldVersion < 18) {
updateOldMonthlyEvents(db)
}
if (oldVersion < 19) {
db.execSQL("ALTER TABLE $MAIN_TABLE_NAME ADD COLUMN $COL_LOCATION TEXT DEFAULT ''")
}
}
private fun createMetaTable(db: SQLiteDatabase) {
@ -258,6 +264,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
put(COL_IS_DST_INCLUDED, if (event.isDstIncluded) 1 else 0)
put(COL_LAST_UPDATED, event.lastUpdated)
put(COL_EVENT_SOURCE, event.source)
put(COL_LOCATION, event.location)
}
}
@ -767,7 +774,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
private val allColumns: Array<String>
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_OFFSET,
COL_IS_DST_INCLUDED, COL_LAST_UPDATED, COL_EVENT_SOURCE)
COL_IS_DST_INCLUDED, COL_LAST_UPDATED, COL_EVENT_SOURCE, COL_LOCATION)
private fun fillEvents(cursor: Cursor?): List<Event> {
val eventTypeColors = SparseIntArray()
@ -776,7 +783,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
}
val events = ArrayList<Event>()
try {
cursor.use { cursor ->
if (cursor != null && cursor.moveToFirst()) {
do {
val id = cursor.getIntValue(COL_ID)
@ -797,6 +804,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
val isDstIncluded = cursor.getIntValue(COL_IS_DST_INCLUDED) == 1
val lastUpdated = cursor.getLongValue(COL_LAST_UPDATED)
val source = cursor.getStringValue(COL_EVENT_SOURCE)
val location = cursor.getStringValue(COL_LOCATION)
val color = eventTypeColors[eventType]
val ignoreEventOccurrences = if (repeatInterval != 0) {
@ -811,12 +819,10 @@ 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, offset, isDstIncluded,
0, lastUpdated, source, color)
0, lastUpdated, source, color, location)
events.add(event)
} while (cursor.moveToNext())
}
} finally {
cursor?.close()
}
return events
}

View file

@ -33,6 +33,7 @@ class IcsExporter {
event.importId.let { if (it.isNotEmpty()) out.writeLn("$UID$it") }
event.eventType.let { out.writeLn("$CATEGORIES${activity.dbHelper.getEventType(it)?.title}") }
event.lastUpdated.let { out.writeLn("$LAST_MODIFIED:${Formatter.getExportedTime(it)}") }
event.location.let { if (it.isNotEmpty()) out.writeLn("$LOCATION$it") }
if (event.getIsAllDay()) {
out.writeLn("$DTSTART;$VALUE=$DATE:${Formatter.getDayCodeFromTS(event.startTS)}")

View file

@ -29,6 +29,7 @@ class IcsImporter {
private var curRepeatRule = 0
private var curEventType = DBHelper.REGULAR_EVENT_TYPE_ID
private var curLastModified = 0L
private var curLocation = ""
private var isNotificationDescription = false
private var lastReminderAction = ""
@ -92,6 +93,8 @@ class IcsImporter {
curLastModified = getTimestamp(line.substring(LAST_MODIFIED.length)) * 1000L
} else if (line.startsWith(EXDATE)) {
curRepeatExceptions.add(getTimestamp(line.substring(EXDATE.length)))
} else if (line.startsWith(LOCATION)) {
curLocation = line.substring(LOCATION.length)
} else if (line == END_EVENT) {
if (curStart != -1 && curEnd == -1)
curEnd = curStart
@ -107,7 +110,7 @@ class IcsImporter {
val event = Event(0, curStart, curEnd, curTitle, curDescription, curReminderMinutes.getOrElse(0, { -1 }),
curReminderMinutes.getOrElse(1, { -1 }), curReminderMinutes.getOrElse(2, { -1 }), curRepeatInterval,
curImportId, curFlags, curRepeatLimit, curRepeatRule, curEventType, lastUpdated = curLastModified,
source = SOURCE_IMPORTED_ICS)
source = SOURCE_IMPORTED_ICS, location = curLocation)
if (event.getIsAllDay() && curEnd > curStart) {
event.endTS -= DAY
@ -197,6 +200,7 @@ class IcsImporter {
curRepeatRule = 0
curEventType = DBHelper.REGULAR_EVENT_TYPE_ID
curLastModified = 0L
curLocation = ""
isNotificationDescription = false
lastReminderAction = ""
}

View file

@ -12,7 +12,7 @@ data class Event(var id: Int = 0, var startTS: Int = 0, var endTS: Int = 0, var
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<Int> = ArrayList(),
var offset: String = "", var isDstIncluded: Boolean = false, var parentId: Int = 0, var lastUpdated: Long = 0L,
var source: String = SOURCE_SIMPLE_CALENDAR, var color: Int = 0) : Serializable {
var source: String = SOURCE_SIMPLE_CALENDAR, var color: Int = 0, var location: String = "") : Serializable {
companion object {
private val serialVersionUID = -32456795132345616L

View file

@ -28,13 +28,29 @@
android:textSize="@dimen/day_text_size"/>
<com.simplemobiletools.commons.views.MyEditText
android:id="@+id/event_description"
android:id="@+id/event_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/event_title"
android:layout_marginLeft="@dimen/activity_margin"
android:layout_marginRight="@dimen/activity_margin"
android:layout_marginTop="@dimen/activity_margin"
android:hint="@string/location"
android:inputType="textCapWords"
android:maxLength="80"
android:maxLines="1"
android:minEms="20"
android:textCursorDrawable="@null"
android:textSize="@dimen/day_text_size"/>
<com.simplemobiletools.commons.views.MyEditText
android:id="@+id/event_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/event_location"
android:layout_marginLeft="@dimen/activity_margin"
android:layout_marginRight="@dimen/activity_margin"
android:layout_marginTop="@dimen/activity_margin"
android:autoLink="all"
android:gravity="top"
android:hint="@string/description"

View file

@ -28,6 +28,7 @@
<string name="event_updated">Událost úspěšně změněna</string>
<string name="filter">Filtrovat</string>
<string name="filter_events_by_type">Filtrovat události podle typu</string>
<string name="location">Location</string>
<!-- Event Repetition -->
<string name="repetition">Opakovaná událost</string>

View file

@ -28,6 +28,7 @@
<string name="event_updated">Termin erfolgreich aktualisiert</string>
<string name="filter">Sortieren</string>
<string name="filter_events_by_type">Sortiere Termine nach Typ</string>
<string name="location">Location</string>
<!-- Event Repetition -->
<string name="repetition">Wiederholung</string>

View file

@ -28,6 +28,7 @@
<string name="event_updated">El evento se ha actualizado con éxito</string>
<string name="filter">Filtrar</string>
<string name="filter_events_by_type">Filtrar eventos según tipo</string>
<string name="location">Location</string>
<!-- Event Repetition -->
<string name="repetition">Repetición</string>

View file

@ -28,6 +28,7 @@
<string name="event_updated">Evénement ajouté avec succès</string>
<string name="filter">Filtrer</string>
<string name="filter_events_by_type">Filtrer les evénements par type</string>
<string name="location">Location</string>
<!-- Event Repetition -->
<string name="repetition">Répétition</string>

View file

@ -28,6 +28,7 @@
<string name="event_updated">इवेंट सफलतापूर्वक अपडेट किया गया</string>
<string name="filter">Filter</string>
<string name="filter_events_by_type">Filter events by type</string>
<string name="location">Location</string>
<!-- Event Repetition -->
<string name="repetition">दुहराव</string>

View file

@ -28,6 +28,7 @@
<string name="event_updated">Bejegyzés frissítve</string>
<string name="filter">Filter</string>
<string name="filter_events_by_type">Filter events by type</string>
<string name="location">Location</string>
<!-- Event Repetition -->
<string name="repetition">Ismétlés</string>

View file

@ -28,6 +28,7 @@
<string name="event_updated">Evento aggiornato correttamente</string>
<string name="filter">Filtro</string>
<string name="filter_events_by_type">Filtra eventi per tipologia</string>
<string name="location">Location</string>
<!-- Event Repetition -->
<string name="repetition">Ripeti</string>

View file

@ -28,6 +28,7 @@
<string name="event_updated">האירוע עודכן בהצלחה</string>
<string name="filter">Filter</string>
<string name="filter_events_by_type">Filter events by type</string>
<string name="location">Location</string>
<!-- Event Repetition -->
<string name="repetition">Repetition</string>

View file

@ -28,6 +28,7 @@
<string name="event_updated">イベントを正常に更新しました</string>
<string name="filter">Filter</string>
<string name="filter_events_by_type">Filter events by type</string>
<string name="location">Location</string>
<!-- Event Repetition -->
<string name="repetition">繰り返し</string>

View file

@ -28,6 +28,7 @@
<string name="event_updated">이벤트를 수정했습니다</string>
<string name="filter">필터</string>
<string name="filter_events_by_type">유형별 이벤트</string>
<string name="location">Location</string>
<!-- Event Repetition -->
<string name="repetition">반복</string>

View file

@ -28,6 +28,7 @@
<string name="event_updated">Wydarzenie zostało zaktualizowane</string>
<string name="filter">Filtr</string>
<string name="filter_events_by_type">Filtruj wydarzenia według typu</string>
<string name="location">Location</string>
<!-- Event Repetition -->
<string name="repetition">Powtórzenie</string>

View file

@ -28,6 +28,7 @@
<string name="event_updated">Evento atualizado com sucesso</string>
<string name="filter">Filtrar</string>
<string name="filter_events_by_type">Filtrar eventos por tipo</string>
<string name="location">Location</string>
<!-- Event Repetition -->
<string name="repetition">Repetição</string>

View file

@ -28,6 +28,7 @@
<string name="event_updated">Evento atualizado com sucesso</string>
<string name="filter">Filtrar</string>
<string name="filter_events_by_type">Filtrar eventos por tipo</string>
<string name="location">Location</string>
<!-- Event Repetition -->
<string name="repetition">Repetição</string>

View file

@ -28,6 +28,7 @@
<string name="event_updated">Событие успешно обновлено</string>
<string name="filter">Фильтрация</string>
<string name="filter_events_by_type">Фильтровать события по типу</string>
<string name="location">Location</string>
<!-- Event Repetition -->
<string name="repetition">Повторять</string>

View file

@ -28,6 +28,7 @@
<string name="event_updated">Udalosť bola úspešne upravená</string>
<string name="filter">Filtrovať</string>
<string name="filter_events_by_type">Filtrovať udalosti podľa typu</string>
<string name="location">Miesto</string>
<!-- Event Repetition -->
<string name="repetition">Opakovanie</string>

View file

@ -28,6 +28,7 @@
<string name="event_updated">Händelsen uppdaterad</string>
<string name="filter">Filtrera</string>
<string name="filter_events_by_type">Filtrera händelser efter typ</string>
<string name="location">Location</string>
<!-- Event Repetition -->
<string name="repetition">Upprepning</string>

View file

@ -28,6 +28,7 @@
<string name="event_updated">Etkinlik başarıyla güncellendi</string>
<string name="filter">Filtre</string>
<string name="filter_events_by_type">Etkinlikleri türe göre filtreleyin</string>
<string name="location">Location</string>
<!-- Event Repetition -->
<string name="repetition">Tekrarla</string>

View file

@ -28,6 +28,7 @@
<string name="event_updated">Event updated successfully</string>
<string name="filter">Filter</string>
<string name="filter_events_by_type">Filter events by type</string>
<string name="location">Location</string>
<!-- Event Repetition -->
<string name="repetition">Repetition</string>