]> iEval git - unical.git/commitdiff
Refresh DisplayEventActivity in onStart
authorMarius Gavrilescu <marius@ieval.ro>
Fri, 16 Aug 2013 09:28:06 +0000 (12:28 +0300)
committerMarius Gavrilescu <marius@ieval.ro>
Fri, 16 Aug 2013 09:28:06 +0000 (12:28 +0300)
src/ro/ieval/unical/Calendar.java
src/ro/ieval/unical/DisplayEventActivity.java
src/ro/ieval/unical/Event.java
src/ro/ieval/unical/EventListActivity.java

index 192c93784a008812ba218eac1843c6ff6f67bd5d..d6f0a159589b2ae8c48cdc311810fe35a1ddb70a 100644 (file)
@@ -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;
+       }
 }
index 79c053e904a2e620c7385f31d27622468426b9dc..af4fe159379eda508d0d3741b9ad9c3458545397 100644 (file)
@@ -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);
 
index a7fce60a038b1a62b1b0e5a44a73f8146389a34a..6b39cb3ce9722b18f6f0e61860bd4dbbd82b679d 100644 (file)
@@ -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<Event> r = new ArrayList<Event>();
                for(final Calendar calendar : Calendar.getAllCalendars(context))   {
index 8763aebeb798ad0b3ace6e5594af4fe2f8620dfc..346178152de3da4fcb89fb7e5172d4b4f68e5f91 100644 (file)
@@ -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() {
This page took 0.0318 seconds and 4 git commands to generate.