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

Commit 03cea2e8 authored by Walter Jang's avatar Walter Jang
Browse files

Don't change the default account when saving contacts (E2)

Also address some comments on ag/766424 that were given
after that CL was submitted.

Bug 23667287
Bug 23589603

Change-Id: If2a5aee5c17358278fd3b59ed56b4c5344e5ecf6
parent 708ea9e6
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -364,12 +364,12 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O

    private void parseRawContactDeltas(RawContactDeltaList rawContactDeltas) {
        // Get the raw contact delta for the primary account (the one displayed at the top)
        if (mPrimaryAccount == null || mPrimaryAccount.name == null
                || mReadOnlyDisplayName != null) {
            // Use the first writable contact if this is 1) a phone local contact or 2) an insert,
            // for a read-only contact.  For the last case, we can assume the first writable
            // raw contact is the newly created one because inserts have a raw contact delta list
            // of size 1 and read-only contacts have a list of size 2
        if (mPrimaryAccount == null || TextUtils.isEmpty(mPrimaryAccount.name)
                || !TextUtils.isEmpty(mReadOnlyDisplayName)) {
            // Use the first writable contact if this is an insert for a read-only contact.
            // In this case we can assume the first writable raw contact is the newly created one
            // because inserts have a raw contact delta list of size 1 and read-only contacts have
            // a list of size 2.
            for (RawContactDelta rawContactDelta : rawContactDeltas) {
                if (!rawContactDelta.isVisible()) continue;
                final AccountType accountType = rawContactDelta.getAccountType(mAccountTypeManager);
@@ -564,7 +564,7 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O
    }

    private void addAccountHeader(Pair<String,String> accountInfo) {
        if (accountInfo.first == null) {
        if (TextUtils.isEmpty(accountInfo.first)) {
            // Hide this view so the other text view will be centered vertically
            mAccountHeaderName.setVisibility(View.GONE);
        } else {
@@ -581,7 +581,7 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O
    private void addAccountSelector(Pair<String,String> accountInfo) {
        mAccountSelectorContainer.setVisibility(View.VISIBLE);

        if (accountInfo.first == null) {
        if (TextUtils.isEmpty(accountInfo.first)) {
            // Hide this view so the other text view will be centered vertically
            mAccountSelectorName.setVisibility(View.GONE);
        } else {
+0 −24
Original line number Diff line number Diff line
@@ -972,9 +972,6 @@ abstract public class ContactEditorBaseFragment extends Fragment implements

        setEnabled(false);

        // Store account as default account, only if this is a new contact
        saveDefaultAccountIfNecessary();

        if (isInsert(getActivity().getIntent()) && saveMode == SaveMode.COMPACT
                && mListener != null && backPressed) {
            // If we're coming back from the fully expanded editor and this is an insert, just
@@ -1137,27 +1134,6 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
        }
    }

    /**
     * Saves all writable accounts and the default account, but only for new contacts.
     */
    protected void saveDefaultAccountIfNecessary() {
        // Verify that this is a newly created contact composed of only 1 raw contact
        // and not a user profile
        if (isInsert(mAction) && mState.size() == 1 && !isEditingUserProfile()) {
            // Find the associated account for this contact (retrieve it here because there are
            // multiple paths to creating a contact and this ensures we always have the correct
            // account).
            final RawContactDelta rawContactDelta = mState.get(0);
            String name = rawContactDelta.getAccountName();
            String type = rawContactDelta.getAccountType();
            String dataSet = rawContactDelta.getDataSet();

            AccountWithDataSet account = (name == null || type == null) ? null :
                    new AccountWithDataSet(name, type, dataSet);
            mEditorUtils.saveDefaultAndAllAccounts(account);
        }
    }

    //
    // Data binding
    //