Refactored gcalhelper to avoid double read for tasks with empty gcal property

pull/14/head
Tim Su 13 years ago
parent 956c39476c
commit 7fb4ef4b11

@ -4,6 +4,7 @@ import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;
import com.todoroo.andlib.service.ContextManager;
import com.todoroo.astrid.core.PluginServices;
@ -11,17 +12,19 @@ import com.todoroo.astrid.data.Task;
public class GCalHelper {
public static void deleteTaskEvent(Task task) {
String uri = task.getValue(Task.CALENDAR_URI);
Uri calendarUri = null;
if (TextUtils.isEmpty(uri)) {
task = PluginServices.getTaskService().fetchById(task.getId(), Task.ID, Task.CALENDAR_URI);
String uri;
if(task.containsNonNullValue(Task.CALENDAR_URI))
uri = task.getValue(Task.CALENDAR_URI);
else {
task = PluginServices.getTaskService().fetchById(task.getId(), Task.CALENDAR_URI);
if(task == null)
return;
uri = task.getValue(Task.CALENDAR_URI);
}
if(!TextUtils.isEmpty(uri)) {
try {
calendarUri = Uri.parse(uri);
Uri calendarUri = Uri.parse(uri);
// try to load calendar
ContentResolver cr = ContextManager.getContext().getContentResolver();
@ -33,7 +36,7 @@ public class GCalHelper {
cr.delete(calendarUri, null, null);
}
} catch (Exception e) {
e.printStackTrace();
Log.e("astrid-gcal", "error-deleting-calendar-event", e); //$NON-NLS-1$ //$NON-NLS-2$
}
}
}

Loading…
Cancel
Save