Added/using organization field in contacts

This commit is contained in:
Sylvain Berfini 2016-07-25 16:09:36 +02:00
parent 0da493a81e
commit 822478f457
8 changed files with 131 additions and 9 deletions

View file

@ -93,13 +93,21 @@
android:layout_gravity="center" android:layout_gravity="center"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content"/> android:layout_height="wrap_content"/>
<TextView
android:id="@+id/contactOrganization"
style="@style/font9"
android:singleLine="true"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TableLayout <TableLayout
android:id="@+id/controls" android:id="@+id/controls"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:stretchColumns="*" android:stretchColumns="*"
android:paddingTop="20dp"/> android:paddingTop="10dp"/>
</LinearLayout> </LinearLayout>

View file

@ -72,16 +72,31 @@
android:paddingLeft="5dp" android:paddingLeft="5dp"
android:paddingRight="5dp" /> android:paddingRight="5dp" />
<TextView <RelativeLayout
android:id="@+id/name"
android:lines="1"
style="@style/font6"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_toRightOf="@id/avatar_layout" android:layout_toRightOf="@id/avatar_layout"
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:layout_toLeftOf="@id/delete" android:layout_toLeftOf="@id/delete"
android:layout_marginLeft="10dp" /> android:layout_marginLeft="10dp">
<TextView
android:id="@+id/name"
android:lines="1"
style="@style/font6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"/>
<TextView
android:id="@+id/contactOrganization"
style="@style/font9"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
<ImageView <ImageView
android:id="@+id/friendStatus" android:id="@+id/friendStatus"

View file

@ -134,6 +134,26 @@
android:gravity="left" android:gravity="left"
android:paddingRight="5dp" android:paddingRight="5dp"
android:inputType="textPersonName|textCapWords"/> android:inputType="textPersonName|textCapWords"/>
<TextView
android:text="@string/contact_organization"
style="@style/font13"
android:textAllCaps="true"
android:paddingTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="@+id/contactOrganization"
android:textCursorDrawable="@null"
android:background="@drawable/resizable_textfield"
style="@style/font6"
android:contentDescription="@string/content_description_contact_organization"
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="left"
android:paddingRight="5dp"
android:inputType="textPersonName|textCapWords"/>
</LinearLayout> </LinearLayout>

View file

@ -107,6 +107,7 @@
<string name="phone_number">Phone number</string> <string name="phone_number">Phone number</string>
<string name="contact_first_name">First name</string> <string name="contact_first_name">First name</string>
<string name="contact_last_name">Last name</string> <string name="contact_last_name">Last name</string>
<string name="contact_organization">Organization</string>
<!-- Chat --> <!-- Chat -->
<string name="no_chat_history">No conversations</string> <string name="no_chat_history">No conversations</string>
@ -376,6 +377,7 @@
<string name="content_description_delete_selection">Delete selection</string> <string name="content_description_delete_selection">Delete selection</string>
<string name="content_description_contact_first_name">First name</string> <string name="content_description_contact_first_name">First name</string>
<string name="content_description_contact_last_name">Last name</string> <string name="content_description_contact_last_name">Last name</string>
<string name="content_description_contact_organization">Organization</string>
<string name="content_description_back_call">Back to call</string> <string name="content_description_back_call">Back to call</string>
<string name="content_description_send_file">Send a file</string> <string name="content_description_send_file">Send a file</string>
<string name="content_description_message">Message</string> <string name="content_description_message">Message</string>

View file

@ -38,6 +38,7 @@ import android.widget.TextView;
public class ContactDetailsFragment extends Fragment implements OnClickListener { public class ContactDetailsFragment extends Fragment implements OnClickListener {
private LinphoneContact contact; private LinphoneContact contact;
private ImageView editContact, deleteContact, back; private ImageView editContact, deleteContact, back;
private TextView organization;
private LayoutInflater inflater; private LayoutInflater inflater;
private View view; private View view;
private boolean displayChatAddressOnly = false; private boolean displayChatAddressOnly = false;
@ -75,6 +76,14 @@ public class ContactDetailsFragment extends Fragment implements OnClickListener
deleteContact = (ImageView) view.findViewById(R.id.deleteContact); deleteContact = (ImageView) view.findViewById(R.id.deleteContact);
deleteContact.setOnClickListener(this); deleteContact.setOnClickListener(this);
organization = (TextView) view.findViewById(R.id.contactOrganization);
String org = contact.getOrganization();
if (org != null && !org.isEmpty()) {
organization.setText(org);
} else {
organization.setVisibility(View.GONE);
}
back = (ImageView) view.findViewById(R.id.back); back = (ImageView) view.findViewById(R.id.back);
if(getResources().getBoolean(R.bool.isTablet)){ if(getResources().getBoolean(R.bool.isTablet)){

View file

@ -62,7 +62,7 @@ public class ContactEditorFragment extends Fragment {
private ImageView cancel, deleteContact, ok; private ImageView cancel, deleteContact, ok;
private ImageView addNumber, addSipAddress, contactPicture; private ImageView addNumber, addSipAddress, contactPicture;
private LinearLayout phoneNumbersSection, sipAddressesSection; private LinearLayout phoneNumbersSection, sipAddressesSection;
private EditText firstName, lastName; private EditText firstName, lastName, organization;
private LayoutInflater inflater; private LayoutInflater inflater;
private static final int ADD_PHOTO = 1337; private static final int ADD_PHOTO = 1337;
@ -148,6 +148,7 @@ public class ContactEditorFragment extends Fragment {
} }
contact.addOrUpdateNumberOrAddress(noa); contact.addOrUpdateNumberOrAddress(noa);
} }
contact.setOrganization(organization.getText().toString());
contact.save(); contact.save();
getFragmentManager().popBackStackImmediate(); getFragmentManager().popBackStackImmediate();
} }
@ -202,6 +203,11 @@ public class ContactEditorFragment extends Fragment {
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
} }
}); });
organization = (EditText) view.findViewById(R.id.contactOrganization);
if (!isNewContact) {
organization.setText(contact.getOrganization());
}
if (!isNewContact) { if (!isNewContact) {
String fn = contact.getFirstName(); String fn = contact.getFirstName();

View file

@ -485,7 +485,7 @@ public class ContactsListFragment extends Fragment implements OnClickListener, O
} }
} }
if(contact.isInLinphoneFriendList()){ if (contact.isInLinphoneFriendList()) {
linphoneFriend.setVisibility(View.VISIBLE); linphoneFriend.setVisibility(View.VISIBLE);
} else { } else {
linphoneFriend.setVisibility(View.GONE); linphoneFriend.setVisibility(View.GONE);
@ -499,6 +499,14 @@ public class ContactsListFragment extends Fragment implements OnClickListener, O
} else { } else {
icon.setImageResource(R.drawable.avatar); icon.setImageResource(R.drawable.avatar);
} }
TextView organization = (TextView) view.findViewById(R.id.contactOrganization);
String org = contact.getOrganization();
if (org != null && !org.isEmpty()) {
organization.setText(org);
} else {
organization.setVisibility(View.GONE);
}
if (isEditMode) { if (isEditMode) {
delete.setVisibility(View.VISIBLE); delete.setVisibility(View.VISIBLE);

View file

@ -49,7 +49,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
private static final long serialVersionUID = 9015568163905205244L; private static final long serialVersionUID = 9015568163905205244L;
private transient LinphoneFriend friend; private transient LinphoneFriend friend;
private String fullName, firstName, lastName, androidId, androidRawId, androidTagId; private String fullName, firstName, lastName, androidId, androidRawId, androidTagId, organization;
private transient Uri photoUri, thumbnailUri; private transient Uri photoUri, thumbnailUri;
private List<LinphoneNumberOrAddress> addresses; private List<LinphoneNumberOrAddress> addresses;
private transient ArrayList<ContentProviderOperation> changesToCommit; private transient ArrayList<ContentProviderOperation> changesToCommit;
@ -127,6 +127,41 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
return lastName; return lastName;
} }
public String getOrganization() {
return organization;
}
public void setOrganization(String org) {
if (isAndroidContact()) {
if (androidRawId != null) {
String select = ContactsContract.Data.CONTACT_ID + "=? AND " + ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE + "'";
String[] args = new String[]{ getAndroidId() };
if (organization != null) {
changesToCommit.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
.withSelection(select, args)
.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE)
.withValue(ContactsContract.CommonDataKinds.Organization.COMPANY, org)
.build());
} else {
changesToCommit.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
.withValue(ContactsContract.Data.RAW_CONTACT_ID, androidRawId)
.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE)
.withValue(ContactsContract.CommonDataKinds.Organization.COMPANY, org)
.build());
}
} else {
changesToCommit.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE)
.withValue(ContactsContract.CommonDataKinds.Organization.COMPANY, org)
.build());
}
}
organization = org;
}
public boolean hasPhoto() { public boolean hasPhoto() {
return photoUri != null; return photoUri != null;
} }
@ -391,6 +426,9 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
for (String phone : friend.getPhoneNumbers()) { for (String phone : friend.getPhoneNumbers()) {
friend.removePhoneNumber(phone); friend.removePhoneNumber(phone);
} }
if (organization != null && !organization.isEmpty()) {
friend.setOrganization(organization);
}
for (LinphoneNumberOrAddress noa : addresses) { for (LinphoneNumberOrAddress noa : addresses) {
if (noa.isSIPAddress()) { if (noa.isSIPAddress()) {
try { try {
@ -465,6 +503,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
getContactNames(); getContactNames();
setThumbnailUri(getContactThumbnailPictureUri()); setThumbnailUri(getContactThumbnailPictureUri());
setPhotoUri(getContactPictureUri()); setPhotoUri(getContactPictureUri());
getNativeContactOrganization();
if (isLinphoneFriend()) { if (isLinphoneFriend()) {
hasSipAddress = friend.getAddress() != null; hasSipAddress = friend.getAddress() != null;
@ -476,6 +515,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
thumbnailUri = null; thumbnailUri = null;
photoUri = null; photoUri = null;
hasSipAddress = friend.getAddress() != null; hasSipAddress = friend.getAddress() != null;
organization = friend.getOrganization();
} }
} }
@ -574,6 +614,20 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
} }
} }
private void getNativeContactOrganization() {
ContentResolver resolver = ContactsManager.getInstance().getContentResolver();
String[] proj = new String[]{ ContactsContract.CommonDataKinds.Organization.COMPANY };
String select = ContactsContract.Data.CONTACT_ID + "=? AND " + ContactsContract.Data.MIMETYPE + "=?";
String[] args = new String[]{ getAndroidId(), ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE };
Cursor c = resolver.query(ContactsContract.Data.CONTENT_URI, proj, select, args, null);
if (c != null) {
if (c.moveToFirst()) {
organization = c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.Organization.COMPANY));
}
c.close();
}
}
private String findRawContactID() { private String findRawContactID() {
ContentResolver resolver = ContactsManager.getInstance().getContentResolver(); ContentResolver resolver = ContactsManager.getInstance().getContentResolver();
String result = null; String result = null;