final ActionBar actionBar = getActionBar();
setContentView(R.layout.add_event);
- if(getIntent().hasExtra(EXTRA_EVENT)) {
- final LinearLayout layout = (LinearLayout) findViewById(R.id.repeat_layout);
- final Switch repeatSwitch = (Switch) findViewById(R.id.repeat_switch);
- Utils.setEnabledRecursively(layout, false);
-
- repeatSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener(layout));
-
- EditText title = (EditText) findViewById(R.id.eventtitle);
- title.setText(event.title);
-
- TextView tstart = (TextView) findViewById(R.id.time_start);
- TextView tend = (TextView) findViewById(R.id.time_end);
- SimpleDateFormat sf=new SimpleDateFormat("HH:mm");
- Date d=new Date(event.dtstart);
- tstart.setText(sf.format(d).toString());
- d.setTime(event.dtend);
- tend.setText(sf.format(d).toString());
-
- SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");
- TextView dstart = (TextView)findViewById(R.id.date_start);
- TextView dend = (TextView)findViewById(R.id.date_end);
- d.setTime(event.dtstart);
- dstart.setText(sd.format(d).toString());
- d.setTime(event.dtend);
- dend.setText(sd.format(d).toString());
- EditText description = (EditText) findViewById(R.id.description);
- description.setText(event.description);
- }
+ final LinearLayout layout = (LinearLayout) findViewById(R.id.repeat_layout);
+ final Switch repeatSwitch = (Switch) findViewById(R.id.repeat_switch);
+ Utils.setEnabledRecursively(layout, false);
+
+ repeatSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener(layout));
+
+ final EditText title = (EditText) findViewById(R.id.eventtitle);
+ title.setText(event.title);
+
+ final TextView tstart = (TextView) findViewById(R.id.time_start);
+ final TextView tend = (TextView) findViewById(R.id.time_end);
+ final SimpleDateFormat sf=new SimpleDateFormat("HH:mm");
+ final Date d=new Date(event.dtstart);
+ tstart.setText(sf.format(d).toString());
+ d.setTime(event.dtend);
+ tend.setText(sf.format(d).toString());
+
+ final SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");
+ final TextView dstart = (TextView)findViewById(R.id.date_start);
+ final TextView dend = (TextView)findViewById(R.id.date_end);
+ d.setTime(event.dtstart);
+ dstart.setText(sd.format(d).toString());
+ d.setTime(event.dtend);
+ dend.setText(sd.format(d).toString());
+ final EditText description = (EditText) findViewById(R.id.description);
+ description.setText(event.description);
}
@Override
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();
public void onTimeSet(final TimePicker picker, final int hour, final int minute) {
dateTimeTextView.setText(String.format("%02d:%02d",hour,minute));
if(dateTimeTextView.getId() == R.id.time_start)
- ((TextView)findViewById(R.id.time_end)).setText(String.format("%2d:%2d",hour,minute));
+ ((TextView)findViewById(R.id.time_end)).setText(String.format("%02d:%02d",hour,minute));
}
@Override