mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-02-02 03:36:50 +01:00
properly handle importing events with multiple reminders
This commit is contained in:
parent
cf1b13d533
commit
dbaf0d79c7
@ -38,7 +38,7 @@ class ImportEventsDialog(val activity: Activity, val path: String, val callback:
|
|||||||
activity.setupDialogStuff(view, this, R.string.import_events)
|
activity.setupDialogStuff(view, this, R.string.import_events)
|
||||||
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener({
|
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener({
|
||||||
Thread({
|
Thread({
|
||||||
val result = IcsImporter().parseIcs(context, path, currEventTypeId)
|
val result = IcsImporter().importEvents(context, path, currEventTypeId)
|
||||||
handleParseResult(result)
|
handleParseResult(result)
|
||||||
dismiss()
|
dismiss()
|
||||||
}).start()
|
}).start()
|
||||||
|
@ -22,17 +22,17 @@ class IcsImporter {
|
|||||||
var curDescription = ""
|
var curDescription = ""
|
||||||
var curImportId = ""
|
var curImportId = ""
|
||||||
var curFlags = 0
|
var curFlags = 0
|
||||||
var curReminderMinutes = -1
|
var curReminderMinutes = ArrayList<Int>()
|
||||||
var curRepeatInterval = 0
|
var curRepeatInterval = 0
|
||||||
var curRepeatLimit = 0
|
var curRepeatLimit = 0
|
||||||
var curEventType = DBHelper.REGULAR_EVENT_TYPE_ID
|
var curEventType = DBHelper.REGULAR_EVENT_TYPE_ID
|
||||||
var curShouldHaveNotification = false
|
|
||||||
var isNotificationDescription = false
|
var isNotificationDescription = false
|
||||||
|
var lastReminderAction = ""
|
||||||
|
|
||||||
var eventsImported = 0
|
var eventsImported = 0
|
||||||
var eventsFailed = 0
|
var eventsFailed = 0
|
||||||
|
|
||||||
fun parseIcs(context: Context, path: String, defaultEventType: Int): ImportResult {
|
fun importEvents(context: Context, path: String, defaultEventType: Int): ImportResult {
|
||||||
try {
|
try {
|
||||||
val importIDs = context.dbHelper.getImportIds()
|
val importIDs = context.dbHelper.getImportIds()
|
||||||
var prevLine = ""
|
var prevLine = ""
|
||||||
@ -69,12 +69,10 @@ class IcsImporter {
|
|||||||
curRepeatInterval = parseRepeatInterval(line.substring(RRULE.length))
|
curRepeatInterval = parseRepeatInterval(line.substring(RRULE.length))
|
||||||
} else if (line.startsWith(ACTION)) {
|
} else if (line.startsWith(ACTION)) {
|
||||||
isNotificationDescription = true
|
isNotificationDescription = true
|
||||||
if (line.substring(ACTION.length) == DISPLAY)
|
lastReminderAction = line.substring(ACTION.length)
|
||||||
curShouldHaveNotification = true
|
|
||||||
} else if (line.startsWith(TRIGGER)) {
|
} else if (line.startsWith(TRIGGER)) {
|
||||||
if (curReminderMinutes == -1 && curShouldHaveNotification) {
|
if (lastReminderAction == DISPLAY)
|
||||||
curReminderMinutes = decodeTime(line.substring(TRIGGER.length)) / 60
|
curReminderMinutes.add(decodeTime(line.substring(TRIGGER.length)) / 60)
|
||||||
}
|
|
||||||
} 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)
|
||||||
@ -83,7 +81,8 @@ class IcsImporter {
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
importIDs.add(curImportId)
|
importIDs.add(curImportId)
|
||||||
val event = Event(0, curStart, curEnd, curTitle, curDescription, curReminderMinutes, -1, -1, curRepeatInterval,
|
val event = Event(0, curStart, curEnd, curTitle, curDescription, curReminderMinutes.getOrElse(0, { -1 }),
|
||||||
|
curReminderMinutes.getOrElse(1, { -1 }), curReminderMinutes.getOrElse(2, { -1 }), curRepeatInterval,
|
||||||
curImportId, curFlags, curRepeatLimit, curEventType)
|
curImportId, curFlags, curRepeatLimit, curEventType)
|
||||||
context.dbHelper.insert(event) { }
|
context.dbHelper.insert(event) { }
|
||||||
eventsImported++
|
eventsImported++
|
||||||
@ -216,11 +215,11 @@ class IcsImporter {
|
|||||||
curDescription = ""
|
curDescription = ""
|
||||||
curImportId = ""
|
curImportId = ""
|
||||||
curFlags = 0
|
curFlags = 0
|
||||||
curReminderMinutes = -1
|
curReminderMinutes = ArrayList<Int>()
|
||||||
curRepeatInterval = 0
|
curRepeatInterval = 0
|
||||||
curRepeatLimit = 0
|
curRepeatLimit = 0
|
||||||
curEventType = DBHelper.REGULAR_EVENT_TYPE_ID
|
curEventType = DBHelper.REGULAR_EVENT_TYPE_ID
|
||||||
curShouldHaveNotification = false
|
|
||||||
isNotificationDescription = false
|
isNotificationDescription = false
|
||||||
|
lastReminderAction = ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user