cursor.close();
return calendars;
}
+
+ public static Calendar getCalendarById(final Context context, final long id){
+ final ContentResolver cr=context.getContentResolver();
+ final Cursor cursor = cr.query(Calendars.CONTENT_URI, PROJECTION, BaseColumns._ID + " = ?", new String[]{Long.toString(id)}, null);
+ final Calendar calendar;
+ if(cursor.moveToFirst())
+ calendar = new Calendar(cursor.getLong(0), cursor.getString(1), cursor.getString(2), cursor.getInt(3)!=0, cursor.getString(4), cursor.getString(5), cursor.getInt(6));
+ else
+ calendar = null;
+ cursor.close();
+ return calendar;
+ }
}
private Event event;
private final DeleteEventDialog d=new DeleteEventDialog();
- public static void displayEvent(final Context context, final Event event){
+ public static void displayEvent(final Context context, final long id){
final Intent i=new Intent(context,DisplayEventActivity.class);
- i.putExtra(DisplayEventActivity.EXTRA_EVENT, event);
+ i.putExtra(DisplayEventActivity.EXTRA_EVENT, id);
context.startActivity(i);
}
@Override
- protected void onCreate(final Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- event=getIntent().getParcelableExtra(EXTRA_EVENT);
+ protected void onStart() {
+ super.onStart();
+ event=getIntent().hasExtra(EXTRA_EVENT) ? Event.getEventById(this, getIntent().getLongExtra(EXTRA_EVENT, 0)) : new Event();
setContentView(R.layout.event_view);
setTitle(event.title);
return events;
}
+ public static Event getEventById(final Context context, final long id){
+ final ContentResolver cr=context.getContentResolver();
+ final Cursor cursor = cr.query(Events.CONTENT_URI,
+ PROJECTION,
+ BaseColumns._ID+" = ?",
+ new String[]{Long.toString(id)},
+ null);
+ final Event event;
+ if(cursor.moveToFirst()){
+ int colour=cursor.getInt(5);
+ colour=colour == 0 ? Calendar.getCalendarById(context, cursor.getLong(8)).colour : colour;
+ event = new Event(cursor.getLong(0), cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getString(4), colour, cursor.getLong(6), cursor.getLong(7), cursor.getLong(8));
+ } else
+ event = null;
+ cursor.close();
+ return event;
+ }
+
public static Event[] getAllEvents(final Context context) {
final ArrayList<Event> r = new ArrayList<Event>();
for(final Calendar calendar : Calendar.getAllCalendars(context)) {
@Override
public void onListItemClick(final ListView view, final View v, final int pos, final long id) {
- DisplayEventActivity.displayEvent(this, events[pos]);
+ DisplayEventActivity.displayEvent(this, events[pos]._id);
}
private void displayEvents() {