Minor contact related fixes and improvements
This commit is contained in:
@@ -89,19 +89,21 @@ sealed class Contact {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun nameExists(name: String, ignoreCase: Boolean): Boolean {
|
fun nameExists(name: String, ignoreCase: Boolean): Boolean {
|
||||||
for (c in BaresipService.baresipContacts)
|
for (c in BaresipService.contacts)
|
||||||
|
when (c) {
|
||||||
|
is BaresipContact ->
|
||||||
if (c.name.equals(name, ignoreCase = ignoreCase))
|
if (c.name.equals(name, ignoreCase = ignoreCase))
|
||||||
return true
|
return true
|
||||||
for (c in BaresipService.androidContacts)
|
is AndroidContact ->
|
||||||
if (c.name.equals(name, ignoreCase = ignoreCase))
|
if (c.name.equals(name, ignoreCase = ignoreCase))
|
||||||
return true
|
return true
|
||||||
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
fun saveBaresipContacts() {
|
fun saveBaresipContacts() {
|
||||||
var contents = ""
|
var contents = ""
|
||||||
for (c in BaresipService.contacts)
|
for (c in BaresipService.baresipContacts)
|
||||||
if (c is BaresipContact)
|
|
||||||
contents += "\"${c.name}\" <${c.uri}>;id=${c.id};color=${c.color}\n"
|
contents += "\"${c.name}\" <${c.uri}>;id=${c.id};color=${c.color}\n"
|
||||||
Utils.putFileContents(BaresipService.filesPath + "/contacts",
|
Utils.putFileContents(BaresipService.filesPath + "/contacts",
|
||||||
contents.toByteArray())
|
contents.toByteArray())
|
||||||
@@ -124,10 +126,6 @@ sealed class Contact {
|
|||||||
val mime = cur.getString(2)
|
val mime = cur.getString(2)
|
||||||
val data = cur.getString(3)
|
val data = cur.getString(3)
|
||||||
val thumb = cur.getString(4)?.toUri()
|
val thumb = cur.getString(4)?.toUri()
|
||||||
if (nameExists(name, true)) {
|
|
||||||
Log.d(TAG, "Skipping Android contact with existing name '$name'")
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
val contact = if (contacts.containsKey(id))
|
val contact = if (contacts.containsKey(id))
|
||||||
contacts[id]!!
|
contacts[id]!!
|
||||||
else
|
else
|
||||||
@@ -200,13 +198,18 @@ sealed class Contact {
|
|||||||
if (BaresipService.contactsMode != "Android")
|
if (BaresipService.contactsMode != "Android")
|
||||||
BaresipService.contacts.addAll(BaresipService.baresipContacts)
|
BaresipService.contacts.addAll(BaresipService.baresipContacts)
|
||||||
if (BaresipService.contactsMode != "baresip")
|
if (BaresipService.contactsMode != "baresip")
|
||||||
BaresipService.contacts.addAll(BaresipService.androidContacts)
|
addAndroidContacts()
|
||||||
sortContacts()
|
sortContacts()
|
||||||
generateContactNames()
|
generateContactNames()
|
||||||
BaresipService.contactUpdate.postValue(System.nanoTime())
|
BaresipService.contactUpdate.postValue(System.nanoTime())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun generateContactNames () {
|
fun removeBaresipContact(contact: BaresipContact) {
|
||||||
|
BaresipService.baresipContacts.remove(contact)
|
||||||
|
saveBaresipContacts()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun generateContactNames () {
|
||||||
BaresipService.contactNames.clear()
|
BaresipService.contactNames.clear()
|
||||||
for (c in BaresipService.contacts)
|
for (c in BaresipService.contacts)
|
||||||
when (c) {
|
when (c) {
|
||||||
@@ -218,6 +221,12 @@ sealed class Contact {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun addAndroidContacts() {
|
||||||
|
for (c in BaresipService.androidContacts)
|
||||||
|
if (!nameExists(c.name, true))
|
||||||
|
BaresipService.contacts.add(c)
|
||||||
|
}
|
||||||
|
|
||||||
private fun sortContacts() {
|
private fun sortContacts() {
|
||||||
BaresipService.contacts.sortBy{ when (it) {
|
BaresipService.contacts.sortBy{ when (it) {
|
||||||
is BaresipContact -> it.name
|
is BaresipContact -> it.name
|
||||||
|
|||||||
@@ -172,9 +172,8 @@ class ContactListAdapter(private val ctx: Context, private val rows: ArrayList<C
|
|||||||
Log.e(TAG, "Could not delete file '$id.img")
|
Log.e(TAG, "Could not delete file '$id.img")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Contact.contacts().removeAt(position)
|
Contact.removeBaresipContact(contact)
|
||||||
Contact.generateContactNames()
|
Contact.contactsUpdate()
|
||||||
Contact.saveBaresipContacts()
|
|
||||||
this.notifyDataSetChanged()
|
this.notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
is Contact.AndroidContact -> {
|
is Contact.AndroidContact -> {
|
||||||
|
|||||||
Reference in New Issue
Block a user