OSDN Git Service

b/2531257 More work on cleaning up owner account for dupes
[android-x86/packages-apps-Calendar.git] / src / com / android / calendar / EventInfoActivity.java
index 4079c86..8f4b4cc 100644 (file)
@@ -156,11 +156,14 @@ public class EventInfoActivity extends Activity implements View.OnClickListener,
         Calendars._ID,           // 0
         Calendars.DISPLAY_NAME,  // 1
         Calendars.OWNER_ACCOUNT, // 2
+        Calendars.ORGANIZER_CAN_RESPOND // 3
     };
     static final int CALENDARS_INDEX_DISPLAY_NAME = 1;
     static final int CALENDARS_INDEX_OWNER_ACCOUNT = 2;
+    static final int CALENDARS_INDEX_OWNER_CAN_RESPOND = 3;
 
     static final String CALENDARS_WHERE = Calendars._ID + "=%d";
+    static final String CALENDARS_DUPLICATE_NAME_WHERE = Calendars.DISPLAY_NAME + "=?";
 
     private static final String[] REMINDERS_PROJECTION = new String[] {
         Reminders._ID,      // 0
@@ -205,6 +208,7 @@ public class EventInfoActivity extends Activity implements View.OnClickListener,
     private boolean mHasAttendeeData;
     private boolean mIsOrganizer;
     private long mCalendarOwnerAttendeeId = ATTENDEE_ID_NONE;
+    private boolean mOrganizerCanRespond;
     private String mCalendarOwnerAccount;
     private boolean mCanModifyCalendar;
     private boolean mIsBusyFreeCalendar;
@@ -226,6 +230,7 @@ public class EventInfoActivity extends Activity implements View.OnClickListener,
     private int mOriginalAttendeeResponse;
     private int mAttendeeResponseFromIntent = ATTENDEE_NO_RESPONSE;
     private boolean mIsRepeating;
+    private boolean mIsDuplicateName;
 
     private Pattern mWildcardPattern = Pattern.compile("^.*$");
     private LayoutInflater mLayoutInflater;
@@ -331,6 +336,10 @@ public class EventInfoActivity extends Activity implements View.OnClickListener,
         if (mCalendarsCursor != null) {
             mCalendarsCursor.moveToFirst();
             mCalendarOwnerAccount = mCalendarsCursor.getString(CALENDARS_INDEX_OWNER_ACCOUNT);
+            mOrganizerCanRespond = mCalendarsCursor.getInt(CALENDARS_INDEX_OWNER_CAN_RESPOND) != 0;
+
+            String displayName = mCalendarsCursor.getString(CALENDARS_INDEX_DISPLAY_NAME);
+            mIsDuplicateName = isDuplicateName(displayName);
         }
         String eventOrganizer = mEventCursor.getString(EVENT_INDEX_ORGANIZER);
         mIsOrganizer = mCalendarOwnerAccount.equalsIgnoreCase(eventOrganizer);
@@ -438,6 +447,19 @@ public class EventInfoActivity extends Activity implements View.OnClickListener,
         }
     }
 
+    boolean isDuplicateName(String displayName) {
+        Cursor dupNameCursor = managedQuery(Calendars.CONTENT_URI, CALENDARS_PROJECTION,
+                CALENDARS_DUPLICATE_NAME_WHERE, new String[] {displayName}, null);
+        boolean isDuplicateName = false;
+        if(dupNameCursor != null) {
+            if (dupNameCursor.getCount() > 1) {
+                isDuplicateName = true;
+            }
+            dupNameCursor.close();
+        }
+        return isDuplicateName;
+    }
+
     /**
      * Initializes the event cursor, which is expected to point to the first
      * (and only) result from a query.
@@ -906,6 +928,15 @@ public class EventInfoActivity extends Activity implements View.OnClickListener,
         // Calendar
         if (mCalendarsCursor != null) {
             String calendarName = mCalendarsCursor.getString(CALENDARS_INDEX_DISPLAY_NAME);
+            String ownerAccount = mCalendarsCursor.getString(CALENDARS_INDEX_OWNER_ACCOUNT);
+            if (mIsDuplicateName && !calendarName.equalsIgnoreCase(ownerAccount)) {
+                Resources res = getResources();
+                TextView ownerText = (TextView) findViewById(R.id.owner);
+                ownerText.setText(ownerAccount);
+                ownerText.setTextColor(res.getColor(R.color.calendar_owner_text_color));
+            } else {
+                setVisibilityCommon(R.id.owner, View.GONE);
+            }
             setTextCommon(R.id.calendar, calendarName);
         } else {
             setVisibilityCommon(R.id.calendar_container, View.GONE);
@@ -1050,14 +1081,16 @@ public class EventInfoActivity extends Activity implements View.OnClickListener,
     void updateResponse() {
         // we only let the user accept/reject/etc. a meeting if:
         // a) you can edit the event's containing calendar AND
-        // b) you're not the organizer and only attendee
+        // b) you're not the organizer and only attendee AND
+        // c) organizerCanRespond is enabled for the calendar
         // (if the attendee data has been hidden, the visible number of attendees
         // will be 1 -- the calendar owner's).
         // (there are more cases involved to be 100% accurate, such as
         // paying attention to whether or not an attendee status was
         // included in the feed, but we're currently omitting those corner cases
         // for simplicity).
-        if (!mCanModifyCalendar || (mHasAttendeeData && mIsOrganizer && mNumOfAttendees <= 1)) {
+        if (!mCanModifyCalendar || (mHasAttendeeData && mIsOrganizer && mNumOfAttendees <= 1) ||
+                (mIsOrganizer && !mOrganizerCanRespond)) {
             setVisibilityCommon(R.id.response_container, View.GONE);
             return;
         }