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

Commit 23709545 authored by Walter Jang's avatar Walter Jang
Browse files

Allow "Saving to" and linked selectors to be displayed at the same time

Also, only show contacts that can be opened in the full editor
in the linked accounts selector.

Bug 25186290

Change-Id: Iefecb47b40160b291acdc358fad4a6c17492df07
parent c44db6ee
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -229,7 +229,7 @@ public class CompactContactEditorFragment extends ContactEditorBaseFragment impl

    @Override
    public void onPhotoEditorViewClicked() {
        if (isMultiAccountContact()) {
        if (isEditingMultipleRawContacts()) {
            final ArrayList<CompactPhotoSelectionFragment.Photo> photos = getContent().getPhotos();
            if (photos.size() > 1) {
                // For aggregate contacts, the user may select a new super primary photo from among
@@ -260,7 +260,7 @@ public class CompactContactEditorFragment extends ContactEditorBaseFragment impl

    private int getPhotoMode() {
        if (getContent().isWritablePhotoSet()) {
            return isMultiAccountContact()
            return isEditingMultipleRawContacts()
                    ? PhotoActionPopup.Modes.MULTIPLE_WRITE_ABLE_PHOTOS
                    : PhotoActionPopup.Modes.WRITE_ABLE_PHOTO;
        }
+16 −11
Original line number Diff line number Diff line
@@ -143,7 +143,7 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O
            mContext = context;
            mRawContactDeltas = new RawContactDeltaList();
            for (RawContactDelta rawContactDelta : rawContactDeltas) {
                if (rawContactDelta.isVisible()) {
                if (rawContactDelta.isVisible() && rawContactDelta.getRawContactId() > 0) {
                    mRawContactDeltas.add(rawContactDelta);
                }
            }
@@ -749,7 +749,7 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O
                        rawContactDelta.getAccountName(),
                        rawContactDelta.getAccountType(mAccountTypeManager));

        // Only one of the account header, selector, and raw contact selector should be shown
        // Either the account header or selector should be shown, not both.
        final List<AccountWithDataSet> accounts =
                AccountTypeManager.getInstance(getContext()).getAccounts(true);
        if (mHasNewContact && !mIsUserProfile) {
@@ -758,11 +758,21 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O
            } else {
                addAccountHeader(accountInfo);
            }
        } else if (rawContactDeltas.size() > 1) {
            addRawContactAccountSelector(rawContactDeltas);
        } else {
            addAccountHeader(accountInfo);
        }

        // The raw contact selector should only display linked raw contacts that can be edited in
        // the full editor (i.e. they are not newly created raw contacts)
        Collections.sort(rawContactDeltas, new RawContactDeltaComparator(getContext()));
        final RawContactAccountListAdapter adapter =
                new RawContactAccountListAdapter(getContext(), rawContactDeltas);
        if (adapter.getCount() > 1) {
            final String accountsSummary = getResources().getString(
                    R.string.compact_editor_linked_contacts_selector_title,
                    adapter.getCount());
            addRawContactAccountSelector(accountsSummary, adapter);
        }
    }

    private void addAccountHeader(Pair<String,String> accountInfo) {
@@ -847,21 +857,16 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O
        });
    }

    private void addRawContactAccountSelector(final RawContactDeltaList rawContactDeltas) {
    private void addRawContactAccountSelector(String accountsSummary,
            final RawContactAccountListAdapter adapter) {
        mRawContactContainer.setVisibility(View.VISIBLE);

        Collections.sort(rawContactDeltas, new RawContactDeltaComparator(getContext()));

        final String accountsSummary = getResources().getString(
                R.string.compact_editor_linked_contacts_selector_title, rawContactDeltas.size());
        mRawContactSummary.setText(accountsSummary);

        mRawContactContainer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                final ListPopupWindow popup = new ListPopupWindow(getContext(), null);
                final RawContactAccountListAdapter adapter =
                        new RawContactAccountListAdapter(getContext(), rawContactDeltas);
                popup.setWidth(mRawContactContainer.getWidth());
                popup.setAnchorView(mRawContactContainer);
                popup.setAdapter(adapter);
+27 −10
Original line number Diff line number Diff line
@@ -758,15 +758,7 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
            deleteMenu.setVisible(false);
        } else if (isEdit(mAction)) {
            HelpUtils.prepareHelpMenuItem(mContext, helpMenu, R.string.help_url_people_edit);
            // Split only if there is more than one raw contact, it is not a user-profile, and
            // splitting won't result in an empty contact. For the empty contact case, we only guard
            // against this when there is a single read-only contact in the aggregate.  If the user
            // has joined >1 read-only contacts together, we allow them to split it,
            // even if they have never added their own information and splitting will create a
            // name only contact.
            final boolean isSingleReadOnlyContact = mHasNewContact && mState.size() == 2;
            splitMenu.setVisible(isMultiAccountContact() && !isEditingUserProfile()
                    && !isSingleReadOnlyContact);
            splitMenu.setVisible(canUnlinkRawContacts());
            // Cannot join a user profile
            joinMenu.setVisible(!isEditingUserProfile());
            deleteMenu.setVisible(!mDisableDeleteMenuOption && !isEditingUserProfile());
@@ -966,10 +958,22 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
        return mNewLocalProfile || mIsUserProfile;
    }

    protected boolean isMultiAccountContact() {
    /**
     * Whether the contact being edited spans multiple raw contacts.
     * The may also span multiple accounts.
     */
    public boolean isEditingMultipleRawContacts() {
        return mState.size() > 1;
    }

    /**
     * Whether the contact being edited is composed of a single read-only raw contact
     * aggregated with a newly created writable raw contact.
     */
    protected boolean isEditingReadOnlyRawContactWithNewContact() {
        return mHasNewContact && mState.size() == 2;
    }

    /**
     * Return true if there are any edits to the current contact which need to
     * be saved.
@@ -979,6 +983,19 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
        return RawContactModifier.hasChanges(mState, accountTypes);
    }

    /**
     * We allow unlinking only if there is more than one raw contact, it is not a user-profile,
     * and unlinking won't result in an empty contact.  For the empty contact case, we only guard
     * against this when there is a single read-only contact in the aggregate.  If the user
     * has joined >1 read-only contacts together, we allow them to unlink it, even if they have
     * never added their own information and unlinking will create a name only contact.
     */
    protected boolean canUnlinkRawContacts() {
        return isEditingMultipleRawContacts()
                && !isEditingUserProfile()
                && !isEditingReadOnlyRawContactWithNewContact();
    }

    /**
     * Determines if changes were made in the editor that need to be saved, while taking into
     * account that name changes are not real for read-only contacts.