mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-02-18 20:50:40 +01:00
write some initial content to exported ics file
This commit is contained in:
parent
6e3e47fe94
commit
1a2a5f5a75
@ -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
|
val FLAG_ALL_DAY = 1
|
||||||
|
|
||||||
// constants related to ICS file exporting / importing
|
// constants related to ICS file exporting / importing
|
||||||
|
val BEGIN_CALENDAR = "BEGIN:VCALENDAR"
|
||||||
|
val END_CALENDAR = "END:VCALENDAR"
|
||||||
val BEGIN_EVENT = "BEGIN:VEVENT"
|
val BEGIN_EVENT = "BEGIN:VEVENT"
|
||||||
val END = "END:VEVENT"
|
val END_EVENT = "END:VEVENT"
|
||||||
val DTSTART = "DTSTART"
|
val DTSTART = "DTSTART"
|
||||||
val DTEND = "DTEND"
|
val DTEND = "DTEND"
|
||||||
val DURATION = "DURATION:"
|
val DURATION = "DURATION:"
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package com.simplemobiletools.calendar.helpers
|
package com.simplemobiletools.calendar.helpers
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import com.simplemobiletools.calendar.extensions.writeLn
|
||||||
import com.simplemobiletools.calendar.helpers.IcsExporter.ExportResult.*
|
import com.simplemobiletools.calendar.helpers.IcsExporter.ExportResult.*
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
class IcsExporter {
|
class IcsExporter {
|
||||||
enum class ExportResult {
|
enum class ExportResult {
|
||||||
@ -12,6 +14,10 @@ class IcsExporter {
|
|||||||
var eventsFailed = 0
|
var eventsFailed = 0
|
||||||
|
|
||||||
fun exportEvents(context: Context, path: String): ExportResult {
|
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) {
|
return if (eventsExported == 0) {
|
||||||
EXPORT_FAIL
|
EXPORT_FAIL
|
||||||
|
@ -78,7 +78,7 @@ class IcsImporter {
|
|||||||
} else if (line.startsWith(CATEGORIES)) {
|
} else if (line.startsWith(CATEGORIES)) {
|
||||||
val categories = line.substring(CATEGORIES.length)
|
val categories = line.substring(CATEGORIES.length)
|
||||||
tryAddCategories(categories, context)
|
tryAddCategories(categories, context)
|
||||||
} else if (line == END) {
|
} else if (line == END_EVENT) {
|
||||||
if (curTitle.isEmpty() || curStart == -1 || curEnd == -1 || importIDs.contains(curImportId))
|
if (curTitle.isEmpty() || curStart == -1 || curEnd == -1 || importIDs.contains(curImportId))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user