OSDN Git Service

- b/2067801 Show event organizer in event info
authorMichael Chan <mchan@android.com>
Mon, 31 Aug 2009 06:28:46 +0000 (23:28 -0700)
committerMichael Chan <mchan@android.com>
Mon, 31 Aug 2009 20:53:22 +0000 (13:53 -0700)
- b/2065026 Moved attendence status on top of other guests' status
- In event info, hide "Add reminder" when adding is not possible i.e. reminders > 5 or busy/free calendar
- Show the Edit event option when appropritate i.e. has write calendar access and (event creator or guest_can_edit flag on)

res/layout/event_info_activity.xml
res/values/strings.xml
src/com/android/calendar/EventInfoActivity.java

index a6b4d73..a431919 100644 (file)
                     android:autoLink="all"
                     style="?android:attr/textAppearanceSmall"
                 />
+
+                <!-- Organizer -->
+                <LinearLayout android:id="@+id/organizer_container"
+                    android:orientation="horizontal"
+                    android:layout_width="fill_parent"
+                    android:layout_height="wrap_content"
+                    android:paddingBottom="5dip"
+                >
+            
+                    <TextView
+                        android:layout_width="wrap_content"
+                        android:layout_height="wrap_content"
+                        android:layout_marginRight="5dip"
+                        android:text="@string/view_event_organizer_label"
+                        style="?android:attr/textAppearanceSmall"
+                    />
     
+                    <TextView android:id="@+id/organizer"
+                        android:layout_width="fill_parent"
+                        android:layout_height="wrap_content"
+                        style="?android:attr/textAppearanceSmall"
+                    />
+                </LinearLayout>
+
                 <!-- DESCRIPTION -->
                 <TextView android:id="@+id/description"
                     android:layout_width="fill_parent"
             </LinearLayout>
         </LinearLayout>
 
-        <!-- GUEST LIST -->
-        <LinearLayout
-            android:id="@+id/attendee_list"
-            android:layout_width="fill_parent"
-            android:layout_height="wrap_content"
-            android:paddingLeft="8dip"
-            android:orientation="vertical" />
-
         <!-- RESPONSE -->
         <LinearLayout android:id="@+id/response_container"
             android:orientation="vertical"
                 android:entries="@array/response_labels1"/>
         </LinearLayout>
         
+        <!-- GUEST LIST -->
+        <LinearLayout
+            android:id="@+id/attendee_list"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:paddingLeft="8dip"
+            android:orientation="vertical" />
+
         <!-- REMINDERS -->
         <LinearLayout android:id="@+id/reminders_container"
             android:orientation="vertical"
             android:paddingLeft="8dip"
             android:paddingRight="7dip"
             android:paddingTop="5dip"
-            android:paddingBottom="1dip">
+            android:paddingBottom="5dip">
         
             <TextView android:id="@+id/reminders_label"
                 android:layout_width="wrap_content"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content">
             </LinearLayout>
-        </LinearLayout>
-        <LinearLayout
-            android:layout_width="fill_parent"
-            android:layout_height="wrap_content"
-            android:gravity="center_vertical|right"
-            android:paddingRight="5dip"
-            android:paddingBottom="5dip">
-
-            <TextView
-                android:layout_width="wrap_content"
+            <LinearLayout android:id="@+id/reminder_adder"
+                android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
-                android:layout_marginRight="7dip"
-                android:text="@string/add_new_reminder"/>
+                android:gravity="center_vertical|right">
 
-            <ImageButton android:id="@+id/reminder_add"
-                style="@style/PlusButton"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:layout_marginRight="2dip"
-            />
+                <TextView
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_marginRight="7dip"
+                    android:text="@string/add_new_reminder"/>
+
+                <ImageButton android:id="@+id/reminder_add"
+                    style="@style/PlusButton"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                />
+            </LinearLayout>
         </LinearLayout>
     </LinearLayout>
 </ScrollView>
index 4286874..474be03 100644 (file)
     <skip />
     <!-- Label for which calendar an event is part of -->
     <string name="view_event_calendar_label">Calendar</string>
+    <!-- Label for the event organizer -->
+    <string name="view_event_organizer_label">Organizer</string>
     <!-- Label for the local timezone -->
     <string name="view_event_timezone_label">Local time zone</string>
     <!-- Label for whether the user is attending this event. This is shown when
index fb1faea..c56adca 100644 (file)
@@ -83,6 +83,10 @@ import java.util.regex.Pattern;
 
 public class EventInfoActivity extends Activity implements View.OnClickListener,
         AdapterView.OnItemSelectedListener {
+    public static final boolean DEBUG = false;
+
+    public static final String TAG = "EventInfoActivity";
+
     private static final int MAX_REMINDERS = 5;
 
     /**
@@ -107,7 +111,9 @@ public class EventInfoActivity extends Activity implements View.OnClickListener,
         Events.ACCESS_LEVEL,         // 11
         Events.COLOR,                // 12
         Events.GUESTS_CAN_MODIFY,    // 13
-        Events.ORGANIZER,            // 14
+        // TODO Events.CAN_INVITE_OTHERS is broken. Investigate
+        Events.GUESTS_CAN_INVITE_OTHERS, // 14
+        Events.ORGANIZER,            // 15
     };
     private static final int EVENT_INDEX_ID = 0;
     private static final int EVENT_INDEX_TITLE = 1;
@@ -122,7 +128,8 @@ public class EventInfoActivity extends Activity implements View.OnClickListener,
     private static final int EVENT_INDEX_ACCESS_LEVEL = 11;
     private static final int EVENT_INDEX_COLOR = 12;
     private static final int EVENT_INDEX_GUESTS_CAN_MODIFY = 13;
-    private static final int EVENT_INDEX_ORGANIZER = 14;
+    private static final int EVENT_INDEX_CAN_INVITE_OTHERS = 14;
+    private static final int EVENT_INDEX_ORGANIZER = 15;
 
     private static final String[] ATTENDEES_PROJECTION = new String[] {
         Attendees._ID,                      // 0
@@ -179,6 +186,8 @@ public class EventInfoActivity extends Activity implements View.OnClickListener,
     };
 
     private LinearLayout mRemindersContainer;
+    private LinearLayout mOrganizerContainer;
+    private TextView mOrganizerView;
 
     private Uri mUri;
     private long mEventId;
@@ -192,8 +201,9 @@ public class EventInfoActivity extends Activity implements View.OnClickListener,
     private long mCalendarOwnerAttendeeId = -1;
     private String mCalendarOwnerAccount;
     private boolean mCanModifyCalendar;
+    private boolean mIsBusyFreeCalendar;
     private boolean mCanModifyEvent;
-    private boolean mIsAttendee;
+    private int mNumOfAttendees;
     private String mOrganizer;
 
     private ArrayList<Integer> mOriginalMinutes = new ArrayList<Integer>();
@@ -212,6 +222,7 @@ public class EventInfoActivity extends Activity implements View.OnClickListener,
 
     private Pattern mWildcardPattern = Pattern.compile("^.*$");
     private LayoutInflater mLayoutInflater;
+    private LinearLayout mReminderAdder;
 
     // TODO This can be removed when the contacts content provider doesn't return duplicates
     private int mUpdateCounts;
@@ -238,10 +249,6 @@ public class EventInfoActivity extends Activity implements View.OnClickListener,
         Contacts.PHOTO_ID,        // 3
     };
 
-    public static final boolean DEBUG = false;
-
-    public static final String TAG = "EventInfoActivity";
-
     ArrayList<Attendee> mAcceptedAttendees = new ArrayList<Attendee>();
     ArrayList<Attendee> mDeclinedAttendees = new ArrayList<Attendee>();
     ArrayList<Attendee> mTentativeAttendees = new ArrayList<Attendee>();
@@ -338,11 +345,15 @@ public class EventInfoActivity extends Activity implements View.OnClickListener,
             mCalendarOwnerAccount = mCalendarsCursor.getString(CALENDARS_INDEX_OWNER_ACCOUNT);
         }
 
+        String eventOrganizer = mEventCursor.getString(EVENT_INDEX_ORGANIZER);
+        mOrganizer = eventOrganizer;
         mCanModifyCalendar =
                 mEventCursor.getInt(EVENT_INDEX_ACCESS_LEVEL) >= Calendars.CONTRIBUTOR_ACCESS;
+        mIsBusyFreeCalendar =
+                mEventCursor.getInt(EVENT_INDEX_ACCESS_LEVEL) == Calendars.FREEBUSY_ACCESS;
         mCanModifyEvent = mCanModifyCalendar
-                && (mEventCursor.getInt(EVENT_INDEX_GUESTS_CAN_MODIFY) != 0);
-        mOrganizer = mEventCursor.getString(EVENT_INDEX_ORGANIZER);
+                && (mCalendarOwnerAccount.equals(eventOrganizer)
+                        || mEventCursor.getInt(EVENT_INDEX_GUESTS_CAN_MODIFY) != 0);
 
         // Initialize the reminder values array.
         Resources r = getResources();
@@ -361,7 +372,9 @@ public class EventInfoActivity extends Activity implements View.OnClickListener,
                 prefs.getString(CalendarPreferenceActivity.KEY_DEFAULT_REMINDER, "0");
         mDefaultReminderMinutes = Integer.parseInt(durationString);
 
-        mRemindersContainer = (LinearLayout) findViewById(R.id.reminder_items_container);
+        mRemindersContainer = (LinearLayout) findViewById(R.id.reminders_container);
+        mOrganizerContainer = (LinearLayout) findViewById(R.id.organizer_container);
+        mOrganizerView = (TextView) findViewById(R.id.organizer);
 
         // Reminders cursor
         boolean hasAlarm = mEventCursor.getInt(EVENT_INDEX_HAS_ALARM) != 0;
@@ -392,7 +405,6 @@ public class EventInfoActivity extends Activity implements View.OnClickListener,
         }
 
         updateView();
-        updateRemindersVisibility();
 
         // Setup the + Add Reminder Button
         View.OnClickListener addReminderOnClickListener = new View.OnClickListener() {
@@ -400,8 +412,11 @@ public class EventInfoActivity extends Activity implements View.OnClickListener,
                 addReminder();
             }
         };
-        ImageButton reminderRemoveButton = (ImageButton) findViewById(R.id.reminder_add);
-        reminderRemoveButton.setOnClickListener(addReminderOnClickListener);
+        ImageButton reminderAddButton = (ImageButton) findViewById(R.id.reminder_add);
+        reminderAddButton.setOnClickListener(addReminderOnClickListener);
+
+        mReminderAdder = (LinearLayout) findViewById(R.id.reminder_adder);
+        updateRemindersVisibility();
 
         mDeleteEventHelper = new DeleteEventHelper(this, true /* exit when done */);
         mEditResponseHelper = new EditResponseHelper(this);
@@ -426,7 +441,7 @@ public class EventInfoActivity extends Activity implements View.OnClickListener,
 
     private void updateTitle() {
         Resources res = getResources();
-        if (mCanModifyCalendar && mIsAttendee) {
+        if (mCanModifyCalendar && mNumOfAttendees > 1) {
             setTitle(res.getString(R.string.event_info_title_invite));
         } else {
             setTitle(res.getString(R.string.event_info_title));
@@ -462,7 +477,9 @@ public class EventInfoActivity extends Activity implements View.OnClickListener,
     private void initAttendeesCursor() {
         mOriginalAttendeeResponse = ATTENDEE_NO_RESPONSE;
         mCalendarOwnerAttendeeId = -1;
+        mNumOfAttendees = 0;
         if (mAttendeesCursor != null) {
+            mNumOfAttendees = mAttendeesCursor.getCount();
             if (mAttendeesCursor.moveToFirst()) {
                 mAcceptedAttendees.clear();
                 mDeclinedAttendees.clear();
@@ -473,8 +490,17 @@ public class EventInfoActivity extends Activity implements View.OnClickListener,
                     String name = mAttendeesCursor.getString(ATTENDEES_INDEX_NAME);
                     String email = mAttendeesCursor.getString(ATTENDEES_INDEX_EMAIL);
 
+                    if (mAttendeesCursor.getInt(ATTENDEES_INDEX_RELATIONSHIP) ==
+                            Attendees.RELATIONSHIP_ORGANIZER) {
+                        // Overwrites the one from Event table if available
+                        if (name != null && name.length() > 0) {
+                            mOrganizer = name;
+                        } else if (email != null && email.length() > 0) {
+                            mOrganizer = email;
+                        }
+                    }
+
                     if (mCalendarOwnerAttendeeId == -1 && mCalendarOwnerAccount.equals(email)) {
-                        mIsAttendee = true;
                         mCalendarOwnerAttendeeId = mAttendeesCursor.getInt(ATTENDEES_INDEX_ID);
                         mOriginalAttendeeResponse = mAttendeesCursor.getInt(ATTENDEES_INDEX_STATUS);
                     }
@@ -495,6 +521,12 @@ public class EventInfoActivity extends Activity implements View.OnClickListener,
                 updateAttendees();
             }
         }
+        if (mNumOfAttendees > 1) {
+            mOrganizerContainer.setVisibility(View.VISIBLE);
+            mOrganizerView.setText(mOrganizer);
+        } else {
+            mOrganizerContainer.setVisibility(View.GONE);
+        }
     }
 
     private void initCalendarsCursor() {
@@ -551,9 +583,7 @@ public class EventInfoActivity extends Activity implements View.OnClickListener,
 
     @Override
     public boolean onPrepareOptionsMenu(Menu menu) {
-        // Cannot add reminders to a shared calendar with only free/busy
-        // permissions
-        boolean canAddReminders = mCanModifyCalendar && mReminderItems.size() < MAX_REMINDERS;
+        boolean canAddReminders = canAddReminders();
         menu.setGroupVisible(MENU_GROUP_REMINDER, canAddReminders);
         menu.setGroupEnabled(MENU_GROUP_REMINDER, canAddReminders);
 
@@ -565,6 +595,10 @@ public class EventInfoActivity extends Activity implements View.OnClickListener,
         return super.onPrepareOptionsMenu(menu);
     }
 
+    private boolean canAddReminders() {
+        return !mIsBusyFreeCalendar && mReminderItems.size() < MAX_REMINDERS;
+    }
+
     private void addReminder() {
         // TODO: when adding a new reminder, make it different from the
         // last one in the list (if any).
@@ -605,10 +639,11 @@ public class EventInfoActivity extends Activity implements View.OnClickListener,
     }
 
     private void updateRemindersVisibility() {
-        if (mReminderItems.size() == 0) {
+        if (mIsBusyFreeCalendar) {
             mRemindersContainer.setVisibility(View.GONE);
         } else {
             mRemindersContainer.setVisibility(View.VISIBLE);
+            mReminderAdder.setVisibility(canAddReminders() ? View.VISIBLE : View.GONE);
         }
     }
 
@@ -977,7 +1012,7 @@ public class EventInfoActivity extends Activity implements View.OnClickListener,
     }
 
     void updateResponse() {
-        if (!mCanModifyCalendar || !mIsAttendee) {
+        if (!mCanModifyCalendar || mNumOfAttendees <= 1) {
             setVisibilityCommon(R.id.response_container, View.GONE);
             return;
         }