GCal - wrap cursor accessors in try/finally blocks

pull/14/head
Tim Su 13 years ago
parent 9eb47a268b
commit 5cb3db64a7

@ -102,11 +102,15 @@ public class GCalControlSet extends PopupControlSet {
// try to load calendar
ContentResolver cr = activity.getContentResolver();
Cursor cursor = cr.query(calendarUri, new String[] { "dtstart" }, null, null, null); //$NON-NLS-1$
boolean deleted = cursor.getCount() == 0;
cursor.close();
if(deleted) {
calendarUri = null;
return;
try {
boolean deleted = cursor.getCount() == 0;
if(deleted) {
calendarUri = null;
return;
}
} finally {
cursor.close();
}
hasEvent = true;
@ -182,12 +186,11 @@ public class GCalControlSet extends PopupControlSet {
return;
ContentResolver cr = activity.getContentResolver();
Intent intent = new Intent(Intent.ACTION_EDIT, calendarUri);
Cursor cursor = cr.query(calendarUri, new String[] { "dtstart", "dtend" },
null, null, null);
Intent intent = new Intent(Intent.ACTION_EDIT, calendarUri);
try {
if(cursor == null || cursor.getCount() == 0) {
if(cursor.getCount() == 0) {
// event no longer exists, recreate it
calendarUri = null;
writeToModel(myTask);
@ -196,12 +199,12 @@ public class GCalControlSet extends PopupControlSet {
cursor.moveToFirst();
intent.putExtra("beginTime", cursor.getLong(0));
intent.putExtra("endTime", cursor.getLong(1));
} catch (Exception e) {
Log.e("gcal-error", "Error opening calendar", e); //$NON-NLS-1$ //$NON-NLS-2$
Toast.makeText(activity, R.string.gcal_TEA_error, Toast.LENGTH_LONG);
} finally {
if(cursor != null)
cursor.close();
cursor.close();
}
activity.startActivity(intent);

@ -63,7 +63,6 @@ public class GCalHelper {
}
try{
// FIXME test this with empty quickadd and full quickadd and taskedit-page
Uri uri = Calendars.getCalendarContentUri(Calendars.CALENDAR_CONTENT_EVENTS);
values.put("title", task.getValue(Task.TITLE));
values.put("description", task.getValue(Task.NOTES));
@ -89,7 +88,8 @@ public class GCalHelper {
return eventUri;
} catch (Exception e) {
Log.e("astrid-gcal", "error-creating-calendar-event", e); //$NON-NLS-1$ //$NON-NLS-2$
// TODO FIX ME
// Log.e("astrid-gcal", "error-creating-calendar-event", e); //$NON-NLS-1$ //$NON-NLS-2$
}
return null;
@ -114,12 +114,15 @@ public class GCalHelper {
// try to load calendar
ContentResolver cr = ContextManager.getContext().getContentResolver();
Cursor cursor = cr.query(calendarUri, new String[] { "dtstart" }, null, null, null); //$NON-NLS-1$
boolean alreadydeleted = cursor.getCount() == 0;
cursor.close();
if (!alreadydeleted) {
cr.delete(calendarUri, null, null);
eventDeleted = true;
try {
boolean alreadydeleted = cursor.getCount() == 0;
if (!alreadydeleted) {
cr.delete(calendarUri, null, null);
eventDeleted = true;
}
} finally {
cursor.close();
}
task.setValue(Task.CALENDAR_URI,"");

Loading…
Cancel
Save