Extracted deleteTaskEvent to its own Helper-class to keep UI-classes clean.

pull/14/head
Arne Jans 13 years ago
parent 84625149b1
commit ccfbd8f79b

@ -21,7 +21,7 @@ import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.andlib.utility.TodorooPreferenceActivity;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.gcal.GCalControlSet;
import com.todoroo.astrid.gcal.GCalHelper;
import com.todoroo.astrid.service.MetadataService;
import com.todoroo.astrid.service.TaskService;
@ -85,7 +85,7 @@ public class OldTaskPreferences extends TodorooPreferenceActivity {
for(int i = 0; i < length; i++) {
cursor.moveToNext();
task.readFromCursor(cursor);
GCalControlSet.deleteTaskEvent(task);
GCalHelper.deleteTaskEvent(task);
}
} finally {
cursor.close();
@ -124,7 +124,7 @@ public class OldTaskPreferences extends TodorooPreferenceActivity {
for(int i = 0; i < length; i++) {
cursor.moveToNext();
task.readFromCursor(cursor);
GCalControlSet.deleteTaskEvent(task);
GCalHelper.deleteTaskEvent(task);
}
} finally {
cursor.close();

@ -22,13 +22,11 @@ import android.widget.Toast;
import com.timsu.astrid.R;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.service.ExceptionService;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.activity.TaskEditActivity.TaskEditControlSet;
import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.gcal.Calendars.CalendarResult;
import com.todoroo.astrid.service.StatisticsService;
@ -118,34 +116,6 @@ public class GCalControlSet implements TaskEditControlSet {
});
}
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);
uri = task.getValue(Task.CALENDAR_URI);
}
if(!TextUtils.isEmpty(uri)) {
try {
calendarUri = Uri.parse(uri);
// try to load calendar
ContentResolver cr = ContextManager.getContext().getContentResolver();
Cursor cursor = cr.query(calendarUri, new String[] { "dtstart" }, null, null, null); //$NON-NLS-1$
boolean deleted = cursor.getCount() == 0;
cursor.close();
if (!deleted) {
cr.delete(calendarUri, null, null);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
@Override
public void readFromTask(Task task) {
this.myTask = task;

@ -0,0 +1,40 @@
package com.todoroo.astrid.gcal;
import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;
import android.text.TextUtils;
import com.todoroo.andlib.service.ContextManager;
import com.todoroo.astrid.core.PluginServices;
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);
uri = task.getValue(Task.CALENDAR_URI);
}
if(!TextUtils.isEmpty(uri)) {
try {
calendarUri = Uri.parse(uri);
// try to load calendar
ContentResolver cr = ContextManager.getContext().getContentResolver();
Cursor cursor = cr.query(calendarUri, new String[] { "dtstart" }, null, null, null); //$NON-NLS-1$
boolean deleted = cursor.getCount() == 0;
cursor.close();
if (!deleted) {
cr.delete(calendarUri, null, null);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}

@ -24,7 +24,7 @@ import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.gcal.GCalControlSet;
import com.todoroo.astrid.gcal.GCalHelper;
import com.todoroo.astrid.gtasks.GtasksMetadata;
import com.todoroo.astrid.opencrx.OpencrxCoreUtils;
import com.todoroo.astrid.producteev.ProducteevUtilities;
@ -151,14 +151,14 @@ public class TaskService {
if(!item.isSaved())
return;
else if(item.containsValue(Task.TITLE) && item.getValue(Task.TITLE).length() == 0) {
GCalControlSet.deleteTaskEvent(item);
GCalHelper.deleteTaskEvent(item);
taskDao.delete(item.getId());
item.setId(Task.NO_ID);
} else {
long id = item.getId();
item.clear();
item.setId(id);
GCalControlSet.deleteTaskEvent(item);
GCalHelper.deleteTaskEvent(item);
item.setValue(Task.DELETION_DATE, DateUtilities.now());
taskDao.save(item);
}

Loading…
Cancel
Save