OSDN Git Service

b/2098823 Fixed the problem where Delete and Edit Event weren't showing in long press...
authorMichael Chan <mchan@android.com>
Fri, 11 Sep 2009 21:42:31 +0000 (14:42 -0700)
committerMichael Chan <mchan@android.com>
Fri, 11 Sep 2009 21:42:31 +0000 (14:42 -0700)
src/com/android/calendar/CalendarView.java
src/com/android/calendar/Event.java

index 8b94d5d..0bc8258 100644 (file)
@@ -84,8 +84,10 @@ public class CalendarView extends View
     private static final String[] CALENDARS_PROJECTION = new String[] {
         Calendars._ID,          // 0
         Calendars.ACCESS_LEVEL, // 1
+        Calendars.OWNER_ACCOUNT, // 2
     };
     private static final int CALENDARS_INDEX_ACCESS_LEVEL = 1;
+    private static final int CALENDARS_INDEX_OWNER_ACCOUNT = 2;
     private static final String CALENDARS_WHERE = Calendars._ID + "=%d";
 
     private static final String[] ATTENDEES_PROJECTION = new String[] {
@@ -2766,25 +2768,23 @@ public class CalendarView extends View
         String where = String.format(CALENDARS_WHERE, calId);
         cursor = cr.query(uri, CALENDARS_PROJECTION, where, null, null);
 
+        String calendarOwnerAccount = null;
         if (cursor != null) {
             cursor.moveToFirst();
             visibility = cursor.getInt(CALENDARS_INDEX_ACCESS_LEVEL);
+            calendarOwnerAccount = cursor.getString(CALENDARS_INDEX_OWNER_ACCOUNT);
             cursor.close();
         }
+        
+        if (visibility < Calendars.CONTRIBUTOR_ACCESS) {
+            return false;
+        }
 
-        // Attendees cursor
-        uri = Attendees.CONTENT_URI;
-        where = String.format(ATTENDEES_WHERE, e.id);
-        Cursor attendeesCursor = cr.query(uri, ATTENDEES_PROJECTION, where, null, null);
-        if (attendeesCursor != null) {
-            if (attendeesCursor.moveToFirst()) {
-                relationship = attendeesCursor.getInt(ATTENDEES_INDEX_RELATIONSHIP);
-            }
-            attendeesCursor.close();
+        if (e.guestsCanModify) {
+            return true;
         }
 
-        return visibility >= Calendars.CONTRIBUTOR_ACCESS &&
-                relationship >= Attendees.RELATIONSHIP_ORGANIZER;
+        return !TextUtils.isEmpty(calendarOwnerAccount) && calendarOwnerAccount.equals(e.organizer);
     }
 
     /**
index 9061cda..956a0f6 100644 (file)
@@ -23,6 +23,7 @@ import android.database.Cursor;
 import android.os.Debug;
 import android.preference.PreferenceManager;
 import android.provider.Calendar.Attendees;
+import android.provider.Calendar.Events;
 import android.provider.Calendar.Instances;
 import android.text.TextUtils;
 import android.text.format.DateUtils;
@@ -56,6 +57,8 @@ public class Event implements Comparable, Cloneable {
             Instances.RRULE,                 // 14
             Instances.RDATE,                 // 15
             Instances.SELF_ATTENDEE_STATUS,  // 16
+            Events.ORGANIZER,                // 17
+            Events.GUESTS_CAN_MODIFY,        // 18
     };
 
     // The indices for the projection array above.
@@ -75,12 +78,16 @@ public class Event implements Comparable, Cloneable {
     private static final int PROJECTION_RRULE_INDEX = 14;
     private static final int PROJECTION_RDATE_INDEX = 15;
     private static final int PROJECTION_SELF_ATTENDEE_STATUS_INDEX = 16;
+    private static final int PROJECTION_ORGANIZER_INDEX = 17;
+    private static final int PROJECTION_GUESTS_CAN_INVITE_OTHERS_INDEX = 18;
 
     public long id;
     public int color;
     public CharSequence title;
     public CharSequence location;
     public boolean allDay;
+    public String organizer;
+    public boolean guestsCanModify;
 
     public int startDay;       // start Julian day
     public int endDay;         // end Julian day
@@ -130,6 +137,8 @@ public class Event implements Comparable, Cloneable {
         e.hasAlarm = hasAlarm;
         e.isRepeating = isRepeating;
         e.selfAttendeeStatus = selfAttendeeStatus;
+        e.organizer = organizer;
+        e.guestsCanModify = guestsCanModify;
 
         return e;
     }
@@ -149,6 +158,8 @@ public class Event implements Comparable, Cloneable {
         dest.hasAlarm = hasAlarm;
         dest.isRepeating = isRepeating;
         dest.selfAttendeeStatus = selfAttendeeStatus;
+        dest.organizer = organizer;
+        dest.guestsCanModify = guestsCanModify;
     }
 
     public static final Event newInstance() {
@@ -196,6 +207,9 @@ public class Event implements Comparable, Cloneable {
         if (allDay && !e.allDay) return -1;
         if (!allDay && e.allDay) return 1;
 
+        if (guestsCanModify && !e.guestsCanModify) return -1;
+        if (!guestsCanModify && e.guestsCanModify) return 1;
+
         // If two events have the same time range, then sort them in
         // alphabetical order based on their titles.
         int cmp = compareStrings(title, e.title);
@@ -210,6 +224,11 @@ public class Event implements Comparable, Cloneable {
         if (cmp != 0) {
             return cmp;
         }
+
+        cmp = compareStrings(organizer, e.organizer);
+        if (cmp != 0) {
+            return cmp;
+        }
         return 0;
     }
 
@@ -316,6 +335,9 @@ public class Event implements Comparable, Cloneable {
                 e.title = c.getString(PROJECTION_TITLE_INDEX);
                 e.location = c.getString(PROJECTION_LOCATION_INDEX);
                 e.allDay = c.getInt(PROJECTION_ALL_DAY_INDEX) != 0;
+                e.organizer = c.getString(PROJECTION_ORGANIZER_INDEX);
+                e.guestsCanModify = c.getInt(PROJECTION_GUESTS_CAN_INVITE_OTHERS_INDEX) != 0;
+
                 String timezone = c.getString(PROJECTION_TIMEZONE_INDEX);
 
                 if (e.title == null || e.title.length() == 0) {
@@ -538,6 +560,8 @@ public class Event implements Comparable, Cloneable {
         Log.e("Cal", "+    endDay = " + endDay);
         Log.e("Cal", "+ startTime = " + startTime);
         Log.e("Cal", "+   endTime = " + endTime);
+        Log.e("Cal", "+ organizer = " + organizer);
+        Log.e("Cal", "+  guestwrt = " + guestsCanModify);
     }
 
     public final boolean intersects(int julianDay, int startMinute,