finish();
return true;
case R.id.save:
-
- if(event.title!=null) event.delete(this);
+ boolean edit=false;
+ if(event.title!=null) edit=true;
event.title=((EditText)findViewById(R.id.eventtitle)).getText().toString();
String start=((TextView)findViewById(R.id.date_start)).getText().toString()+ " " +((TextView)findViewById(R.id.time_start)).getText().toString();
String end=((TextView)findViewById(R.id.date_end)).getText().toString()+ " "+((TextView)findViewById(R.id.time_end)).getText().toString();
event.description=((EditText) findViewById(R.id.description)).getText().toString();
if(!Event.calendarCreated)createCalendar();
+ if(event.calendarID!=Event.getUnicalId(this)) {
+ edit=false;
+ event.delete(this);
+ }
event.calendarID=Event.getUnicalId(this);
- event.insert(this);
+ if(!edit) event.insert(this);
+ else event.edit(this);
Toast toast = Toast.makeText(getApplicationContext(),"Event saved!",Toast.LENGTH_LONG);
toast.show();
Uri url = context.getContentResolver().insert(Events.CONTENT_URI, cv);
}
+ public void edit(final Context context) {
+ ContentValues cv = new ContentValues();
+ cv.put("calendar_id",calendarID);
+ cv.put("title",title);
+ cv.put("description",description);
+ cv.put("dtstart",dtstart);
+ cv.put("dtend",dtend);
+ cv.put("eventTimezone", TimeZone.getDefault().getID());
+ context.getContentResolver().update(Events.CONTENT_URI,cv,"_id = '" + String.valueOf(_id) + "'",new String[0]);
+ }
public void delete(final Context context){
final ContentResolver cr=context.getContentResolver();