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

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

Show "local only" account name for me profile

Bug 24988734

Change-Id: Ief827757e148d240ec74b46c1dfbb11c1c68a18c
parent 9488a766
Loading
Loading
Loading
Loading
+38 −4
Original line number Diff line number Diff line
@@ -781,8 +781,12 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O
        }

        // Get the account information for the primary raw contact delta
        final Pair<String,String> accountInfo = EditorUiUtils.getAccountInfo(getContext(),
                mIsUserProfile, mPrimaryRawContactDelta.getAccountName(),
        final Pair<String,String> accountInfo = mIsUserProfile
                ? EditorUiUtils.getLocalAccountInfo(getContext(),
                        mPrimaryRawContactDelta.getAccountName(),
                        mPrimaryRawContactDelta.getAccountType(mAccountTypeManager))
                : EditorUiUtils.getAccountInfo(getContext(),
                        mPrimaryRawContactDelta.getAccountName(),
                        mPrimaryRawContactDelta.getAccountType(mAccountTypeManager));

        // The account header and selector show the same information so both shouldn't be visible
@@ -800,13 +804,40 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O
            mAccountHeaderContainer.setVisibility(View.GONE);
            mAccountSelectorContainer.setVisibility(View.GONE);
            addRawContactAccountSelector(rawContactDeltas);
        } else {
            if (mIsUserProfile) {
                addLocalAccountHeader(accountInfo);
            } else {
                addAccountHeader(accountInfo);
            }
            mAccountSelectorContainer.setVisibility(View.GONE);
        }
    }

    private void addLocalAccountHeader(Pair<String,String> accountInfo) {
        // Set the account name
        final String accountName = TextUtils.isEmpty(accountInfo.first)
                ? accountInfo.second : accountInfo.first;
        mAccountHeaderName.setVisibility(View.VISIBLE);
        mAccountHeaderName.setText(accountName);

        // Set the account type
        final String selectorTitle = getResources().getString(
                R.string.compact_editor_account_selector_title);
        mAccountHeaderType.setText(selectorTitle);

        // Set the icon
        final AccountType primaryAccountType =
                mPrimaryRawContactDelta.getRawContactAccountType(getContext());
        mAccountHeaderIcon.setImageDrawable(primaryAccountType.getDisplayIcon(getContext()));

        // Set the content description
        mAccountHeaderContainer.setContentDescription(
                EditorUiUtils.getAccountInfoContentDescription(accountName, selectorTitle));
    }

    private void addAccountHeader(Pair<String,String> accountInfo) {
        // Set the account name
        if (TextUtils.isEmpty(accountInfo.first)) {
            // Hide this view so the other text view will be centered vertically
            mAccountHeaderName.setVisibility(View.GONE);
@@ -815,14 +846,17 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O
            mAccountHeaderName.setText(accountInfo.first);
        }

        // Set the account type
        final String selectorTitle = getResources().getString(
                R.string.compact_editor_account_selector_title);
        mAccountHeaderType.setText(selectorTitle);

        // Set the icon
        final AccountType primaryAccountType = mPrimaryRawContactDelta.getRawContactAccountType(
                getContext());
        mAccountHeaderIcon.setImageDrawable(primaryAccountType.getDisplayIcon(getContext()));

        // Set the content description
        mAccountHeaderContainer.setContentDescription(
                EditorUiUtils.getAccountInfoContentDescription(
                        accountInfo.first, selectorTitle));
+17 −16
Original line number Diff line number Diff line
@@ -112,14 +112,10 @@ public class EditorUiUtils {
    }

    /**
     * Returns the account name and account type labels to display for the given account type.
     *
     * @param isProfile True to get the labels for the "me" profile or a phone only (local) contact
     *         and false otherwise.
     * Returns the account name and account type labels to display for local accounts.
     */
    public static Pair<String,String> getAccountInfo(Context context,
            boolean isProfile, String accountName, AccountType accountType) {
        if (isProfile) {
    public static Pair<String,String> getLocalAccountInfo(Context context,
            String accountName, AccountType accountType) {
        if (TextUtils.isEmpty(accountName)) {
            return new Pair<>(
                    /* accountName =*/ null,
@@ -131,6 +127,11 @@ public class EditorUiUtils {
                        accountType.getDisplayLabel(context)));
    }

    /**
     * Returns the account name and account type labels to display for the given account type.
     */
    public static Pair<String,String> getAccountInfo(Context context, String accountName,
            AccountType accountType) {
        CharSequence accountTypeDisplayLabel = accountType.getDisplayLabel(context);
        if (TextUtils.isEmpty(accountTypeDisplayLabel)) {
            accountTypeDisplayLabel = context.getString(R.string.account_phone);
@@ -167,7 +168,7 @@ public class EditorUiUtils {
            builder.append(accountType).append('\n');
        }
        if (!TextUtils.isEmpty(accountName)) {
            builder.append(accountName).append('\n');
            builder.append(accountName);
        }
        return builder.toString();
    }
+3 −2
Original line number Diff line number Diff line
@@ -189,8 +189,9 @@ public class RawContactEditorView extends BaseRawContactEditorView {
        mRawContactId = state.getRawContactId();

        // Fill in the account info
        final Pair<String,String> accountInfo = EditorUiUtils.getAccountInfo(getContext(),
                isProfile, state.getAccountName(), type);
        final Pair<String,String> accountInfo = isProfile
                ? EditorUiUtils.getLocalAccountInfo(getContext(), state.getAccountName(), type)
                : EditorUiUtils.getAccountInfo(getContext(), state.getAccountName(), type);
        if (accountInfo.first == null) {
            // Hide this view so the other text view will be centered vertically
            mAccountHeaderNameTextView.setVisibility(View.GONE);
+3 −2
Original line number Diff line number Diff line
@@ -115,8 +115,9 @@ public class RawContactReadOnlyEditorView extends BaseRawContactEditorView
        mAccountType = state.getAccountType();
        mDataSet = state.getDataSet();

        final Pair<String,String> accountInfo = EditorUiUtils.getAccountInfo(getContext(),
                isProfile, state.getAccountName(), type);
        final Pair<String,String> accountInfo = isProfile
                ? EditorUiUtils.getLocalAccountInfo(getContext(), state.getAccountName(), type)
                : EditorUiUtils.getAccountInfo(getContext(), state.getAccountName(), type);
        if (accountInfo.first == null) {
            // Hide this view so the other text view will be centered vertically
            mAccountHeaderNameTextView.setVisibility(View.GONE);
+7 −7
Original line number Diff line number Diff line
@@ -68,7 +68,7 @@ public class EditorUiUtilsTest extends AndroidTestCase {
    }

    public void testGetProfileAccountInfo_AccountName() {
        final Pair pair = EditorUiUtils.getAccountInfo(getContext(), /* isProfile =*/ true,
        final Pair pair = EditorUiUtils.getLocalAccountInfo(getContext(),
                ACCOUNT_NAME, new MockAccountType(DISPLAY_LABEL));

        assertNotNull(pair);
@@ -78,7 +78,7 @@ public class EditorUiUtilsTest extends AndroidTestCase {
    }

    public void testGetProfileAccountInfo_NoAccountName() {
        final Pair pair = EditorUiUtils.getAccountInfo(getContext(), /* isProfile =*/ true,
        final Pair pair = EditorUiUtils.getLocalAccountInfo(getContext(),
                /* accountName =*/ null, new MockAccountType(DISPLAY_LABEL));

        assertNotNull(pair);
@@ -88,7 +88,7 @@ public class EditorUiUtilsTest extends AndroidTestCase {
    }

    public void testGetAccountInfo_AccountName_DisplayLabel() {
        final Pair pair = EditorUiUtils.getAccountInfo(getContext(), /* isProfile =*/ false,
        final Pair pair = EditorUiUtils.getAccountInfo(getContext(),
                ACCOUNT_NAME, new MockAccountType(DISPLAY_LABEL));

        assertNotNull(pair);
@@ -101,7 +101,7 @@ public class EditorUiUtilsTest extends AndroidTestCase {
    public void testGetAccountInfo_AccountName_DisplayLabel_GoogleAccountType() {
        final AccountType accountType = new MockAccountType(GOOGLE_DISPLAY_LABEL);
        accountType.accountType = GoogleAccountType.ACCOUNT_TYPE;
        final Pair pair = EditorUiUtils.getAccountInfo(getContext(), /* isProfile =*/ false,
        final Pair pair = EditorUiUtils.getAccountInfo(getContext(),
                GOOGLE_ACCOUNT_NAME, accountType);

        assertNotNull(pair);
@@ -113,7 +113,7 @@ public class EditorUiUtilsTest extends AndroidTestCase {
    }

    public void testGetAccountInfo_AccountName_NoDisplayLabel() {
        final Pair pair = EditorUiUtils.getAccountInfo(getContext(), /* isProfile =*/ false,
        final Pair pair = EditorUiUtils.getAccountInfo(getContext(),
                ACCOUNT_NAME, new MockAccountType(/* displayLabel =*/ null));

        assertNotNull(pair);
@@ -126,7 +126,7 @@ public class EditorUiUtilsTest extends AndroidTestCase {
    }

    public void testGetAccountInfo_NoAccountName_DisplayLabel() {
        final Pair pair = EditorUiUtils.getAccountInfo(getContext(), /* isProfile =*/ false,
        final Pair pair = EditorUiUtils.getAccountInfo(getContext(),
                /* accountName =*/ null, new MockAccountType(DISPLAY_LABEL));

        assertNotNull(pair);
@@ -136,7 +136,7 @@ public class EditorUiUtilsTest extends AndroidTestCase {
    }

    public void testGetAccountInfo_NoAccountName_NoDisplayLabel() {
        final Pair pair = EditorUiUtils.getAccountInfo(getContext(), /* isProfile =*/ false,
        final Pair pair = EditorUiUtils.getAccountInfo(getContext(),
                /* accountName =*/ null, new MockAccountType(/* displayLabel =*/ null));

        assertNotNull(pair);