Fix contact sip address
This commit is contained in:
parent
55977fa706
commit
d2f91f5a84
3 changed files with 55 additions and 36 deletions
|
@ -539,6 +539,8 @@ public class EditContactFragment extends Fragment {
|
||||||
if (isSipAddress) {
|
if (isSipAddress) {
|
||||||
if (newNumberOrAddress.startsWith("sip:"))
|
if (newNumberOrAddress.startsWith("sip:"))
|
||||||
newNumberOrAddress = newNumberOrAddress.substring(4);
|
newNumberOrAddress = newNumberOrAddress.substring(4);
|
||||||
|
if(!newNumberOrAddress.contains("@"))
|
||||||
|
newNumberOrAddress = newNumberOrAddress + "@" + getResources().getString(R.string.default_domain);
|
||||||
Compatibility.addSipAddressToContact(getActivity(), ops, newNumberOrAddress);
|
Compatibility.addSipAddressToContact(getActivity(), ops, newNumberOrAddress);
|
||||||
} else {
|
} else {
|
||||||
ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
|
ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
|
||||||
|
@ -556,6 +558,8 @@ public class EditContactFragment extends Fragment {
|
||||||
if (isSipAddress) {
|
if (isSipAddress) {
|
||||||
if (newNumberOrAddress.startsWith("sip:"))
|
if (newNumberOrAddress.startsWith("sip:"))
|
||||||
newNumberOrAddress = newNumberOrAddress.substring(4);
|
newNumberOrAddress = newNumberOrAddress.substring(4);
|
||||||
|
if(!newNumberOrAddress.contains("@"))
|
||||||
|
newNumberOrAddress = newNumberOrAddress + "@" + getResources().getString(R.string.default_domain);
|
||||||
Compatibility.addSipAddressToContact(getActivity(), ops, newNumberOrAddress, rawContactId);
|
Compatibility.addSipAddressToContact(getActivity(), ops, newNumberOrAddress, rawContactId);
|
||||||
} else {
|
} else {
|
||||||
ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
|
ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
|
||||||
|
@ -578,6 +582,8 @@ public class EditContactFragment extends Fragment {
|
||||||
if (isSipAddress) {
|
if (isSipAddress) {
|
||||||
if (newNumberOrAddress.startsWith("sip:"))
|
if (newNumberOrAddress.startsWith("sip:"))
|
||||||
newNumberOrAddress = newNumberOrAddress.substring(4);
|
newNumberOrAddress = newNumberOrAddress.substring(4);
|
||||||
|
if(!newNumberOrAddress.contains("@"))
|
||||||
|
newNumberOrAddress = newNumberOrAddress + "@" + getResources().getString(R.string.default_domain);
|
||||||
Compatibility.updateSipAddressForContact(ops, oldNumberOrAddress, newNumberOrAddress, String.valueOf(contactID));
|
Compatibility.updateSipAddressForContact(ops, oldNumberOrAddress, newNumberOrAddress, String.valueOf(contactID));
|
||||||
} else {
|
} else {
|
||||||
String select = ContactsContract.Data.CONTACT_ID + "=? AND "
|
String select = ContactsContract.Data.CONTACT_ID + "=? AND "
|
||||||
|
|
|
@ -17,6 +17,7 @@ import android.graphics.Bitmap;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.provider.ContactsContract;
|
import android.provider.ContactsContract;
|
||||||
|
import android.provider.ContactsContract.CommonDataKinds.Im;
|
||||||
import android.provider.ContactsContract.Contacts;
|
import android.provider.ContactsContract.Contacts;
|
||||||
import android.provider.ContactsContract.CommonDataKinds.SipAddress;
|
import android.provider.ContactsContract.CommonDataKinds.SipAddress;
|
||||||
import android.provider.ContactsContract.Intents.Insert;
|
import android.provider.ContactsContract.Intents.Insert;
|
||||||
|
@ -136,8 +137,9 @@ public class ApiElevenPlus {
|
||||||
|
|
||||||
ArrayList<ContentValues> data = new ArrayList<ContentValues>();
|
ArrayList<ContentValues> data = new ArrayList<ContentValues>();
|
||||||
ContentValues sipAddressRow = new ContentValues();
|
ContentValues sipAddressRow = new ContentValues();
|
||||||
sipAddressRow.put(Contacts.Data.MIMETYPE, SipAddress.CONTENT_ITEM_TYPE);
|
sipAddressRow.put(Contacts.Data.MIMETYPE, Im.CONTENT_ITEM_TYPE);
|
||||||
sipAddressRow.put(SipAddress.SIP_ADDRESS, sipUri);
|
sipAddressRow.put(Im.DATA, sipUri);
|
||||||
|
sipAddressRow.put(Im.CUSTOM_PROTOCOL,"Sip");
|
||||||
data.add(sipAddressRow);
|
data.add(sipAddressRow);
|
||||||
intent.putParcelableArrayListExtra(Insert.DATA, data);
|
intent.putParcelableArrayListExtra(Insert.DATA, data);
|
||||||
|
|
||||||
|
@ -151,8 +153,9 @@ public class ApiElevenPlus {
|
||||||
|
|
||||||
ArrayList<ContentValues> data = new ArrayList<ContentValues>();
|
ArrayList<ContentValues> data = new ArrayList<ContentValues>();
|
||||||
ContentValues sipAddressRow = new ContentValues();
|
ContentValues sipAddressRow = new ContentValues();
|
||||||
sipAddressRow.put(Contacts.Data.MIMETYPE, SipAddress.CONTENT_ITEM_TYPE);
|
sipAddressRow.put(Contacts.Data.MIMETYPE, Im.CONTENT_ITEM_TYPE);
|
||||||
sipAddressRow.put(SipAddress.SIP_ADDRESS, sipUri);
|
sipAddressRow.put(Im.DATA, sipUri);
|
||||||
|
sipAddressRow.put(Im.CUSTOM_PROTOCOL,"Sip");
|
||||||
data.add(sipAddressRow);
|
data.add(sipAddressRow);
|
||||||
data.add(sipAddressRow);
|
data.add(sipAddressRow);
|
||||||
intent.putParcelableArrayListExtra(Insert.DATA, data);
|
intent.putParcelableArrayListExtra(Insert.DATA, data);
|
||||||
|
|
|
@ -15,6 +15,7 @@ import android.database.Cursor;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.provider.ContactsContract;
|
import android.provider.ContactsContract;
|
||||||
import android.provider.ContactsContract.CommonDataKinds;
|
import android.provider.ContactsContract.CommonDataKinds;
|
||||||
|
import android.provider.ContactsContract.Contacts;
|
||||||
import android.provider.ContactsContract.CommonDataKinds.Phone;
|
import android.provider.ContactsContract.CommonDataKinds.Phone;
|
||||||
import android.provider.ContactsContract.Data;
|
import android.provider.ContactsContract.Data;
|
||||||
|
|
||||||
|
@ -45,10 +46,12 @@ public class ApiNinePlus {
|
||||||
public static void addSipAddressToContact(Context context, ArrayList<ContentProviderOperation> ops, String sipAddress) {
|
public static void addSipAddressToContact(Context context, ArrayList<ContentProviderOperation> ops, String sipAddress) {
|
||||||
ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
|
ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
|
||||||
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
|
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
|
||||||
.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE)
|
.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE)
|
||||||
.withValue(ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS, sipAddress)
|
.withValue(ContactsContract.CommonDataKinds.Im.DATA, sipAddress)
|
||||||
.withValue(ContactsContract.CommonDataKinds.SipAddress.TYPE, ContactsContract.CommonDataKinds.SipAddress.TYPE_CUSTOM)
|
.withValue(ContactsContract.CommonDataKinds.Im.TYPE, ContactsContract.CommonDataKinds.Im.TYPE_CUSTOM)
|
||||||
.withValue(ContactsContract.CommonDataKinds.SipAddress.LABEL, context.getString(R.string.addressbook_label))
|
.withValue(ContactsContract.CommonDataKinds.Im.PROTOCOL, ContactsContract.CommonDataKinds.Im.PROTOCOL_CUSTOM)
|
||||||
|
.withValue(ContactsContract.CommonDataKinds.Im.CUSTOM_PROTOCOL,"Sip")
|
||||||
|
.withValue(ContactsContract.CommonDataKinds.Im.LABEL, context.getString(R.string.addressbook_label))
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -56,33 +59,35 @@ public class ApiNinePlus {
|
||||||
public static void addSipAddressToContact(Context context, ArrayList<ContentProviderOperation> ops, String sipAddress, String rawContactID) {
|
public static void addSipAddressToContact(Context context, ArrayList<ContentProviderOperation> ops, String sipAddress, String rawContactID) {
|
||||||
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)
|
||||||
.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE)
|
.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE)
|
||||||
.withValue(ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS, sipAddress)
|
.withValue(ContactsContract.CommonDataKinds.Im.DATA, sipAddress)
|
||||||
.withValue(ContactsContract.CommonDataKinds.SipAddress.TYPE, ContactsContract.CommonDataKinds.SipAddress.TYPE_CUSTOM)
|
.withValue(ContactsContract.CommonDataKinds.Im.TYPE, ContactsContract.CommonDataKinds.Im.TYPE_CUSTOM)
|
||||||
.withValue(ContactsContract.CommonDataKinds.SipAddress.LABEL, context.getString(R.string.addressbook_label))
|
.withValue(ContactsContract.CommonDataKinds.Im.PROTOCOL, ContactsContract.CommonDataKinds.Im.PROTOCOL_CUSTOM)
|
||||||
|
.withValue(ContactsContract.CommonDataKinds.Im.CUSTOM_PROTOCOL,"Sip")
|
||||||
|
.withValue(ContactsContract.CommonDataKinds.Im.LABEL, context.getString(R.string.addressbook_label))
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void updateSipAddressForContact(ArrayList<ContentProviderOperation> ops, String oldSipAddress, String newSipAddress, String contactID) {
|
public static void updateSipAddressForContact(ArrayList<ContentProviderOperation> ops, String oldIm, String newIm, String contactID) {
|
||||||
String select = ContactsContract.Data.CONTACT_ID + "=? AND "
|
String select = ContactsContract.Data.CONTACT_ID + "=? AND "
|
||||||
+ ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE + "' AND "
|
+ ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE + "' AND "
|
||||||
+ ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS + "=?";
|
+ ContactsContract.CommonDataKinds.Im.DATA + "=? AND lower(" + CommonDataKinds.Im.CUSTOM_PROTOCOL + ") = 'sip'";
|
||||||
String[] args = new String[] { String.valueOf(contactID), oldSipAddress };
|
String[] args = new String[] { String.valueOf(contactID), oldIm };
|
||||||
|
|
||||||
ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
|
ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
|
||||||
.withSelection(select, args)
|
.withSelection(select, args)
|
||||||
.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE)
|
.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE)
|
||||||
.withValue(ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS, newSipAddress)
|
.withValue(ContactsContract.CommonDataKinds.Im.DATA, newIm)
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void deleteSipAddressFromContact(ArrayList<ContentProviderOperation> ops, String oldSipAddress, String contactID) {
|
public static void deleteSipAddressFromContact(ArrayList<ContentProviderOperation> ops, String oldIm, String contactID) {
|
||||||
String select = ContactsContract.Data.CONTACT_ID + "=? AND "
|
String select = ContactsContract.Data.CONTACT_ID + "=? AND "
|
||||||
+ ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE + "' AND "
|
+ ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE + "' AND "
|
||||||
+ ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS + "=?";
|
+ ContactsContract.CommonDataKinds.Im.DATA + "=? AND lower(" + CommonDataKinds.Im.CUSTOM_PROTOCOL + ") = 'sip'";
|
||||||
String[] args = new String[] { String.valueOf(contactID), oldSipAddress };
|
String[] args = new String[] { String.valueOf(contactID), oldIm };
|
||||||
|
|
||||||
ops.add(ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI)
|
ops.add(ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI)
|
||||||
.withSelection(select, args)
|
.withSelection(select, args)
|
||||||
|
@ -112,13 +117,15 @@ public class ApiNinePlus {
|
||||||
.append(" = ? AND ")
|
.append(" = ? AND ")
|
||||||
.append(Data.MIMETYPE)
|
.append(Data.MIMETYPE)
|
||||||
.append(" = '")
|
.append(" = '")
|
||||||
.append(ContactsContract.CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE)
|
.append(ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE)
|
||||||
.append("'")
|
.append("' AND lower(")
|
||||||
|
.append(ContactsContract.CommonDataKinds.Im.CUSTOM_PROTOCOL)
|
||||||
|
.append(") = 'sip'")
|
||||||
.toString();
|
.toString();
|
||||||
projection = new String[] {ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS};
|
projection = new String[] {ContactsContract.CommonDataKinds.Im.DATA};
|
||||||
c = cr.query(uri, projection, selection, new String[]{id}, null);
|
c = cr.query(uri, projection, selection, new String[]{id}, null);
|
||||||
if (c != null) {
|
if (c != null) {
|
||||||
int nbId = c.getColumnIndex(ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS);
|
int nbId = c.getColumnIndex(ContactsContract.CommonDataKinds.Im.DATA);
|
||||||
while (c.moveToNext()) {
|
while (c.moveToNext()) {
|
||||||
list.add("sip:" + c.getString(nbId));
|
list.add("sip:" + c.getString(nbId));
|
||||||
}
|
}
|
||||||
|
@ -131,8 +138,9 @@ public class ApiNinePlus {
|
||||||
public static Cursor getContactsCursor(ContentResolver cr, String search) {
|
public static Cursor getContactsCursor(ContentResolver cr, String search) {
|
||||||
String req = "(" + Data.MIMETYPE + " = '" + CommonDataKinds.Phone.CONTENT_ITEM_TYPE
|
String req = "(" + Data.MIMETYPE + " = '" + CommonDataKinds.Phone.CONTENT_ITEM_TYPE
|
||||||
+ "' AND " + CommonDataKinds.Phone.NUMBER + " IS NOT NULL OR ("
|
+ "' AND " + CommonDataKinds.Phone.NUMBER + " IS NOT NULL OR ("
|
||||||
+ Data.MIMETYPE + " = '" + CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE
|
+ Data.MIMETYPE + " = '" + CommonDataKinds.Im.CONTENT_ITEM_TYPE
|
||||||
+ "' AND " + ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS + " IS NOT NULL))";
|
+ "' AND lower(" + CommonDataKinds.Im.CUSTOM_PROTOCOL + ") = 'sip'"
|
||||||
|
+ " AND " + ContactsContract.CommonDataKinds.Im.DATA + " IS NOT NULL))";
|
||||||
|
|
||||||
if (search != null) {
|
if (search != null) {
|
||||||
req += " AND " + Data.DISPLAY_NAME + " LIKE '%" + search + "%'";
|
req += " AND " + Data.DISPLAY_NAME + " LIKE '%" + search + "%'";
|
||||||
|
@ -143,8 +151,9 @@ public class ApiNinePlus {
|
||||||
|
|
||||||
public static Cursor getSIPContactsCursor(ContentResolver cr, String search) {
|
public static Cursor getSIPContactsCursor(ContentResolver cr, String search) {
|
||||||
String req = null;
|
String req = null;
|
||||||
req = Data.MIMETYPE + " = '" + CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE
|
req = Data.MIMETYPE + " = '" + CommonDataKinds.Im.CONTENT_ITEM_TYPE
|
||||||
+ "' AND " + ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS + " IS NOT NULL";
|
+ "' AND lower(" + CommonDataKinds.Im.CUSTOM_PROTOCOL + ") = 'sip'"
|
||||||
|
+ " AND " + ContactsContract.CommonDataKinds.Im.DATA + " IS NOT NULL";
|
||||||
|
|
||||||
if (search != null) {
|
if (search != null) {
|
||||||
req += " AND " + Data.DISPLAY_NAME + " LIKE '%" + search + "%'";
|
req += " AND " + Data.DISPLAY_NAME + " LIKE '%" + search + "%'";
|
||||||
|
@ -155,10 +164,11 @@ public class ApiNinePlus {
|
||||||
|
|
||||||
private static Cursor getSIPContactCursor(ContentResolver cr, String id) {
|
private static Cursor getSIPContactCursor(ContentResolver cr, String id) {
|
||||||
String req = null;
|
String req = null;
|
||||||
req = Data.MIMETYPE + " = '" + CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE
|
req = Contacts.Data.MIMETYPE + " = '" + CommonDataKinds.Im.CONTENT_ITEM_TYPE
|
||||||
+ "' AND " + ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS + " LIKE '" + id + "'";
|
+ " AND lower(" + CommonDataKinds.Im.CUSTOM_PROTOCOL + ") = 'sip' AND "
|
||||||
|
+ android.provider.ContactsContract.CommonDataKinds.Im.DATA + " LIKE '" + id + "'";
|
||||||
|
|
||||||
return ApiFivePlus.getGeneralContactCursor(cr, req, false);
|
return ApiFivePlus.getGeneralContactCursor(cr, req, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Uri findUriPictureOfContactAndSetDisplayName(LinphoneAddress address, ContentResolver cr) {
|
public static Uri findUriPictureOfContactAndSetDisplayName(LinphoneAddress address, ContentResolver cr) {
|
||||||
|
|
Loading…
Reference in a new issue