Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2cd9947a authored by Sara Ting's avatar Sara Ting Committed by Android Git Automerger
Browse files

am 30ecf57e: Merge "Query by profile id when it exists for attendee info in...

am 30ecf57e: Merge "Query by profile id when it exists for attendee info in event view." into jb-dev

* commit '30ecf57e':
  Query by profile id when it exists for attendee info in event view.
parents d52ed1a0 30ecf57e
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -76,16 +76,19 @@ public class CalendarEventModel implements Serializable {
        public String mName;
        public String mEmail;
        public int mStatus;
        public String mIdentity;
        public String mIdNamespace;

        public Attendee(String name, String email) {
            mName = name;
            mEmail = email;
            mStatus = Attendees.ATTENDEE_STATUS_NONE;
            this(name, email, Attendees.ATTENDEE_STATUS_NONE, null, null);
        }
        public Attendee(String name, String email, int status) {
        public Attendee(String name, String email, int status, String identity,
                String idNamespace) {
            mName = name;
            mEmail = email;
            mStatus = status;
            mIdentity = identity;
            mIdNamespace = idNamespace;
        }
    }

+18 −8
Original line number Diff line number Diff line
@@ -110,7 +110,6 @@ import static com.android.calendar.CalendarController.EVENT_EDIT_ON_LAUNCH;

public class EventInfoFragment extends DialogFragment implements OnCheckedChangeListener,
        CalendarController.EventHandler, OnClickListener, DeleteEventHelper.DeleteNotifyListener {
    private static final String MACHINE_GENERATED_ADDRESS = "calendar.google.com";

    public static final boolean DEBUG = false;

@@ -194,12 +193,16 @@ public class EventInfoFragment extends DialogFragment implements OnCheckedChange
        Attendees.ATTENDEE_EMAIL,           // 2
        Attendees.ATTENDEE_RELATIONSHIP,    // 3
        Attendees.ATTENDEE_STATUS,          // 4
        Attendees.ATTENDEE_IDENTITY,        // 5
        Attendees.ATTENDEE_ID_NAMESPACE     // 6
    };
    private static final int ATTENDEES_INDEX_ID = 0;
    private static final int ATTENDEES_INDEX_NAME = 1;
    private static final int ATTENDEES_INDEX_EMAIL = 2;
    private static final int ATTENDEES_INDEX_RELATIONSHIP = 3;
    private static final int ATTENDEES_INDEX_STATUS = 4;
    private static final int ATTENDEES_INDEX_IDENTITY = 5;
    private static final int ATTENDEES_INDEX_ID_NAMESPACE = 6;

    private static final String ATTENDEES_WHERE = Attendees.EVENT_ID + "=?";

@@ -840,25 +843,33 @@ public class EventInfoFragment extends DialogFragment implements OnCheckedChange
                        mCalendarOwnerAttendeeId = mAttendeesCursor.getInt(ATTENDEES_INDEX_ID);
                        mOriginalAttendeeResponse = mAttendeesCursor.getInt(ATTENDEES_INDEX_STATUS);
                    } else {
                        String identity = mAttendeesCursor.getString(ATTENDEES_INDEX_IDENTITY);
                        String idNamespace = mAttendeesCursor.getString(
                                ATTENDEES_INDEX_ID_NAMESPACE);

                        // Don't show your own status in the list because:
                        //  1) it doesn't make sense for event without other guests.
                        //  2) there's a spinner for that for events with guests.
                        switch(status) {
                            case Attendees.ATTENDEE_STATUS_ACCEPTED:
                                mAcceptedAttendees.add(new Attendee(name, email,
                                        Attendees.ATTENDEE_STATUS_ACCEPTED));
                                        Attendees.ATTENDEE_STATUS_ACCEPTED, identity,
                                        idNamespace));
                                break;
                            case Attendees.ATTENDEE_STATUS_DECLINED:
                                mDeclinedAttendees.add(new Attendee(name, email,
                                        Attendees.ATTENDEE_STATUS_DECLINED));
                                        Attendees.ATTENDEE_STATUS_DECLINED, identity,
                                        idNamespace));
                                break;
                            case Attendees.ATTENDEE_STATUS_TENTATIVE:
                                mTentativeAttendees.add(new Attendee(name, email,
                                        Attendees.ATTENDEE_STATUS_TENTATIVE));
                                        Attendees.ATTENDEE_STATUS_TENTATIVE, identity,
                                        idNamespace));
                                break;
                            default:
                                mNoResponseAttendees.add(new Attendee(name, email,
                                        Attendees.ATTENDEE_STATUS_NONE));
                                        Attendees.ATTENDEE_STATUS_NONE, identity,
                                        idNamespace));
                        }
                    }
                } while (mAttendeesCursor.moveToNext());
@@ -1551,7 +1562,7 @@ public class EventInfoFragment extends DialogFragment implements OnCheckedChange
            mEventOrganizerEmail = mEventCursor.getString(EVENT_INDEX_ORGANIZER);
            mIsOrganizer = mCalendarOwnerAccount.equalsIgnoreCase(mEventOrganizerEmail);

            if (!mEventOrganizerEmail.endsWith(MACHINE_GENERATED_ADDRESS)) {
            if (!mEventOrganizerEmail.endsWith(Utils.MACHINE_GENERATED_ADDRESS)) {
                mEventOrganizerDisplayName = mEventOrganizerEmail;
            }

@@ -1994,8 +2005,7 @@ public class EventInfoFragment extends DialogFragment implements OnCheckedChange
     *   (2) the attendee is not the viewer, to prevent mailing himself.
     */
    private void addIfEmailable(ArrayList<String> emailList, String email) {
        if (email != null && !email.equals(mSyncAccountName) &&
                !email.endsWith(MACHINE_GENERATED_ADDRESS)) {
        if (Utils.isValidEmail(email) && !email.equals(mSyncAccountName)) {
            emailList.add(email);
        }
    }
+7 −7
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ import java.util.TimeZone;
public class Utils {
    private static final boolean DEBUG = false;
    private static final String TAG = "CalUtils";

    // Set to 0 until we have UI to perform undo
    public static final long UNDO_DELAY = 0;

@@ -108,6 +109,8 @@ public class Utils {

    public static final String APPWIDGET_DATA_TYPE = "vnd.android.data/update";

    static final String MACHINE_GENERATED_ADDRESS = "calendar.google.com";

    private static final TimeZoneUtils mTZUtils = new TimeZoneUtils(SHARED_PREFS_NAME);
    private static boolean mAllowWeekForDetailView = false;
    private static long mTardis = 0;
@@ -1354,13 +1357,10 @@ public class Utils {
    }

    /**
     * Adds the attendee's email to the list if:
     *   (1) the attendee is not a resource like a conference room or another calendar.
     *       Catch most of these by filtering out suffix calendar.google.com.
     *   (2) the attendee is not the viewer, to prevent mailing himself.
     * Example fake email addresses used as attendee emails are resources like conference rooms,
     * or another calendar, etc.  These all end in "calendar.google.com".
     */
    public static boolean isEmailable(String email, String syncAccount) {
        return (email != null && !email.equals(syncAccount) &&
                !email.endsWith("calendar.google.com"));
    public static boolean isValidEmail(String email) {
        return email != null && !email.endsWith(MACHINE_GENERATED_ADDRESS);
    }
}
+30 −8
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.calendar.event;
import com.android.calendar.CalendarEventModel.Attendee;
import com.android.calendar.ContactsAsyncHelper;
import com.android.calendar.R;
import com.android.calendar.Utils;
import com.android.calendar.event.EditEventHelper.AttendeeItem;
import com.android.common.Rfc822Validator;

@@ -35,7 +36,10 @@ import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.provider.CalendarContract.Attendees;
import android.provider.ContactsContract.CommonDataKinds.Email;
import android.provider.ContactsContract.CommonDataKinds.Identity;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.Data;
import android.provider.ContactsContract.RawContacts;
import android.text.TextUtils;
import android.text.util.Rfc822Token;
import android.util.AttributeSet;
@@ -59,10 +63,10 @@ public class AttendeesView extends LinearLayout implements View.OnClickListener
    private static final int EMAIL_PROJECTION_CONTACT_LOOKUP_INDEX = 1;
    private static final int EMAIL_PROJECTION_PHOTO_ID_INDEX = 2;

    private static final String[] EMAIL_PROJECTION = new String[] {
        Email.CONTACT_ID,           // 0
    private static final String[] PROJECTION = new String[] {
        RawContacts.CONTACT_ID,     // 0
        Contacts.LOOKUP_KEY,        // 1
        Email.PHOTO_ID,             // 2
        Contacts.PHOTO_ID,          // 2
    };

    private final Context mContext;
@@ -343,9 +347,23 @@ public class AttendeesView extends LinearLayout implements View.OnClickListener
            }
        }

        mPresenceQueryHandler.startQuery(item.mUpdateCounts + 1, item,
                Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode(attendee.mEmail)),
                EMAIL_PROJECTION, null, null, null);
        Uri uri;
        String selection = null;
        String[] selectionArgs = null;
        if (attendee.mIdentity != null && attendee.mIdNamespace != null) {
            // Query by identity + namespace
            uri = Data.CONTENT_URI;
            selection = Data.MIMETYPE + "=? AND " + Identity.IDENTITY + "=? AND " +
                    Identity.NAMESPACE + "=?";
            selectionArgs = new String[] {Identity.CONTENT_ITEM_TYPE, attendee.mIdentity,
                    attendee.mIdNamespace};
        } else {
            // Query by email
            uri = Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode(attendee.mEmail));
        }

        mPresenceQueryHandler.startQuery(item.mUpdateCounts + 1, item, uri, PROJECTION, selection,
                selectionArgs, null);
    }

    public void addAttendees(ArrayList<Attendee> attendees) {
@@ -435,9 +453,13 @@ public class AttendeesView extends LinearLayout implements View.OnClickListener
                            updateAttendeeView(item);
                        }
                    } else {
                        // Contact not found. Keep the QuickContactBadge with its Email address set,
                        // so that the user can create a contact by tapping
                        // Contact not found.  For real emails, keep the QuickContactBadge with
                        // its Email address set, so that the user can create a contact by tapping.
                        item.mContactLookupUri = null;
                        if (!Utils.isValidEmail(item.mAttendee.mEmail)) {
                            item.mAttendee.mEmail = null;
                            updateAttendeeView(item);
                        }
                    }
                }
            } finally {