mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-02-20 05:30:40 +01:00
avoid importing the same event twice from ics file
This commit is contained in:
parent
f56dfce1fe
commit
737f457dbc
@ -118,6 +118,7 @@ class DBHelper(context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_V
|
|||||||
put(COL_TITLE, event.title)
|
put(COL_TITLE, event.title)
|
||||||
put(COL_DESCRIPTION, event.description)
|
put(COL_DESCRIPTION, event.description)
|
||||||
put(COL_REMINDER_MINUTES, event.reminderMinutes)
|
put(COL_REMINDER_MINUTES, event.reminderMinutes)
|
||||||
|
put(COL_IMPORT_ID, event.importId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,6 +153,25 @@ class DBHelper(context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_V
|
|||||||
mEventsListener?.eventsDeleted(ids.size)
|
mEventsListener?.eventsDeleted(ids.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getImportIds(): ArrayList<String> {
|
||||||
|
val ids = ArrayList<String>()
|
||||||
|
val columns = arrayOf(COL_IMPORT_ID)
|
||||||
|
val selection = "$COL_IMPORT_ID IS NOT NULL"
|
||||||
|
var cursor: Cursor? = null
|
||||||
|
try {
|
||||||
|
cursor = mDb.query(MAIN_TABLE_NAME, columns, selection, null, null, null, null)
|
||||||
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
|
do {
|
||||||
|
val id = cursor.getStringValue(COL_IMPORT_ID)
|
||||||
|
ids.add(id)
|
||||||
|
} while (cursor.moveToNext())
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
cursor?.close()
|
||||||
|
}
|
||||||
|
return ids
|
||||||
|
}
|
||||||
|
|
||||||
fun getEvent(id: Int): Event? {
|
fun getEvent(id: Int): Event? {
|
||||||
val selection = "$MAIN_TABLE_NAME.$COL_ID = ?"
|
val selection = "$MAIN_TABLE_NAME.$COL_ID = ?"
|
||||||
val selectionArgs = arrayOf(id.toString())
|
val selectionArgs = arrayOf(id.toString())
|
||||||
|
@ -21,11 +21,13 @@ class IcsParser {
|
|||||||
private val DTEND = "DTEND:"
|
private val DTEND = "DTEND:"
|
||||||
private val SUMMARY = "SUMMARY:"
|
private val SUMMARY = "SUMMARY:"
|
||||||
private val DESCRIPTION = "DESCRIPTION:"
|
private val DESCRIPTION = "DESCRIPTION:"
|
||||||
|
private val UID = "UID:"
|
||||||
|
|
||||||
var curStart = -1
|
var curStart = -1
|
||||||
var curEnd = -1
|
var curEnd = -1
|
||||||
var curTitle = ""
|
var curTitle = ""
|
||||||
var curDescription = ""
|
var curDescription = ""
|
||||||
|
var curImportId = ""
|
||||||
|
|
||||||
var eventsImported = 0
|
var eventsImported = 0
|
||||||
var eventsFailed = 0
|
var eventsFailed = 0
|
||||||
@ -33,6 +35,7 @@ class IcsParser {
|
|||||||
fun parseIcs(context: Context, reminderMinutes: Int, path: String): ImportResult {
|
fun parseIcs(context: Context, reminderMinutes: Int, path: String): ImportResult {
|
||||||
try {
|
try {
|
||||||
val dbHelper = DBHelper(context)
|
val dbHelper = DBHelper(context)
|
||||||
|
val importIDs = dbHelper.getImportIds()
|
||||||
|
|
||||||
File(path).inputStream().bufferedReader().use {
|
File(path).inputStream().bufferedReader().use {
|
||||||
while (true) {
|
while (true) {
|
||||||
@ -47,11 +50,13 @@ class IcsParser {
|
|||||||
curTitle = line.substring(SUMMARY.length)
|
curTitle = line.substring(SUMMARY.length)
|
||||||
} else if (line.startsWith(DESCRIPTION)) {
|
} else if (line.startsWith(DESCRIPTION)) {
|
||||||
curDescription = line.substring(DESCRIPTION.length)
|
curDescription = line.substring(DESCRIPTION.length)
|
||||||
|
} else if (line.startsWith(UID)) {
|
||||||
|
curImportId = line.substring(UID.length)
|
||||||
} else if (line == END || line == BEGIN_ALARM) {
|
} else if (line == END || line == BEGIN_ALARM) {
|
||||||
if (curTitle.isEmpty() || curStart == -1 || curEnd == -1)
|
if (curTitle.isEmpty() || curStart == -1 || curEnd == -1 || importIDs.contains(curImportId))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
val event = Event(0, curStart, curEnd, curTitle, curDescription, reminderMinutes)
|
val event = Event(0, curStart, curEnd, curTitle, curDescription, reminderMinutes, importId = curImportId)
|
||||||
dbHelper.insert(event) {
|
dbHelper.insert(event) {
|
||||||
context.scheduleNotification(event)
|
context.scheduleNotification(event)
|
||||||
}
|
}
|
||||||
@ -89,5 +94,6 @@ class IcsParser {
|
|||||||
curEnd = -1
|
curEnd = -1
|
||||||
curTitle = ""
|
curTitle = ""
|
||||||
curDescription = ""
|
curDescription = ""
|
||||||
|
curImportId = ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ import org.joda.time.DateTime
|
|||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
|
|
||||||
data class Event(var id: Int = 0, var startTS: Int = 0, var endTS: Int = 0, var title: String = "", var description: String = "",
|
data class Event(var id: Int = 0, var startTS: Int = 0, var endTS: Int = 0, var title: String = "", var description: String = "",
|
||||||
var reminderMinutes: Int = 0, var repeatInterval: Int = 0) : Serializable {
|
var reminderMinutes: Int = 0, var repeatInterval: Int = 0, var importId: String = "") : Serializable {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val serialVersionUID = -32456795132344616L
|
private val serialVersionUID = -32456795132344616L
|
||||||
|
Loading…
x
Reference in New Issue
Block a user