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

Commit 3107b25d authored by Gary Mai's avatar Gary Mai
Browse files

Show "add account" dialog when it needs to appear

Don't show the dialog if the only account is not a device account.
Set the default to be the only account if it is *not* a device
account.

Test:
Manually checked:
  * Removing only account and attempting to create a new account shows
    dialog
  * Clearing preferences shows dialog
  * If dialog was canceled, verify dialog doesn't appear anymore.
  * After adding a google account, (and without manually setting default)
    verified adding a new contact did not show a dialog and the default was
    automatically set to the only account on device.
  * Having two accounts and no default shows the pick default account dialog
  * Removing multiple accounts still has the same behavior as bullet 1

Bug:32555078
Change-Id: Iec664efca7e886d7376cd2aae7c5b2bdad3a8b84
parent 817e9e6f
Loading
Loading
Loading
Loading
+2 −4
Original line number Original line Diff line number Diff line
@@ -16,13 +16,10 @@


package com.android.contacts.common.preference;
package com.android.contacts.common.preference;


import android.content.ContentResolver;
import android.content.Context;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.SharedPreferences.Editor;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Handler;
import android.os.Looper;
import android.os.Looper;
import android.preference.PreferenceManager;
import android.preference.PreferenceManager;
@@ -219,7 +216,8 @@ public class ContactsPreferences implements OnSharedPreferenceChangeListener {
            return defaultAccount == null || !defaultAccount.isNullAccount();
            return defaultAccount == null || !defaultAccount.isNullAccount();
        }
        }


        if (currentWritableAccounts.size() == 1) {
        if (currentWritableAccounts.size() == 1
                && !currentWritableAccounts.get(0).isNullAccount()) {
            return false;
            return false;
        }
        }


+3 −0
Original line number Original line Diff line number Diff line
@@ -987,6 +987,9 @@ public class ContactEditorFragment extends Fragment implements
            mStatus = Status.SUB_ACTIVITY;
            mStatus = Status.SUB_ACTIVITY;
            startActivityForResult(intent, REQUEST_CODE_ACCOUNTS_CHANGED);
            startActivityForResult(intent, REQUEST_CODE_ACCOUNTS_CHANGED);
        } else {
        } else {
            // Make sure the default account is automatically set if there is only one non-device
            // account.
            mEditorUtils.maybeUpdateDefaultAccount();
            // Otherwise, there should be a default account. Then either create a local contact
            // Otherwise, there should be a default account. Then either create a local contact
            // (if default account is null) or create a contact with the specified account.
            // (if default account is null) or create a contact with the specified account.
            AccountWithDataSet defaultAccount = mEditorUtils.getOnlyOrDefaultAccount();
            AccountWithDataSet defaultAccount = mEditorUtils.getOnlyOrDefaultAccount();
+14 −0
Original line number Original line Diff line number Diff line
@@ -132,6 +132,20 @@ public class ContactEditorUtils {
        return mContactsPrefs.shouldShowAccountChangedNotification(getWritableAccounts());
        return mContactsPrefs.shouldShowAccountChangedNotification(getWritableAccounts());
    }
    }


    /**
     * Sets the only non-device account to be default if it is not already.
     */
    public void maybeUpdateDefaultAccount() {
        final List<AccountWithDataSet> currentWritableAccounts = getWritableAccounts();
        if (currentWritableAccounts.size() == 1) {
            final AccountWithDataSet onlyAccount = currentWritableAccounts.get(0);
            if (!onlyAccount.isNullAccount()
                    && !onlyAccount.equals(mContactsPrefs.getDefaultAccount())) {
                mContactsPrefs.setDefaultAccount(onlyAccount);
            }
        }
    }

    @VisibleForTesting
    @VisibleForTesting
    String[] getWritableAccountTypeStrings() {
    String[] getWritableAccountTypeStrings() {
        final Set<String> types = Sets.newHashSet();
        final Set<String> types = Sets.newHashSet();