/** * Creates the event. * * @param event the event * @param category_ids the category_ids * @return the long */ public long createEvent(Event event, long[] category_ids) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(KEY_EVENT_TITLE, event.getTitle()); values.put(KEY_EVENT_STARTDATE, event.getStartDate()); values.put(KEY_EVENT_ENDDATE, event.getEndDate()); values.put(KEY_EVENT_STARTTIME, event.getStartTime()); values.put(KEY_EVENT_ENDTIME, event.getEndTime()); values.put(KEY_EVENT_DESCRIPTION, event.getDescription()); values.put(KEY_EVENT_REPEAT, event.getRepeat()); // insert row long event_id = db.insert(TABLE_EVENT, null, values); // assigning categories to events for (long category_id : category_ids) { createEventCategory(event_id, category_id); } // for logging // Log.e("createEvent", event.toString()); // db.close(); return event_id; }
/** * Check conflictin update events. * * @param newEvent the new event * @return true, if successful * @throws ParseException the parse exception */ @SuppressLint("LongLogTag") public boolean checkConflictinUpdateEvents(Event newEvent) throws ParseException { SimpleDateFormat timeFormat = new SimpleDateFormat("hh:mm"); String sTime = newEvent.getStartTime(); String sDate = newEvent.getStartDate(); String eTime = newEvent.getEndTime(); String eDate = newEvent.getEndDate(); Date parsedStartTime = timeFormat.parse(sTime); Timestamp newStartTime = new Timestamp(parsedStartTime.getTime()); Date parsedEndTime = timeFormat.parse(eTime); Timestamp newEndTime = new Timestamp(parsedEndTime.getTime()); if (sDate.equalsIgnoreCase(eDate)) { if (newStartTime.after(newEndTime)) { Log.e("Illogiacl Update", "StartTime is greater then EndTime"); return false; } } List<Event> allEvents = getEvent(sDate, eDate); for (Event prevEvent : allEvents) { Log.d( "Event: " + prevEvent.getTitle(), "" + prevEvent.getId() + " " + prevEvent.getDescription()); Date parsedPreviousStartTime = timeFormat.parse(prevEvent.getStartTime()); Timestamp previousStartTime = new Timestamp(parsedPreviousStartTime.getTime()); Date parsedPreviousEndTime = timeFormat.parse(prevEvent.getEndTime()); Timestamp previousEndTime = new Timestamp(parsedPreviousEndTime.getTime()); if (newStartTime.after(previousStartTime) && newStartTime.before(previousEndTime) || newEndTime.after(previousStartTime) && newEndTime.before(previousEndTime) || previousStartTime.after(newStartTime) && previousStartTime.before(newEndTime) || previousEndTime.after(newStartTime) && previousEndTime.before(newEndTime)) { if (newEvent.getId() != prevEvent.getId()) { Log.e("Conflict with existent event", "Can't update this event"); return false; } } } return true; }
public void updateEventWithId(int id, Event e) { ContentValues cv = new ContentValues(); cv.put(colName, e.getName()); cv.put(colStartTime, e.getStartTime()); cv.put(colEndTime, e.getEndTime()); cv.put(colLatitude, e.getLatitude()); cv.put(colLongitude, e.getLongitude()); cv.put(transport, e.getTransport()); cv.put(colInfo, e.getInfo()); cv.put(colPassed, e.getPassed()); db.update(eventTable, cv, colId + "=" + Integer.toString(id), null); }
public long AddEvent(Event e) { ContentValues cv = new ContentValues(); cv.put(colName, e.getName()); cv.put(colStartTime, e.getStartTime()); cv.put(colEndTime, e.getEndTime()); cv.put(colLatitude, e.getLatitude()); cv.put(colLongitude, e.getLongitude()); cv.put(transport, e.getTransport()); cv.put(colInfo, e.getInfo()); cv.put(colPassed, e.getPassed()); return db.insert(eventTable, colName, cv); }
/** * Update event. * * @param event the event * @return the int */ public int updateEvent(Event event) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(KEY_EVENT_TITLE, event.getTitle()); values.put(KEY_EVENT_STARTDATE, event.getStartDate()); values.put(KEY_EVENT_ENDDATE, event.getEndDate()); values.put(KEY_EVENT_STARTTIME, event.getStartTime()); values.put(KEY_EVENT_ENDTIME, event.getEndTime()); values.put(KEY_EVENT_DESCRIPTION, event.getDescription()); values.put(KEY_EVENT_REPEAT, event.getRepeat()); // updating row return db.update( TABLE_EVENT, values, KEY_ID + " = ?", new String[] {String.valueOf(event.getId())}); }
public void updateEvent(Event e) { ContentValues cv = new ContentValues(); cv.put(colName, e.getName()); cv.put(colStartTime, e.getStartTime()); cv.put(colEndTime, e.getEndTime()); cv.put(colLatitude, e.getLatitude()); cv.put(colLongitude, e.getLongitude()); cv.put(transport, e.getTransport()); cv.put(colInfo, e.getInfo()); if (e.getPassed()) { cv.put(colPassed, 1); } else { cv.put(colPassed, 0); } db.update(eventTable, cv, colId + "=" + Integer.toString(e.getId()), null); }
@MediumTest public void testGetEvent_withLocationAndDescription() { mockServer .expect(requestTo("https://graph.facebook.com/193482154020832")) .andExpect(method(GET)) .andExpect(header("Authorization", "OAuth someAccessToken")) .andRespond(withResponse(jsonResource("testdata/full-event"), responseHeaders)); Event event = facebook.eventOperations().getEvent("193482154020832"); assertEquals("193482154020832", event.getId()); assertEquals("100001387295207", event.getOwner().getId()); assertEquals("Art Names", event.getOwner().getName()); assertEquals("Breakdancing Class", event.getName()); assertEquals(Event.Privacy.SECRET, event.getPrivacy()); assertEquals(toDate("2011-03-30T14:30:00+0000"), event.getStartTime()); assertEquals(toDate("2011-03-30T17:30:00+0000"), event.getEndTime()); assertEquals(toDate("2011-03-30T14:38:40+0000"), event.getUpdatedTime()); assertEquals("Bring your best parachute pants!", event.getDescription()); assertEquals("2400 Dunlavy Dr, Denton, TX", event.getLocation()); }