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

Commit 2c0c7744 authored by Sara Ting's avatar Sara Ting Committed by Android (Google) Code Review
Browse files

Merge "Fix emailing guests from event info page when attendees aren't synced...

Merge "Fix emailing guests from event info page when attendees aren't synced down (too many), by emailing only the organizer." into ics-ub-calendar-aqua
parents e472146a 7ffa24cb
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -285,6 +285,8 @@
    <string name="response_no">No</string>
    <!-- Label for emailing attendees -->
    <string name="email_guests_label">Email guests</string>
    <!-- Label for emailing the organizer (when there are no attendees) -->
    <string name="email_organizer_label">Email organizer</string>
    <!-- This is shown in the popup picker when emailing attendees -->
    <string name="email_picker_label">Email with</string>
    <!-- The is shown in the email subject as the prefix appended to the event title -->
+16 −5
Original line number Diff line number Diff line
@@ -307,6 +307,7 @@ public class EventInfoFragment extends DialogFragment implements OnCheckedChange
    private TextView mWhere;
    private ExpandableTextView mDesc;
    private AttendeesView mLongAttendees;
    private Button emailAttendeesButton;
    private Menu mMenu = null;
    private View mHeadlines;
    private ScrollView mScrollView;
@@ -767,7 +768,7 @@ public class EventInfoFragment extends DialogFragment implements OnCheckedChange
        }

        // Create a listener for the email guests button
        View emailAttendeesButton = mView.findViewById(R.id.email_attendees_button);
        emailAttendeesButton = (Button) mView.findViewById(R.id.email_attendees_button);
        if (emailAttendeesButton != null) {
            emailAttendeesButton.setOnClickListener(new View.OnClickListener() {
                @Override
@@ -1804,8 +1805,16 @@ public class EventInfoFragment extends DialogFragment implements OnCheckedChange
            mLongAttendees.setVisibility(View.GONE);
        }

        if (isEmailable()) {
        if (hasEmailableAttendees()) {
            setVisibilityCommon(mView, R.id.email_attendees_container, View.VISIBLE);
            if (emailAttendeesButton != null) {
                emailAttendeesButton.setText(R.string.email_guests_label);
            }
        } else if (hasEmailableOrganizer()) {
            setVisibilityCommon(mView, R.id.email_attendees_container, View.VISIBLE);
            if (emailAttendeesButton != null) {
                emailAttendeesButton.setText(R.string.email_organizer_label);
            }
        } else {
            setVisibilityCommon(mView, R.id.email_attendees_container, View.GONE);
        }
@@ -1814,7 +1823,7 @@ public class EventInfoFragment extends DialogFragment implements OnCheckedChange
    /**
     * Returns true if there is at least 1 attendee that is not the viewer.
     */
    private boolean isEmailable() {
    private boolean hasEmailableAttendees() {
        for (Attendee attendee : mAcceptedAttendees) {
            if (Utils.isEmailableFrom(attendee.mEmail, mSyncAccountName)) {
                return true;
@@ -1835,8 +1844,10 @@ public class EventInfoFragment extends DialogFragment implements OnCheckedChange
                return true;
            }
        }
        // The meeting organizer doesn't appear as an attendee sometimes (particularly
        // when viewing someone else's calendar), so handle that separately.
        return false;
    }

    private boolean hasEmailableOrganizer() {
        return mEventOrganizerEmail != null &&
                Utils.isEmailableFrom(mEventOrganizerEmail, mSyncAccountName);
    }
+10 −0
Original line number Diff line number Diff line
@@ -475,10 +475,12 @@ public class AlertReceiver extends BroadcastReceiver {
        Calendars.OWNER_ACCOUNT, // 0
        Calendars.ACCOUNT_NAME,  // 1
        Events.TITLE,            // 2
        Events.ORGANIZER,        // 3
    };
    private static final int EVENT_INDEX_OWNER_ACCOUNT = 0;
    private static final int EVENT_INDEX_ACCOUNT_NAME = 1;
    private static final int EVENT_INDEX_TITLE = 2;
    private static final int EVENT_INDEX_ORGANIZER = 3;

    private static Cursor getEventCursor(Context context, long eventId) {
        return context.getContentResolver().query(
@@ -552,12 +554,14 @@ public class AlertReceiver extends BroadcastReceiver {
        String ownerAccount = null;
        String syncAccount = null;
        String eventTitle = null;
        String eventOrganizer = null;
        Cursor eventCursor = getEventCursor(context, eventId);
        try {
            if (eventCursor != null && eventCursor.moveToFirst()) {
                ownerAccount = eventCursor.getString(EVENT_INDEX_OWNER_ACCOUNT);
                syncAccount = eventCursor.getString(EVENT_INDEX_ACCOUNT_NAME);
                eventTitle = eventCursor.getString(EVENT_INDEX_TITLE);
                eventOrganizer = eventCursor.getString(EVENT_INDEX_ORGANIZER);
            }
        } finally {
            if (eventCursor != null) {
@@ -592,6 +596,12 @@ public class AlertReceiver extends BroadcastReceiver {
            }
        }

        // Add organizer only if no attendees to email (the case when too many attendees
        // in the event to sync or show).
        if (toEmails.size() == 0 && ccEmails.size() == 0 && eventOrganizer != null) {
            addIfEmailable(toEmails, eventOrganizer, syncAccount);
        }

        Intent intent = null;
        if (ownerAccount != null && (toEmails.size() > 0 || ccEmails.size() > 0)) {
            intent = Utils.createEmailAttendeesIntent(context.getResources(), eventTitle, body,