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
|
||||
try {
|
||||
cursor = contentResolver.query(uri, projection, selection, null, null)
|
||||
cursor.moveToFirst()
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
do {
|
||||
val id = cursor.getLongValue(CalendarContract.Calendars._ID)
|
||||
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)
|
||||
calendars.add(calendar)
|
||||
} while (cursor.moveToNext())
|
||||
}
|
||||
} finally {
|
||||
cursor?.close()
|
||||
}
|
||||
|
@ -282,7 +283,7 @@ fun Context.fetchCalDAVCalendarEvents(calendarID: Long, eventTypeId: Int) {
|
|||
var cursor: Cursor? = null
|
||||
try {
|
||||
cursor = contentResolver.query(uri, projection, selection, null, null)
|
||||
cursor.moveToFirst()
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
do {
|
||||
val id = cursor.getLongValue(CalendarContract.Events._ID)
|
||||
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,
|
||||
"", 0 or allDay, repeatRule.repeatLimit, repeatRule.repeatRule, eventTypeId, lastUpdated = System.currentTimeMillis())
|
||||
} while (cursor.moveToNext())
|
||||
}
|
||||
} finally {
|
||||
cursor?.close()
|
||||
}
|
||||
|
@ -314,7 +316,7 @@ fun Context.getCalDAVEventReminders(eventId: Long): List<Int> {
|
|||
var cursor: Cursor? = null
|
||||
try {
|
||||
cursor = contentResolver.query(uri, projection, selection, null, null)
|
||||
cursor.moveToFirst()
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
do {
|
||||
val minutes = cursor.getIntValue(CalendarContract.Reminders.MINUTES)
|
||||
val method = cursor.getIntValue(CalendarContract.Reminders.METHOD)
|
||||
|
@ -322,6 +324,7 @@ fun Context.getCalDAVEventReminders(eventId: Long): List<Int> {
|
|||
reminders.add(minutes)
|
||||
}
|
||||
} while (cursor.moveToNext())
|
||||
}
|
||||
} finally {
|
||||
cursor?.close()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue