From 86ad378625e166a5ea5b03614c5926616000bd55 Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Fri, 16 Aug 2013 12:28:06 +0300 Subject: [PATCH] Refresh DisplayEventActivity in onStart --- src/ro/ieval/unical/Calendar.java | 12 ++++++++++++ src/ro/ieval/unical/DisplayEventActivity.java | 10 +++++----- src/ro/ieval/unical/Event.java | 18 ++++++++++++++++++ src/ro/ieval/unical/EventListActivity.java | 2 +- 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/ro/ieval/unical/Calendar.java b/src/ro/ieval/unical/Calendar.java index 192c937..d6f0a15 100644 --- a/src/ro/ieval/unical/Calendar.java +++ b/src/ro/ieval/unical/Calendar.java @@ -54,4 +54,16 @@ final class Calendar { 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; + } } diff --git a/src/ro/ieval/unical/DisplayEventActivity.java b/src/ro/ieval/unical/DisplayEventActivity.java index 79c053e..af4fe15 100644 --- a/src/ro/ieval/unical/DisplayEventActivity.java +++ b/src/ro/ieval/unical/DisplayEventActivity.java @@ -18,16 +18,16 @@ public class DisplayEventActivity extends Activity { 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); diff --git a/src/ro/ieval/unical/Event.java b/src/ro/ieval/unical/Event.java index a7fce60..6b39cb3 100644 --- a/src/ro/ieval/unical/Event.java +++ b/src/ro/ieval/unical/Event.java @@ -97,6 +97,24 @@ final class Event implements Parcelable{ 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 r = new ArrayList(); for(final Calendar calendar : Calendar.getAllCalendars(context)) { diff --git a/src/ro/ieval/unical/EventListActivity.java b/src/ro/ieval/unical/EventListActivity.java index 8763aeb..3461781 100644 --- a/src/ro/ieval/unical/EventListActivity.java +++ b/src/ro/ieval/unical/EventListActivity.java @@ -58,7 +58,7 @@ public final class EventListActivity extends ListActivity { @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() { -- 2.39.2