From: Petru Date: Fri, 16 Aug 2013 11:26:43 +0000 (+0300) Subject: Use update instead of delete + insert X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=a9aebc182487c7563735215263870ad025c141eb;p=unical.git Use update instead of delete + insert --- diff --git a/src/ro/ieval/unical/AddEventActivity.java b/src/ro/ieval/unical/AddEventActivity.java index 373c4f9..5bb1462 100644 --- a/src/ro/ieval/unical/AddEventActivity.java +++ b/src/ro/ieval/unical/AddEventActivity.java @@ -163,8 +163,8 @@ public final class AddEventActivity extends Activity implements OnDateSetListene 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(); @@ -181,8 +181,13 @@ public final class AddEventActivity extends Activity implements OnDateSetListene 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(); diff --git a/src/ro/ieval/unical/Event.java b/src/ro/ieval/unical/Event.java index 6b39cb3..9357776 100644 --- a/src/ro/ieval/unical/Event.java +++ b/src/ro/ieval/unical/Event.java @@ -144,6 +144,16 @@ final class Event implements Parcelable{ 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();