properly handle all really long lines at importing, not just at the description

This commit is contained in:
tibbi 2021-02-13 20:19:07 +01:00
parent 86293722b9
commit 7495bd4b88
2 changed files with 8 additions and 18 deletions

View file

@ -64,7 +64,7 @@ android {
}
dependencies {
implementation 'com.simplemobiletools:commons:5.33.26'
implementation 'com.simplemobiletools:commons:5.33.28'
implementation 'joda-time:joda-time:2.10.1'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'

View file

@ -38,7 +38,6 @@ class IcsImporter(val activity: SimpleActivity) {
private var curCategoryColor = -2
private var isNotificationDescription = false
private var isProperReminderAction = false
private var isDescription = false
private var isSequence = false
private var isParsingEvent = false
private var curReminderTriggerMinutes = REMINDER_OFF
@ -54,7 +53,7 @@ class IcsImporter(val activity: SimpleActivity) {
val eventTypes = eventsHelper.getEventTypesSync()
val existingEvents = activity.eventsDB.getEventsWithImportIds().toMutableList() as ArrayList<Event>
val eventsToInsert = ArrayList<Event>()
var prevLine = ""
var line = ""
val inputStream = if (path.contains("/")) {
File(path).inputStream()
@ -64,22 +63,14 @@ class IcsImporter(val activity: SimpleActivity) {
inputStream.bufferedReader().use {
while (true) {
var line = it.readLine() ?: break
if (line.trim().isEmpty()) {
val curLine = it.readLine() ?: break
if (curLine.trim().isEmpty()) {
continue
}
if (line.substring(0, 1) == " ") {
line = prevLine + line.trim()
eventsFailed--
}
if (isDescription) {
if (line.startsWith('\t')) {
curDescription += line.trimStart('\t').replace("\\n", "\n")
} else {
isDescription = false
}
if (curLine.startsWith("\t") || curLine.substring(0, 1) == " ") {
line += curLine.removePrefix("\t").removePrefix(" ")
continue
}
if (line == BEGIN_EVENT) {
@ -107,7 +98,6 @@ class IcsImporter(val activity: SimpleActivity) {
if (curDescription.trim().isEmpty()) {
curDescription = ""
}
isDescription = true
} else if (line.startsWith(UID)) {
curImportId = line.substring(UID.length).trim()
} else if (line.startsWith(RRULE)) {
@ -226,7 +216,7 @@ class IcsImporter(val activity: SimpleActivity) {
eventsImported++
resetValues()
}
prevLine = line
line = curLine
}
}