write some initial content to exported ics file
This commit is contained in:
parent
6e3e47fe94
commit
1a2a5f5a75
4 changed files with 18 additions and 2 deletions
|
@ -0,0 +1,8 @@
|
|||
package com.simplemobiletools.calendar.extensions
|
||||
|
||||
import java.io.BufferedWriter
|
||||
|
||||
fun BufferedWriter.writeLn(line: String) {
|
||||
write(line)
|
||||
newLine()
|
||||
}
|
|
@ -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:"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue