diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/BufferedWriter.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/BufferedWriter.kt new file mode 100644 index 000000000..195484320 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/BufferedWriter.kt @@ -0,0 +1,8 @@ +package com.simplemobiletools.calendar.extensions + +import java.io.BufferedWriter + +fun BufferedWriter.writeLn(line: String) { + write(line) + newLine() +} diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt index cdf387b87..ac7b96fdc 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt @@ -50,8 +50,10 @@ val letterIDs = intArrayOf(R.string.sunday_letter, R.string.monday_letter, R.str val FLAG_ALL_DAY = 1 // constants related to ICS file exporting / importing +val BEGIN_CALENDAR = "BEGIN:VCALENDAR" +val END_CALENDAR = "END:VCALENDAR" val BEGIN_EVENT = "BEGIN:VEVENT" -val END = "END:VEVENT" +val END_EVENT = "END:VEVENT" val DTSTART = "DTSTART" val DTEND = "DTEND" val DURATION = "DURATION:" diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/IcsExporter.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/IcsExporter.kt index 6c0dbab1b..fb9bd2e82 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/IcsExporter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/IcsExporter.kt @@ -1,7 +1,9 @@ package com.simplemobiletools.calendar.helpers import android.content.Context +import com.simplemobiletools.calendar.extensions.writeLn import com.simplemobiletools.calendar.helpers.IcsExporter.ExportResult.* +import java.io.File class IcsExporter { enum class ExportResult { @@ -12,6 +14,10 @@ class IcsExporter { var eventsFailed = 0 fun exportEvents(context: Context, path: String): ExportResult { + File(path, "events_${System.currentTimeMillis() / 1000}.ics").bufferedWriter().use { out -> + out.writeLn(BEGIN_CALENDAR) + out.writeLn(END_CALENDAR) + } return if (eventsExported == 0) { EXPORT_FAIL diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/IcsImporter.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/IcsImporter.kt index c8a5710b8..1f5179646 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/IcsImporter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/IcsImporter.kt @@ -78,7 +78,7 @@ class IcsImporter { } else if (line.startsWith(CATEGORIES)) { val categories = line.substring(CATEGORIES.length) tryAddCategories(categories, context) - } else if (line == END) { + } else if (line == END_EVENT) { if (curTitle.isEmpty() || curStart == -1 || curEnd == -1 || importIDs.contains(curImportId)) continue