Skip to content

Commit

Permalink
#140 delete with prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Mar 14, 2015
1 parent 8539fbd commit 39867ba
Showing 1 changed file with 5 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -411,47 +411,15 @@ public JSONArray findEvents(String title, String location, long startFrom, long
}

public boolean deleteEvent(Uri eventsUri, long startFrom, long startTo, String title, String location) {

// filter
String where = "";
List<String> selectionList = new ArrayList<String>();

if (title != null) {
where += Events.TITLE + "=?";
selectionList.add(title);
}
if (location != null) {
if (!"".equals(where)) {
where += " AND ";
}
where += Events.EVENT_LOCATION + "=?";
selectionList.add(location);
}
if (startFrom > 0) {
if (!"".equals(where)) {
where += " AND ";
}
where += Events.DTSTART + "=?";
selectionList.add(""+startFrom);
}
if (startTo > 0) {
if (!"".equals(where)) {
where += " AND ";
}
where += Events.DTEND + "=?";
selectionList.add(""+startTo);
}

String[] selectionArgs = new String[selectionList.size()];
ContentResolver resolver = this.cordova.getActivity().getApplicationContext().getContentResolver();
Event[] events = fetchEventInstances(title, location,startFrom, startTo);

int nrDeletedRecords = 0;
for (int i = 0; i < events.length; i++){
Uri eventUri = ContentUris.withAppendedId(eventsUri, Integer.parseInt(events[i].eventId));
nrDeletedRecords = resolver.delete(eventUri, null, null);
if (events != null) {
for (Event event : events) {
Uri eventUri = ContentUris.withAppendedId(eventsUri, Integer.parseInt(event.eventId));
nrDeletedRecords = resolver.delete(eventUri, null, null);
}
}
//int nrDeletedRecords = resolver.delete(eventsUri, where, selectionList.toArray(selectionArgs));
return nrDeletedRecords > 0;
}

Expand Down

0 comments on commit 39867ba

Please sign in to comment.