add some checks if cursors arent empty
This commit is contained in:
parent
e65b97e647
commit
ad9ad142ed
|
@ -250,7 +250,7 @@ fun Context.getCalDAVCalendars(ids: String = ""): List<CalDAVCalendar> {
|
||||||
var cursor: Cursor? = null
|
var cursor: Cursor? = null
|
||||||
try {
|
try {
|
||||||
cursor = contentResolver.query(uri, projection, selection, null, null)
|
cursor = contentResolver.query(uri, projection, selection, null, null)
|
||||||
cursor.moveToFirst()
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
do {
|
do {
|
||||||
val id = cursor.getLongValue(CalendarContract.Calendars._ID)
|
val id = cursor.getLongValue(CalendarContract.Calendars._ID)
|
||||||
val displayName = cursor.getStringValue(CalendarContract.Calendars.CALENDAR_DISPLAY_NAME)
|
val displayName = cursor.getStringValue(CalendarContract.Calendars.CALENDAR_DISPLAY_NAME)
|
||||||
|
@ -260,6 +260,7 @@ fun Context.getCalDAVCalendars(ids: String = ""): List<CalDAVCalendar> {
|
||||||
val calendar = CalDAVCalendar(id, displayName, accountName, ownerName, color)
|
val calendar = CalDAVCalendar(id, displayName, accountName, ownerName, color)
|
||||||
calendars.add(calendar)
|
calendars.add(calendar)
|
||||||
} while (cursor.moveToNext())
|
} while (cursor.moveToNext())
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
cursor?.close()
|
cursor?.close()
|
||||||
}
|
}
|
||||||
|
@ -282,7 +283,7 @@ fun Context.fetchCalDAVCalendarEvents(calendarID: Long, eventTypeId: Int) {
|
||||||
var cursor: Cursor? = null
|
var cursor: Cursor? = null
|
||||||
try {
|
try {
|
||||||
cursor = contentResolver.query(uri, projection, selection, null, null)
|
cursor = contentResolver.query(uri, projection, selection, null, null)
|
||||||
cursor.moveToFirst()
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
do {
|
do {
|
||||||
val id = cursor.getLongValue(CalendarContract.Events._ID)
|
val id = cursor.getLongValue(CalendarContract.Events._ID)
|
||||||
val title = cursor.getStringValue(CalendarContract.Events.TITLE)
|
val title = cursor.getStringValue(CalendarContract.Events.TITLE)
|
||||||
|
@ -299,6 +300,7 @@ fun Context.fetchCalDAVCalendarEvents(calendarID: Long, eventTypeId: Int) {
|
||||||
reminders.getOrElse(1, { -1 }), reminders.getOrElse(2, { -1 }), repeatRule.repeatInterval,
|
reminders.getOrElse(1, { -1 }), reminders.getOrElse(2, { -1 }), repeatRule.repeatInterval,
|
||||||
"", 0 or allDay, repeatRule.repeatLimit, repeatRule.repeatRule, eventTypeId, lastUpdated = System.currentTimeMillis())
|
"", 0 or allDay, repeatRule.repeatLimit, repeatRule.repeatRule, eventTypeId, lastUpdated = System.currentTimeMillis())
|
||||||
} while (cursor.moveToNext())
|
} while (cursor.moveToNext())
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
cursor?.close()
|
cursor?.close()
|
||||||
}
|
}
|
||||||
|
@ -314,7 +316,7 @@ fun Context.getCalDAVEventReminders(eventId: Long): List<Int> {
|
||||||
var cursor: Cursor? = null
|
var cursor: Cursor? = null
|
||||||
try {
|
try {
|
||||||
cursor = contentResolver.query(uri, projection, selection, null, null)
|
cursor = contentResolver.query(uri, projection, selection, null, null)
|
||||||
cursor.moveToFirst()
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
do {
|
do {
|
||||||
val minutes = cursor.getIntValue(CalendarContract.Reminders.MINUTES)
|
val minutes = cursor.getIntValue(CalendarContract.Reminders.MINUTES)
|
||||||
val method = cursor.getIntValue(CalendarContract.Reminders.METHOD)
|
val method = cursor.getIntValue(CalendarContract.Reminders.METHOD)
|
||||||
|
@ -322,6 +324,7 @@ fun Context.getCalDAVEventReminders(eventId: Long): List<Int> {
|
||||||
reminders.add(minutes)
|
reminders.add(minutes)
|
||||||
}
|
}
|
||||||
} while (cursor.moveToNext())
|
} while (cursor.moveToNext())
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
cursor?.close()
|
cursor?.close()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue