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

Commit 72417d9e authored by Gyanesh Mittal's avatar Gyanesh Mittal
Browse files

Add department field in the Contacts app

Fix: 173429253
Test: manual testing
Change-Id: I1072ae788485d10ab996cc73fd391545c383cf49
parent 02595a68
Loading
Loading
Loading
Loading
+21 −3
Original line number Diff line number Diff line
@@ -452,9 +452,23 @@
    <!-- Menu item for invoking contextual Help & Feedback [CHAR LIMIT=64] -->
    <string name="menu_help">Help &amp; feedback</string>

    <!-- Text used to show a organization that has both a company and title. This is used in the Detail-View
    of a Contact. This is mostly about the formatting of the two elements, so it should be kept small [CHAR LIMIT=79] -->
    <string name="organization_company_and_title"><xliff:g id="company" example="Technical Program Manager">%2$s</xliff:g>, <xliff:g id="company" example="Google Inc.">%1$s</xliff:g></string>
    <!-- String used to build an organization entry containing any of the 2 fields <Company>,
         <Department> or <Job Title>, example: Google • Developer. [CHAR LIMIT=NONE] -->
    <string name="organization_entry_two_field">
        <xliff:g id="first" example="Google">%1$s</xliff:g>

         <xliff:g id="second" example="Developer">%2$s</xliff:g>
    </string>

    <!-- String used to build an organization entry containing all the field <Company>,
       <Department> or <Job Title>, example: Google • Department • Developer. [CHAR LIMIT=NONE] -->
    <string name="organization_entry_all_field">
        <xliff:g id="company" example="Google">%1$s</xliff:g>

         <xliff:g id="department" example="People">%2$s</xliff:g>

         <xliff:g id="title" example="Developer">%3$s</xliff:g>
    </string>

    <!-- Title shown for the phone number when the number tries to call on a device that it not a phone [CHAR LIMIT=30] -->
    <string name="non_phone_caption">Phone number</string>
@@ -923,6 +937,10 @@
    <!-- Hint text for the organization name when editing a business/work contact. [CHAR LIMIT=64] -->
    <string name="ghostData_company">Company</string>

    <!-- Hint text for the organization department when editing a business/work contact.
        [CHAR LIMIT=64] -->
    <string name="ghostData_department">Department</string>

    <!-- Hint text for the organization title when editing a business/work contact. [CHAR LIMIT=64] -->
    <string name="ghostData_title">Title</string>

+45 −29
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import com.android.contacts.model.dataitem.OrganizationDataItem;
import com.android.contacts.preference.ContactsPreferences;
import com.android.contacts.util.MoreMath;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;

import java.util.List;

@@ -111,8 +112,8 @@ public class ContactDisplayUtils {
    }

    /**
     * Returns the organization of the contact. If several organizations are given,
     * the first one is used. Returns null if not applicable.
     * Returns the organization of the contact. If several organizations are given, the first one
     * is used. Returns null if not applicable.
     */
    public static String getCompany(Context context, Contact contactData) {
        final boolean displayNameIsOrganization = contactData.getDisplayNameSource()
@@ -120,33 +121,48 @@ public class ContactDisplayUtils {
        for (RawContact rawContact : contactData.getRawContacts()) {
            for (DataItem dataItem : Iterables.filter(
                rawContact.getDataItems(), OrganizationDataItem.class)) {
                OrganizationDataItem organization = (OrganizationDataItem) dataItem;
                final String company = organization.getCompany();
                final String title = organization.getTitle();
                final String combined;
                // We need to show company and title in a combined string. However, if the
                // DisplayName is already the organization, it mirrors company or (if company
                // is empty title). Make sure we don't show what's already shown as DisplayName
                if (TextUtils.isEmpty(company)) {
                    combined = displayNameIsOrganization ? null : title;
                } else {
                    if (TextUtils.isEmpty(title)) {
                        combined = displayNameIsOrganization ? null : company;
                    } else {
                        if (displayNameIsOrganization) {
                            combined = title;
                        } else {
                            combined = context.getString(
                                    R.string.organization_company_and_title,
                                    company, title);
                String organization = getFormattedCompanyString(context,
                    (OrganizationDataItem) dataItem,
                    displayNameIsOrganization);
                if (!TextUtils.isEmpty(organization)) {
                    return organization;
                }
            }
        }
        return null;
    }

                if (!TextUtils.isEmpty(combined)) {
                    return combined;
    /**
     * Return the formatted organization string from the given OrganizationDataItem
     *
     * This will combine the company, department and title in one formatted string. However, if the
     * DisplayName is already the organization (company or title) and resulted combined string
     * include either company or title only then we don't need to display the organization string,
     * as it will already be shown in the DisplayName.
     */
    public static String getFormattedCompanyString(
            Context context, OrganizationDataItem organization, boolean displayNameIsOrganization) {
        List<String> text = Lists.newArrayList();
        if (!TextUtils.isEmpty(organization.getCompany())) {
            text.add(organization.getCompany());
        }
        if (!TextUtils.isEmpty(organization.getDepartment())) {
            text.add(organization.getDepartment());
        }
        if (!TextUtils.isEmpty(organization.getTitle())) {
            text.add(organization.getTitle());
        }
        if (text.size() == 3) {
            return context.getString(
                R.string.organization_entry_all_field, text.get(0), text.get(1),
                text.get(2));
        }
        if (text.size() == 2) {
            return context.getString(
                R.string.organization_entry_two_field, text.get(0), text.get(1));
        }
        if (text.size() == 1 && !displayNameIsOrganization) {
            return text.get(0);
        }
        return null;
    }
+23 −16
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import android.provider.ContactsContract.CommonDataKinds.StructuredName;
import android.provider.ContactsContract.CommonDataKinds.StructuredPostal;
import android.provider.ContactsContract.CommonDataKinds.Website;
import android.provider.ContactsContract.Data;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.view.inputmethod.EditorInfo;
@@ -368,6 +369,8 @@ public abstract class BaseAccountType extends AccountType {
        kind.fieldList = Lists.newArrayList();
        kind.fieldList.add(new EditField(Organization.COMPANY, R.string.ghostData_company,
                FLAGS_GENERIC_NAME));
        kind.fieldList.add(new EditField(Organization.DEPARTMENT, R.string.ghostData_department,
                FLAGS_GENERIC_NAME));
        kind.fieldList.add(new EditField(Organization.TITLE, R.string.ghostData_title,
                FLAGS_GENERIC_NAME));

@@ -629,22 +632,24 @@ public abstract class BaseAccountType extends AccountType {
        }
    }

    public static final StringInflater ORGANIZATION_BODY_INFLATER = new StringInflater() {
        @Override
        public CharSequence inflateUsing(Context context, ContentValues values) {
            final CharSequence companyValue = values.containsKey(Organization.COMPANY) ?
                    values.getAsString(Organization.COMPANY) : null;
            final CharSequence titleValue = values.containsKey(Organization.TITLE) ?
                    values.getAsString(Organization.TITLE) : null;

            if (companyValue != null && titleValue != null) {
                return companyValue +  ": " + titleValue;
            } else if (companyValue == null) {
                return titleValue;
            } else {
                return companyValue;
    public static final StringInflater ORGANIZATION_BODY_INFLATER =
      (context, values) -> {
        List<String> text = Lists.newArrayList();

        if (values.containsKey(Organization.COMPANY)) {
          text.add(values.getAsString(Organization.COMPANY));
        }
        if (values.containsKey(Organization.DEPARTMENT)) {
          text.add(values.getAsString(Organization.DEPARTMENT));
        }
        if (values.containsKey(Organization.TITLE)) {
          text.add(values.getAsString(Organization.TITLE));
        }

        if (!text.isEmpty()) {
          return TextUtils.join(": ", text);
        }
        return null;
      };

    @Override
@@ -1233,6 +1238,8 @@ public abstract class BaseAccountType extends AccountType {

            kind.fieldList.add(new EditField(Organization.COMPANY, R.string.ghostData_company,
                    FLAGS_GENERIC_NAME));
            kind.fieldList.add(new EditField(Organization.DEPARTMENT, R.string.ghostData_department,
                    FLAGS_GENERIC_NAME));
            kind.fieldList.add(new EditField(Organization.TITLE, R.string.ghostData_title,
                    FLAGS_GENERIC_NAME));

+2 −0
Original line number Diff line number Diff line
@@ -246,6 +246,8 @@ public class ExchangeAccountType extends BaseAccountType {
        kind.fieldList = Lists.newArrayList();
        kind.fieldList.add(new EditField(Organization.COMPANY, R.string.ghostData_company,
                FLAGS_GENERIC_NAME));
        kind.fieldList.add(new EditField(Organization.DEPARTMENT, R.string.ghostData_department,
                FLAGS_GENERIC_NAME));
        kind.fieldList.add(new EditField(Organization.TITLE, R.string.ghostData_title,
                FLAGS_GENERIC_NAME));

+3 −3
Original line number Diff line number Diff line
@@ -1431,10 +1431,10 @@ public class QuickContactActivity extends ContactsActivity {
        } else if (dataItem instanceof OrganizationDataItem) {
            final OrganizationDataItem organization = (OrganizationDataItem) dataItem;
            header = res.getString(R.string.header_organization_entry);
            subHeader = organization.getCompany();
            entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header,
                dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary());
            text = organization.getTitle();
            text = ContactDisplayUtils
                .getFormattedCompanyString(context, (OrganizationDataItem) dataItem, false);
        } else if (dataItem instanceof NicknameDataItem) {
            final NicknameDataItem nickname = (NicknameDataItem) dataItem;
            // Build nickname entries