Fix problems in contacts and remove linphone tag
This commit is contained in:
parent
bd0c2df61e
commit
3706b6ebe2
6 changed files with 152 additions and 127 deletions
|
@ -39,7 +39,7 @@ import java.util.List;
|
||||||
public class ContactsManager {
|
public class ContactsManager {
|
||||||
private static ContactsManager instance;
|
private static ContactsManager instance;
|
||||||
private List<Contact> contactList, sipContactList;
|
private List<Contact> contactList, sipContactList;
|
||||||
private Cursor contactCursor, sipContactCursor, friendContactCursor;
|
private Cursor contactCursor, sipContactCursor;
|
||||||
private Account mAccount;
|
private Account mAccount;
|
||||||
private boolean preferLinphoneContacts = false, isContactPresenceDisabled = true;
|
private boolean preferLinphoneContacts = false, isContactPresenceDisabled = true;
|
||||||
private ContentResolver contentResolver;
|
private ContentResolver contentResolver;
|
||||||
|
@ -65,10 +65,7 @@ public class ContactsManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Cursor getSIPContactsCursor() {
|
public Cursor getSIPContactsCursor() {
|
||||||
if (sipContactCursor.getCount() > 0)
|
return sipContactCursor;
|
||||||
return sipContactCursor;
|
|
||||||
else
|
|
||||||
return friendContactCursor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLinphoneContactsPrefered(boolean isPrefered) {
|
public void setLinphoneContactsPrefered(boolean isPrefered) {
|
||||||
|
@ -103,6 +100,7 @@ public class ContactsManager {
|
||||||
return displayName;
|
return displayName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Contacts
|
||||||
public void createNewContact(ArrayList<ContentProviderOperation> ops, String firstName, String lastName){
|
public void createNewContact(ArrayList<ContentProviderOperation> ops, String firstName, String lastName){
|
||||||
int contactID = 0;
|
int contactID = 0;
|
||||||
|
|
||||||
|
@ -147,17 +145,20 @@ public class ContactsManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
LinphoneFriend friend = LinphoneCoreFactory.instance().createLinphoneFriend(sipUri);
|
LinphoneFriend friend = LinphoneCoreFactory.instance().createLinphoneFriend(sipUri);
|
||||||
friend.edit();
|
if(friend != null) {
|
||||||
friend.setRefKey(contact.getID());
|
friend.edit();
|
||||||
friend.done();
|
friend.setRefKey(contact.getID());
|
||||||
try {
|
friend.done();
|
||||||
LinphoneManager.getLc().addFriend(friend);
|
try {
|
||||||
return true;
|
LinphoneManager.getLc().addFriend(friend);
|
||||||
} catch (LinphoneCoreException e) {
|
return true;
|
||||||
e.printStackTrace();
|
} catch (LinphoneCoreException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateFriend(String oldSipUri, String newSipUri) {
|
public void updateFriend(String oldSipUri, String newSipUri) {
|
||||||
|
@ -239,13 +240,42 @@ public class ContactsManager {
|
||||||
}
|
}
|
||||||
//End linphone Friend
|
//End linphone Friend
|
||||||
|
|
||||||
|
public boolean removeContactTagIsNeeded(Contact contact){
|
||||||
|
contact.refresh(contentResolver);
|
||||||
|
boolean onlyNumbers = true;
|
||||||
|
for(String address: contact.getNumbersOrAddresses()){
|
||||||
|
if(LinphoneUtils.isSipAddress(address)){
|
||||||
|
onlyNumbers = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return onlyNumbers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeLinphoneContactTag(Contact contact){
|
||||||
|
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
|
||||||
|
String select = ContactsContract.RawContacts._ID + " = ?";
|
||||||
|
String[] args = new String[] { findRawLinphoneContactID(contact.getID()) };
|
||||||
|
|
||||||
|
|
||||||
|
ops.add(ContentProviderOperation.newDelete(ContactsContract.RawContacts.CONTENT_URI)
|
||||||
|
.withSelection(select, args)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
contentResolver.applyBatch(ContactsContract.AUTHORITY, ops);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.w(e.getMessage() + ":" + e.getStackTrace());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Contact findContactWithAddress(LinphoneAddress address){
|
public Contact findContactWithAddress(LinphoneAddress address){
|
||||||
for(Contact contact : contactList){
|
for(Contact contact : contactList){
|
||||||
if(contact.getNumbersOrAddresses().contains(address.asStringUriOnly()) || contact.getNumbersOrAddresses().contains(address.getUserName())){
|
if(contact.getNumbersOrAddresses().contains(address.asStringUriOnly()) || contact.getNumbersOrAddresses().contains(address.getUserName())){
|
||||||
return contact;
|
return contact;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,7 +300,7 @@ public class ContactsManager {
|
||||||
public boolean isContactHasAddress(Contact contact, String address){
|
public boolean isContactHasAddress(Contact contact, String address){
|
||||||
if(contact != null) {
|
if(contact != null) {
|
||||||
contact.refresh(contentResolver);
|
contact.refresh(contentResolver);
|
||||||
if (contact.getNumbersOrAddresses().contains("sip:" + address)) {
|
if (contact.getNumbersOrAddresses().contains("sip:" + address)) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
@ -279,6 +309,41 @@ public class ContactsManager {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String findRawContactID(ContentResolver cr, String contactID) {
|
||||||
|
Cursor c = cr.query(ContactsContract.RawContacts.CONTENT_URI,
|
||||||
|
new String[]{ContactsContract.RawContacts._ID},
|
||||||
|
ContactsContract.RawContacts.CONTACT_ID + "=?",
|
||||||
|
new String[]{contactID}, null);
|
||||||
|
if (c != null) {
|
||||||
|
String result = null;
|
||||||
|
if (c.moveToFirst()) {
|
||||||
|
result = c.getString(c.getColumnIndex(ContactsContract.RawContacts._ID));
|
||||||
|
}
|
||||||
|
|
||||||
|
c.close();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String findRawLinphoneContactID(String contactID) {
|
||||||
|
String result = null;
|
||||||
|
String[] projection = { ContactsContract.RawContacts._ID };
|
||||||
|
|
||||||
|
String selection = ContactsContract.RawContacts.CONTACT_ID + "=? AND "
|
||||||
|
+ ContactsContract.RawContacts.ACCOUNT_TYPE + "=? ";
|
||||||
|
|
||||||
|
Cursor c = contentResolver.query(ContactsContract.RawContacts.CONTENT_URI, projection,
|
||||||
|
selection, new String[]{contactID, "org.linphone"}, null);
|
||||||
|
if (c != null) {
|
||||||
|
if (c.moveToFirst()) {
|
||||||
|
result = c.getString(c.getColumnIndex(ContactsContract.RawContacts._ID));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c.close();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
//Migrate old IM contacts into SIP addresses or linphoneFriends
|
//Migrate old IM contacts into SIP addresses or linphoneFriends
|
||||||
public void migrateContacts() {
|
public void migrateContacts() {
|
||||||
Cursor oldContacts = Compatibility.getImContactsCursor(contentResolver);
|
Cursor oldContacts = Compatibility.getImContactsCursor(contentResolver);
|
||||||
|
@ -288,12 +353,13 @@ public class ContactsManager {
|
||||||
for (int i = 0; i < oldContacts.getCount(); i++) {
|
for (int i = 0; i < oldContacts.getCount(); i++) {
|
||||||
Contact contact = Compatibility.getContact(contentResolver, oldContacts, i);
|
Contact contact = Compatibility.getContact(contentResolver, oldContacts, i);
|
||||||
for (String address : Compatibility.extractContactImAddresses(contact.getID(), contentResolver)) {
|
for (String address : Compatibility.extractContactImAddresses(contact.getID(), contentResolver)) {
|
||||||
|
|
||||||
if (LinphoneUtils.isSipAddress(address)) {
|
if (LinphoneUtils.isSipAddress(address)) {
|
||||||
if (address.startsWith("sip:")) {
|
if (address.startsWith("sip:")) {
|
||||||
address = address.substring(4);
|
address = address.substring(4);
|
||||||
}
|
}
|
||||||
Compatibility.addSipAddressToContact(context, ops, address, findRawContactID(contentResolver,contact.getID()));
|
|
||||||
|
//Add new sip address
|
||||||
|
Compatibility.addSipAddressToContact(context, ops, address, findRawContactID(contentResolver, contact.getID()));
|
||||||
try {
|
try {
|
||||||
contentResolver.applyBatch(ContactsContract.AUTHORITY, ops);
|
contentResolver.applyBatch(ContactsContract.AUTHORITY, ops);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -302,42 +368,39 @@ public class ContactsManager {
|
||||||
|
|
||||||
ops.clear();
|
ops.clear();
|
||||||
|
|
||||||
if(isContactHasAddress(contact,address)){
|
contact.refresh(contentResolver);
|
||||||
|
|
||||||
|
//If address sip is correctly add, remove the im address
|
||||||
|
if(contact.getNumbersOrAddresses().contains(address)){
|
||||||
Compatibility.deleteImAddressFromContact(ops, address, contact.getID());
|
Compatibility.deleteImAddressFromContact(ops, address, contact.getID());
|
||||||
try {
|
try {
|
||||||
contentResolver.applyBatch(ContactsContract.AUTHORITY, ops);
|
contentResolver.applyBatch(ContactsContract.AUTHORITY, ops);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
ops.clear();
|
ops.clear();
|
||||||
} else {
|
} else {
|
||||||
if (!address.startsWith("sip:")) {
|
//Add linphone friend instead
|
||||||
address = "sip:" + address;
|
if(createNewFriend(contact, address)) {
|
||||||
|
contact.refresh(contentResolver);
|
||||||
|
|
||||||
|
//Remove IM address
|
||||||
|
Compatibility.deleteImAddressFromContact(ops, address, contact.getID());
|
||||||
|
try {
|
||||||
|
contentResolver.applyBatch(ContactsContract.AUTHORITY, ops);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
createNewFriend(contact, address);
|
|
||||||
|
|
||||||
contact.refresh(contentResolver);
|
|
||||||
|
|
||||||
if (address.startsWith("sip:")) {
|
|
||||||
address = address.substring(4);
|
|
||||||
}
|
|
||||||
Compatibility.deleteImAddressFromContact(ops, address, contact.getID());
|
|
||||||
try {
|
|
||||||
contentResolver.applyBatch(ContactsContract.AUTHORITY, ops);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
|
|
||||||
}
|
|
||||||
ops.clear();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ops.clear();
|
||||||
}
|
}
|
||||||
ops.clear();
|
|
||||||
contact.refresh(contentResolver);
|
|
||||||
}
|
}
|
||||||
|
oldContacts.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void prepareContactsInBackground() {
|
public synchronized void prepareContactsInBackground() {
|
||||||
|
@ -377,6 +440,11 @@ public class ContactsManager {
|
||||||
if (contact == null)
|
if (contact == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
//Remove linphone contact tag if the contact has no sip address
|
||||||
|
if(removeContactTagIsNeeded(contact) && isContactHasLinphoneTag(contact,contentResolver)){
|
||||||
|
removeLinphoneContactTag(contact);
|
||||||
|
}
|
||||||
|
|
||||||
for (Contact c : sipContactList) {
|
for (Contact c : sipContactList) {
|
||||||
if (c != null && c.getID().equals(contact.getID())) {
|
if (c != null && c.getID().equals(contact.getID())) {
|
||||||
contact = c;
|
contact = c;
|
||||||
|
@ -444,21 +512,4 @@ public class ContactsManager {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String findRawContactID(ContentResolver cr, String contactID) {
|
|
||||||
Cursor c = cr.query(ContactsContract.RawContacts.CONTENT_URI,
|
|
||||||
new String[]{ContactsContract.RawContacts._ID},
|
|
||||||
ContactsContract.RawContacts.CONTACT_ID + "=?",
|
|
||||||
new String[]{contactID}, null);
|
|
||||||
if (c != null) {
|
|
||||||
String result = null;
|
|
||||||
if (c.moveToFirst()) {
|
|
||||||
result = c.getString(c.getColumnIndex(ContactsContract.RawContacts._ID));
|
|
||||||
}
|
|
||||||
|
|
||||||
c.close();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.linphone.compatibility.Compatibility;
|
import org.linphone.compatibility.Compatibility;
|
||||||
import org.linphone.mediastream.Version;
|
import org.linphone.mediastream.Version;
|
||||||
import org.linphone.mediastream.Log;
|
|
||||||
import org.linphone.ui.AvatarWithShadow;
|
import org.linphone.ui.AvatarWithShadow;
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.ContentProviderOperation;
|
import android.content.ContentProviderOperation;
|
||||||
|
@ -14,7 +13,6 @@ import android.database.Cursor;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.provider.ContactsContract;
|
import android.provider.ContactsContract;
|
||||||
import android.provider.ContactsContract.RawContacts;
|
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.InputType;
|
import android.text.InputType;
|
||||||
|
@ -102,7 +100,7 @@ public class EditContactFragment extends Fragment {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
getActivity().getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
|
getActivity().getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
|
||||||
checkSipAddress();
|
addLinphoneFriendIfNeeded();
|
||||||
contactsManager.prepareContactsInBackground();
|
contactsManager.prepareContactsInBackground();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -360,39 +358,6 @@ public class EditContactFragment extends Fragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String findRawContactID(String contactID) {
|
|
||||||
Cursor c = getActivity().getContentResolver().query(RawContacts.CONTENT_URI,
|
|
||||||
new String[]{RawContacts._ID},RawContacts.CONTACT_ID + "=?",
|
|
||||||
new String[]{contactID}, null);
|
|
||||||
if (c != null) {
|
|
||||||
String result = null;
|
|
||||||
if (c.moveToFirst()) {
|
|
||||||
result = c.getString(c.getColumnIndex(RawContacts._ID));
|
|
||||||
}
|
|
||||||
c.close();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String findRawLinphoneContactID(String contactID) {
|
|
||||||
String result = null;
|
|
||||||
String[] projection = { RawContacts._ID };
|
|
||||||
|
|
||||||
String selection = RawContacts.CONTACT_ID + "=? AND "
|
|
||||||
+ RawContacts.ACCOUNT_TYPE + "=? ";
|
|
||||||
|
|
||||||
Cursor c = getActivity().getContentResolver().query(RawContacts.CONTENT_URI, projection,
|
|
||||||
selection, new String[]{contactID, getString(R.string.sync_account_type)}, null);
|
|
||||||
if (c != null) {
|
|
||||||
if (c.moveToFirst()) {
|
|
||||||
result = c.getString(c.getColumnIndex(ContactsContract.RawContacts._ID));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
c.close();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String findContactFirstName(String contactID) {
|
private String findContactFirstName(String contactID) {
|
||||||
Cursor c = getActivity().getContentResolver().query(ContactsContract.Data.CONTENT_URI,
|
Cursor c = getActivity().getContentResolver().query(ContactsContract.Data.CONTENT_URI,
|
||||||
new String[]{ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME},
|
new String[]{ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME},
|
||||||
|
@ -425,35 +390,24 @@ public class EditContactFragment extends Fragment {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkSipAddress(){
|
private void addLinphoneFriendIfNeeded(){
|
||||||
boolean check = true;
|
|
||||||
for (NewOrUpdatedNumberOrAddress numberOrAddress : numbersAndAddresses) {
|
for (NewOrUpdatedNumberOrAddress numberOrAddress : numbersAndAddresses) {
|
||||||
if(numberOrAddress.newNumberOrAddress != null){
|
if(numberOrAddress.newNumberOrAddress != null && numberOrAddress.isSipAddress && !contactsManager.isContactHasAddress(contact, numberOrAddress.newNumberOrAddress)) {
|
||||||
if(numberOrAddress.isSipAddress) {
|
if(isNewContact){
|
||||||
if(isNewContact){
|
Contact c = contactsManager.findContactWithDisplayName(ContactsManager.getInstance().getDisplayName(firstName.getText().toString(), lastName.getText().toString()));
|
||||||
Contact c = ContactsManager.getInstance().findContactWithDisplayName(ContactsManager.getInstance().getDisplayName(firstName.getText().toString(), lastName.getText().toString()));
|
if (c != null) {
|
||||||
if (!ContactsManager.getInstance().isContactHasAddress(c, numberOrAddress.newNumberOrAddress)) {
|
contactsManager.createNewFriend(c, numberOrAddress.newNumberOrAddress);
|
||||||
if (c != null) {
|
}
|
||||||
ContactsManager.getInstance().createNewFriend(c, numberOrAddress.newNumberOrAddress);
|
} else {
|
||||||
}
|
if (numberOrAddress.oldNumberOrAddress == null) {
|
||||||
}
|
contactsManager.createNewFriend(contact, numberOrAddress.newNumberOrAddress);
|
||||||
} else {
|
} else {
|
||||||
if (!ContactsManager.getInstance().isContactHasAddress(contact, numberOrAddress.newNumberOrAddress)) {
|
if(contact.hasFriends())
|
||||||
check = false;
|
contactsManager.updateFriend(numberOrAddress.oldNumberOrAddress, numberOrAddress.newNumberOrAddress);
|
||||||
if (numberOrAddress.oldNumberOrAddress == null) {
|
|
||||||
ContactsManager.getInstance().createNewFriend(contact, numberOrAddress.newNumberOrAddress);
|
|
||||||
} else {
|
|
||||||
if(contact.hasFriends())
|
|
||||||
ContactsManager.getInstance().updateFriend(numberOrAddress.oldNumberOrAddress, numberOrAddress.newNumberOrAddress);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return check;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class NewOrUpdatedNumberOrAddress {
|
class NewOrUpdatedNumberOrAddress {
|
||||||
|
@ -509,7 +463,7 @@ public class EditContactFragment extends Fragment {
|
||||||
} else {
|
} else {
|
||||||
Compatibility.deleteSipAddressFromContact(ops, oldNumberOrAddress, String.valueOf(contactID));
|
Compatibility.deleteSipAddressFromContact(ops, oldNumberOrAddress, String.valueOf(contactID));
|
||||||
}
|
}
|
||||||
Compatibility.deleteLinphoneContactTag(ops, oldNumberOrAddress, findRawLinphoneContactID(String.valueOf(contactID)));
|
Compatibility.deleteLinphoneContactTag(ops, oldNumberOrAddress, contactsManager.findRawLinphoneContactID(String.valueOf(contactID)));
|
||||||
} else {
|
} else {
|
||||||
String select = ContactsContract.Data.CONTACT_ID + "=? AND "
|
String select = ContactsContract.Data.CONTACT_ID + "=? AND "
|
||||||
+ ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE + "' AND "
|
+ ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE + "' AND "
|
||||||
|
@ -546,7 +500,7 @@ public class EditContactFragment extends Fragment {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
String rawContactId = findRawContactID(String.valueOf(contactID));
|
String rawContactId = contactsManager.findRawContactID(getActivity().getContentResolver(),String.valueOf(contactID));
|
||||||
if (isSipAddress) {
|
if (isSipAddress) {
|
||||||
if (newNumberOrAddress.startsWith("sip:"))
|
if (newNumberOrAddress.startsWith("sip:"))
|
||||||
newNumberOrAddress = newNumberOrAddress.substring(4);
|
newNumberOrAddress = newNumberOrAddress.substring(4);
|
||||||
|
@ -554,7 +508,7 @@ public class EditContactFragment extends Fragment {
|
||||||
newNumberOrAddress = newNumberOrAddress + "@" + getResources().getString(R.string.default_domain);
|
newNumberOrAddress = newNumberOrAddress + "@" + getResources().getString(R.string.default_domain);
|
||||||
|
|
||||||
Compatibility.addSipAddressToContact(getActivity(), ops, newNumberOrAddress, rawContactId);
|
Compatibility.addSipAddressToContact(getActivity(), ops, newNumberOrAddress, rawContactId);
|
||||||
Compatibility.addLinphoneContactTag(getActivity(), ops, newNumberOrAddress, findRawLinphoneContactID(String.valueOf(contactID)));
|
Compatibility.addLinphoneContactTag(getActivity(), ops, newNumberOrAddress, contactsManager.findRawLinphoneContactID(String.valueOf(contactID)));
|
||||||
} else {
|
} else {
|
||||||
ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
|
ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
|
||||||
.withValue(ContactsContract.Data.RAW_CONTACT_ID, rawContactId)
|
.withValue(ContactsContract.Data.RAW_CONTACT_ID, rawContactId)
|
||||||
|
@ -579,7 +533,7 @@ public class EditContactFragment extends Fragment {
|
||||||
if(!newNumberOrAddress.contains("@"))
|
if(!newNumberOrAddress.contains("@"))
|
||||||
newNumberOrAddress = newNumberOrAddress + "@" + getResources().getString(R.string.default_domain);
|
newNumberOrAddress = newNumberOrAddress + "@" + getResources().getString(R.string.default_domain);
|
||||||
Compatibility.updateSipAddressForContact(ops, oldNumberOrAddress, newNumberOrAddress, String.valueOf(contactID));
|
Compatibility.updateSipAddressForContact(ops, oldNumberOrAddress, newNumberOrAddress, String.valueOf(contactID));
|
||||||
Compatibility.updateLinphoneContactTag(getActivity(), ops, newNumberOrAddress, oldNumberOrAddress, findRawLinphoneContactID(String.valueOf(contactID)));
|
Compatibility.updateLinphoneContactTag(getActivity(), ops, newNumberOrAddress, oldNumberOrAddress, contactsManager.findRawLinphoneContactID(String.valueOf(contactID)));
|
||||||
} else {
|
} else {
|
||||||
String select = ContactsContract.Data.CONTACT_ID + "=? AND "
|
String select = ContactsContract.Data.CONTACT_ID + "=? AND "
|
||||||
+ ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE + "' AND "
|
+ ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE + "' AND "
|
||||||
|
|
|
@ -152,8 +152,8 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
|
||||||
ContactsManager.getInstance().initializeSyncAccount(getApplicationContext(), getContentResolver());
|
ContactsManager.getInstance().initializeSyncAccount(getApplicationContext(), getContentResolver());
|
||||||
|
|
||||||
if(!LinphonePreferences.instance().isContactsMigrationDone()){
|
if(!LinphonePreferences.instance().isContactsMigrationDone()){
|
||||||
//ContactsManager.getInstance().migrateContacts();
|
ContactsManager.getInstance().migrateContacts();
|
||||||
//LinphonePreferences.instance().contactsMigrationDone();
|
LinphonePreferences.instance().contactsMigrationDone();
|
||||||
}
|
}
|
||||||
|
|
||||||
setContentView(R.layout.main);
|
setContentView(R.layout.main);
|
||||||
|
|
|
@ -45,6 +45,7 @@ import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageInfo;
|
import android.content.pm.PackageInfo;
|
||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
|
import android.database.ContentObserver;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
@ -52,6 +53,7 @@ import android.os.Build;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
|
import android.provider.ContactsContract;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -235,10 +237,12 @@ public final class LinphoneService extends Service {
|
||||||
mStartForeground = getClass().getMethod("startForeground", mStartFgSign);
|
mStartForeground = getClass().getMethod("startForeground", mStartFgSign);
|
||||||
mStopForeground = getClass().getMethod("stopForeground", mStopFgSign);
|
mStopForeground = getClass().getMethod("stopForeground", mStopFgSign);
|
||||||
} catch (NoSuchMethodException e) {
|
} catch (NoSuchMethodException e) {
|
||||||
Log.e(e, "Couldn't find startGoreground or stopForeground");
|
Log.e(e, "Couldn't find startForeground or stopForeground");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI, true, mObserver);
|
||||||
|
|
||||||
startForegroundCompat(NOTIF_ID, mNotif);
|
startForegroundCompat(NOTIF_ID, mNotif);
|
||||||
|
|
||||||
if (!mTestDelayElapsed) {
|
if (!mTestDelayElapsed) {
|
||||||
|
@ -259,6 +263,15 @@ public final class LinphoneService extends Service {
|
||||||
, mkeepAlivePendingIntent);
|
, mkeepAlivePendingIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ContentObserver mObserver = new ContentObserver(new Handler()) {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onChange(boolean selfChange) {
|
||||||
|
super.onChange(selfChange);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
private enum IncallIconState {INCALL, PAUSE, VIDEO, IDLE}
|
private enum IncallIconState {INCALL, PAUSE, VIDEO, IDLE}
|
||||||
private IncallIconState mCurrentIncallIconState = IncallIconState.IDLE;
|
private IncallIconState mCurrentIncallIconState = IncallIconState.IDLE;
|
||||||
private synchronized void setIncallIcon(IncallIconState state) {
|
private synchronized void setIncallIcon(IncallIconState state) {
|
||||||
|
@ -299,7 +312,8 @@ public final class LinphoneService extends Service {
|
||||||
LinphoneAddress address = LinphoneCoreFactory.instance().createLinphoneAddress(userName,domain,null);
|
LinphoneAddress address = LinphoneCoreFactory.instance().createLinphoneAddress(userName,domain,null);
|
||||||
address.setDisplayName(displayName);
|
address.setDisplayName(displayName);
|
||||||
|
|
||||||
Uri pictureUri = LinphoneUtils.findUriPictureOfContactAndSetDisplayName(address, getContentResolver());
|
Contact contact = ContactsManager.getInstance().findContactWithAddress(address);
|
||||||
|
Uri pictureUri = contact != null ? contact.getPhotoUri() : null;
|
||||||
Bitmap bm = null;
|
Bitmap bm = null;
|
||||||
try {
|
try {
|
||||||
bm = MediaStore.Images.Media.getBitmap(getContentResolver(), pictureUri);
|
bm = MediaStore.Images.Media.getBitmap(getContentResolver(), pictureUri);
|
||||||
|
@ -376,7 +390,8 @@ public final class LinphoneService extends Service {
|
||||||
|
|
||||||
Uri pictureUri;
|
Uri pictureUri;
|
||||||
try {
|
try {
|
||||||
pictureUri = LinphoneUtils.findUriPictureOfContactAndSetDisplayName(LinphoneCoreFactory.instance().createLinphoneAddress(fromSipUri), getContentResolver());
|
Contact contact = ContactsManager.getInstance().findContactWithAddress(LinphoneCoreFactory.instance().createLinphoneAddress(fromSipUri));
|
||||||
|
pictureUri = contact.getPhotoUri();
|
||||||
} catch (LinphoneCoreException e1) {
|
} catch (LinphoneCoreException e1) {
|
||||||
Log.e("Cannot parse from address",e1);
|
Log.e("Cannot parse from address",e1);
|
||||||
pictureUri=null;
|
pictureUri=null;
|
||||||
|
@ -548,6 +563,7 @@ public final class LinphoneService extends Service {
|
||||||
mNM.cancel(MESSAGE_NOTIF_ID);
|
mNM.cancel(MESSAGE_NOTIF_ID);
|
||||||
|
|
||||||
((AlarmManager) this.getSystemService(Context.ALARM_SERVICE)).cancel(mkeepAlivePendingIntent);
|
((AlarmManager) this.getSystemService(Context.ALARM_SERVICE)).cancel(mkeepAlivePendingIntent);
|
||||||
|
getContentResolver().unregisterContentObserver(mObserver);
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -81,7 +81,11 @@ public class Compatibility {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> extractContactImAddresses(String id, ContentResolver cr) {
|
public static List<String> extractContactImAddresses(String id, ContentResolver cr) {
|
||||||
return ApiFivePlus.extractContactNumbersAndAddresses(id, cr);
|
if (Version.sdkAboveOrEqual(Version.API09_GINGERBREAD_23)) {
|
||||||
|
return ApiFivePlus.extractContactNumbersAndAddresses(id, cr);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Cursor getContactsCursor(ContentResolver cr, List<String> contactsId) {
|
public static Cursor getContactsCursor(ContentResolver cr, List<String> contactsId) {
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 04abb57606e7f322a10e60288291889843feaa70
|
Subproject commit ef7677a88d7aaef4168f884eeaca85af2994ecd9
|
Loading…
Reference in a new issue