diff --git a/app/src/main/kotlin/com/tutpro/baresip/Contact.kt b/app/src/main/kotlin/com/tutpro/baresip/Contact.kt index a2bc9939..6cfa4a3b 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/Contact.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/Contact.kt @@ -139,12 +139,17 @@ sealed class Contact { } fun saveBaresipContacts() { + val avatarFiles = avatarFileNames() var contents = "" - for (c in BaresipService.baresipContacts.value) + for (c in BaresipService.baresipContacts.value) { contents += "\"${c.name}\" <${c.uri}>;id=${c.id};color=${c.color}" + ";favorite=${if (c.favorite) "yes" else "no"}\n" + avatarFiles.remove(c.id.toString() + ".png") + } Utils.putFileContents(BaresipService.filesPath + "/contacts", contents.toByteArray()) + for (f in avatarFiles) + File(BaresipService.filesPath + "/" + f).delete() } fun loadAndroidContacts(ctx: Context) { @@ -300,5 +305,9 @@ sealed class Contact { } contactNames.value = newList.toList() } + + private fun avatarFileNames(): MutableList { + return File(BaresipService.filesPath).list()!!.filter{ it.endsWith(".png")}.toMutableList() + } } }