Delete unused avatar files

This commit is contained in:
Juha Heinanen
2025-04-15 20:00:21 +03:00
parent d56d0aa0c7
commit c8a9704c70
@@ -139,12 +139,17 @@ sealed class Contact {
} }
fun saveBaresipContacts() { fun saveBaresipContacts() {
val avatarFiles = avatarFileNames()
var contents = "" 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}" + contents += "\"${c.name}\" <${c.uri}>;id=${c.id};color=${c.color}" +
";favorite=${if (c.favorite) "yes" else "no"}\n" ";favorite=${if (c.favorite) "yes" else "no"}\n"
avatarFiles.remove(c.id.toString() + ".png")
}
Utils.putFileContents(BaresipService.filesPath + "/contacts", Utils.putFileContents(BaresipService.filesPath + "/contacts",
contents.toByteArray()) contents.toByteArray())
for (f in avatarFiles)
File(BaresipService.filesPath + "/" + f).delete()
} }
fun loadAndroidContacts(ctx: Context) { fun loadAndroidContacts(ctx: Context) {
@@ -300,5 +305,9 @@ sealed class Contact {
} }
contactNames.value = newList.toList() contactNames.value = newList.toList()
} }
private fun avatarFileNames(): MutableList<String> {
return File(BaresipService.filesPath).list()!!.filter{ it.endsWith(".png")}.toMutableList()
}
} }
} }