]> iEval git - unical.git/commitdiff
Use update instead of delete + insert
authorPetru <l3asketballplayer@yahoo.com>
Fri, 16 Aug 2013 11:26:43 +0000 (14:26 +0300)
committerPetru <l3asketballplayer@yahoo.com>
Fri, 16 Aug 2013 11:26:43 +0000 (14:26 +0300)
src/ro/ieval/unical/AddEventActivity.java
src/ro/ieval/unical/Event.java

index 373c4f9088053009a087e8e11c544785d212428d..5bb14623e51d2d61dae920a179713a44a298e1f3 100644 (file)
@@ -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();
index 6b39cb3ce9722b18f6f0e61860bd4dbbd82b679d..9357776ffbf4705dec7189d8be12e22ed6103642 100644 (file)
@@ -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();
This page took 0.021007 seconds and 4 git commands to generate.