mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-02-18 12:50:34 +01:00
properly parse .ics file events if lines are limited to 75-80 chars
This commit is contained in:
parent
6487fded8e
commit
6d7426b49e
@ -36,10 +36,19 @@ class IcsParser {
|
|||||||
try {
|
try {
|
||||||
val dbHelper = DBHelper.newInstance(context)
|
val dbHelper = DBHelper.newInstance(context)
|
||||||
val importIDs = dbHelper.getImportIds()
|
val importIDs = dbHelper.getImportIds()
|
||||||
|
var prevLine = ""
|
||||||
|
|
||||||
File(path).inputStream().bufferedReader().use {
|
File(path).inputStream().bufferedReader().use {
|
||||||
while (true) {
|
while (true) {
|
||||||
val line = it.readLine()?.trim() ?: break
|
var line = it.readLine() ?: break
|
||||||
|
if (line.trim().isEmpty())
|
||||||
|
continue
|
||||||
|
|
||||||
|
if (line.substring(0, 1) == " ") {
|
||||||
|
line = prevLine + line.trim()
|
||||||
|
eventsFailed--
|
||||||
|
}
|
||||||
|
|
||||||
if (line == BEGIN_EVENT) {
|
if (line == BEGIN_EVENT) {
|
||||||
resetValues()
|
resetValues()
|
||||||
} else if (line.startsWith(DTSTART)) {
|
} else if (line.startsWith(DTSTART)) {
|
||||||
@ -62,6 +71,7 @@ class IcsParser {
|
|||||||
eventsImported++
|
eventsImported++
|
||||||
resetValues()
|
resetValues()
|
||||||
}
|
}
|
||||||
|
prevLine = line
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@ -79,15 +89,18 @@ class IcsParser {
|
|||||||
|
|
||||||
private fun getTimestamp(fullString: String): Int {
|
private fun getTimestamp(fullString: String): Int {
|
||||||
try {
|
try {
|
||||||
if (fullString.startsWith(';')) {
|
return if (fullString.startsWith(';')) {
|
||||||
curFlags = curFlags or FLAG_ALL_DAY
|
curFlags = curFlags or FLAG_ALL_DAY
|
||||||
val value = fullString.substring(fullString.lastIndexOf(':') + 1)
|
val value = fullString.substring(fullString.lastIndexOf(':') + 1).replace("T", "").replace("Z", "")
|
||||||
val dateTimeFormat = DateTimeFormat.forPattern("yyyyMMdd")
|
if (value.length == 14) {
|
||||||
return dateTimeFormat.parseDateTime(value).withHourOfDay(1).seconds()
|
parseLongFormat(value)
|
||||||
|
} else {
|
||||||
|
val dateTimeFormat = DateTimeFormat.forPattern("yyyyMMdd")
|
||||||
|
dateTimeFormat.parseDateTime(value).withHourOfDay(1).seconds()
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
val digitString = fullString.substring(1).replace("T", "").replace("Z", "")
|
val digitString = fullString.substring(1).replace("T", "").replace("Z", "")
|
||||||
val dateTimeFormat = DateTimeFormat.forPattern("yyyyMMddHHmmss")
|
parseLongFormat(digitString)
|
||||||
return dateTimeFormat.parseDateTime(digitString).withZoneRetainFields(DateTimeZone.UTC).seconds()
|
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
eventsFailed++
|
eventsFailed++
|
||||||
@ -95,6 +108,11 @@ class IcsParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun parseLongFormat(digitString: String): Int {
|
||||||
|
val dateTimeFormat = DateTimeFormat.forPattern("yyyyMMddHHmmss")
|
||||||
|
return dateTimeFormat.parseDateTime(digitString).withZoneRetainFields(DateTimeZone.UTC).seconds()
|
||||||
|
}
|
||||||
|
|
||||||
private fun resetValues() {
|
private fun resetValues() {
|
||||||
curStart = -1
|
curStart = -1
|
||||||
curEnd = -1
|
curEnd = -1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user