Add CalendarEventProvider.hasEvent(Uri)

pull/413/head
Alex Baker 9 years ago
parent a849af9813
commit 3cc6e7a527

@ -20,7 +20,6 @@ import com.todoroo.astrid.service.TaskService;
import org.tasks.R;
import org.tasks.calendars.AndroidCalendarEvent;
import org.tasks.calendars.CalendarEventProvider;
import org.tasks.calendars.CalendarProvider;
import org.tasks.injection.ForApplication;
import org.tasks.preferences.PermissionChecker;
import org.tasks.preferences.Preferences;
@ -38,18 +37,15 @@ public class GCalHelper {
private final TaskService taskService;
private final Preferences preferences;
private final CalendarProvider calendarProvider;
private final PermissionChecker permissionChecker;
private final CalendarEventProvider calendarEventProvider;
private final ContentResolver cr;
@Inject
public GCalHelper(@ForApplication Context context, TaskService taskService, Preferences preferences,
CalendarProvider calendarProvider, PermissionChecker permissionChecker,
CalendarEventProvider calendarEventProvider) {
PermissionChecker permissionChecker, CalendarEventProvider calendarEventProvider) {
this.taskService = taskService;
this.preferences = preferences;
this.calendarProvider = calendarProvider;
this.permissionChecker = permissionChecker;
this.calendarEventProvider = calendarEventProvider;
cr = context.getContentResolver();
@ -165,7 +161,7 @@ public class GCalHelper {
if(!TextUtils.isEmpty(uri)) {
try {
Uri calendarUri = Uri.parse(uri);
if (calendarProvider.getCalendar(calendarUri) != null) {
if (calendarEventProvider.hasEvent(calendarUri)) {
cr.delete(calendarUri, null, null);
eventDeleted = true;
}

@ -55,6 +55,10 @@ public class CalendarEventProvider {
return events.isEmpty() ? null : events.get(0);
}
public boolean hasEvent(Uri eventUri) {
return getEvent(eventUri) != null;
}
public List<AndroidCalendarEvent> getEventsBetween(long start, long end) {
return getCalendarEvents(
CalendarContract.Events.CONTENT_URI,

@ -44,16 +44,7 @@ public class CalendarProvider {
@Nullable
public AndroidCalendar getCalendar(String id) {
return getCalendar(CalendarContract.Calendars.CONTENT_URI, CAN_MODIFY + " AND Calendars._id=" + id);
}
@Nullable
public AndroidCalendar getCalendar(Uri uri) {
return getCalendar(uri, CAN_MODIFY);
}
private AndroidCalendar getCalendar(Uri uri, String selection) {
List<AndroidCalendar> calendars = getCalendars(uri, selection);
List<AndroidCalendar> calendars = getCalendars(CalendarContract.Calendars.CONTENT_URI, CAN_MODIFY + " AND Calendars._id=" + id);
return calendars.isEmpty() ? null : calendars.get(0);
}

Loading…
Cancel
Save