Work on support for multiple numbers in Android contacts
This commit is contained in:
@@ -51,16 +51,14 @@ sealed class Contact {
|
||||
return uri
|
||||
}
|
||||
|
||||
// Return uri of contact name or null if contact is not found
|
||||
// If Android contact has more than one uri, return latest if given and found
|
||||
fun contactUri(name: String, latest: String?): String? {
|
||||
for (c in contacts())
|
||||
when (c) {
|
||||
is BaresipContact -> {
|
||||
if (c.name.equals(name, ignoreCase = true))
|
||||
return c.uri.removePrefix("<")
|
||||
.replaceAfter(">", "")
|
||||
.replace(">", "")
|
||||
.replaceAfter(">", "")
|
||||
.replace(">", "")
|
||||
}
|
||||
is AndroidContact -> {
|
||||
if (c.name == name) {
|
||||
@@ -83,6 +81,30 @@ sealed class Contact {
|
||||
return null
|
||||
}
|
||||
|
||||
// Return URIs of contact name or null if contact is not found
|
||||
fun contactUris(name: String): ArrayList<String> {
|
||||
val uris = ArrayList<String>()
|
||||
for (c in contacts())
|
||||
when (c) {
|
||||
is BaresipContact -> {
|
||||
if (c.name.equals(name, ignoreCase = true)) {
|
||||
uris.add(c.uri.removePrefix("<")
|
||||
.replaceAfter(">", "")
|
||||
.replace(">", ""))
|
||||
return uris
|
||||
}
|
||||
}
|
||||
is AndroidContact -> {
|
||||
if (c.name == name) {
|
||||
for (u in c.uris)
|
||||
uris.add(u)
|
||||
return uris
|
||||
}
|
||||
}
|
||||
}
|
||||
return uris
|
||||
}
|
||||
|
||||
fun findContact(uri: String): Contact? {
|
||||
for (c in contacts())
|
||||
when (c) {
|
||||
@@ -127,7 +149,7 @@ sealed class Contact {
|
||||
// cursor using getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE
|
||||
val projection = arrayOf(ContactsContract.Data.CONTACT_ID, ContactsContract.Data.DISPLAY_NAME,
|
||||
ContactsContract.Data.MIMETYPE, ContactsContract.Data.DATA1,
|
||||
ContactsContract.Data.PHOTO_THUMBNAIL_URI)
|
||||
/* ContactsContract.Data.DATA2 ,*/ ContactsContract.Data.PHOTO_THUMBNAIL_URI)
|
||||
val selection =
|
||||
ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE + "' OR " +
|
||||
ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE + "'"
|
||||
@@ -149,8 +171,10 @@ sealed class Contact {
|
||||
contact.name = name
|
||||
if (contact.thumbnailUri == null && thumb != null)
|
||||
contact.thumbnailUri = thumb
|
||||
if (mime == ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
|
||||
contact.uris.add("tel:${data.filterNot{setOf('-', ' ', '(', ')').contains(it)}}")
|
||||
if (mime == ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE) {
|
||||
contact.uris.add("tel:${data.filterNot { setOf('-', ' ', '(', ')').contains(it) }}")
|
||||
// contact.types.add(typeToString(cur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE)))
|
||||
}
|
||||
else if (mime == ContactsContract.CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE)
|
||||
contact.uris.add("sip:$data")
|
||||
else
|
||||
@@ -164,6 +188,16 @@ sealed class Contact {
|
||||
BaresipService.androidContacts.add(value)
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
private fun typeToString(type: Int): String {
|
||||
return when(type) {
|
||||
ContactsContract.CommonDataKinds.Phone.TYPE_HOME -> "Home"
|
||||
ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE -> "Mobile"
|
||||
ContactsContract.CommonDataKinds.Phone.TYPE_WORK -> "Work"
|
||||
else -> "Unknown"
|
||||
}
|
||||
}
|
||||
|
||||
fun restoreBaresipContacts(): Boolean {
|
||||
val content = Utils.getFileContents(BaresipService.filesPath + "/contacts")
|
||||
?: return false
|
||||
@@ -235,8 +269,7 @@ sealed class Contact {
|
||||
is BaresipContact ->
|
||||
BaresipService.contactNames.add(c.name)
|
||||
is AndroidContact ->
|
||||
if (c.uris.size == 1)
|
||||
BaresipService.contactNames.add(c.name)
|
||||
BaresipService.contactNames.add(c.name)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user