Allow contact with just name plus contact screen improvements

This commit is contained in:
Juha Heinanen
2026-07-22 14:22:48 +03:00
parent 14fd7efb21
commit 2978ddc8af
3 changed files with 8 additions and 12 deletions
@@ -260,7 +260,7 @@ sealed class Contact {
cur?.close() cur?.close()
val newList = mutableListOf<AndroidContact>() val newList = mutableListOf<AndroidContact>()
for ((_, value) in contacts) for ((_, value) in contacts)
if (value.name != "" && (value.uris.isNotEmpty() || value.email != "")) if (value.name != "")
newList.add(value) newList.add(value)
BaresipService.androidContacts.value = newList.toList() BaresipService.androidContacts.value = newList.toList()
} }
@@ -178,7 +178,7 @@ private fun ContactScreen(
new = true, new = true,
isEditing = true, isEditing = true,
name = "", name = "",
uris = if (uriOrNameArg == "") emptyList() else listOf(Contact.ContactUri(uriOrNameArg, "")), uris = listOf(Contact.ContactUri(uriOrNameArg, "")),
email = "", email = "",
favorite = false, favorite = false,
android = BaresipService.contactsMode == "android", android = BaresipService.contactsMode == "android",
@@ -288,8 +288,10 @@ private fun ContactScreen(
} }
val onEdit: () -> Unit = { val onEdit: () -> Unit = {
if (screenState.isBaresipContact) if (screenState.isBaresipContact) {
screenState = screenState.copy(isEditing = true) val uris = screenState.uris.ifEmpty { listOf(Contact.ContactUri("", "")) }
screenState = screenState.copy(isEditing = true, uris = uris)
}
else { else {
val intent = Intent(Intent.ACTION_EDIT).apply { val intent = Intent(Intent.ACTION_EDIT).apply {
val contactUri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, screenState.id) val contactUri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, screenState.id)
@@ -908,16 +910,10 @@ private fun checkOnClick(
newUris.add(Contact.ContactUri(u, contactUri.label)) newUris.add(Contact.ContactUri(u, contactUri.label))
} }
if (newUris.isEmpty() && currentState.email.trim().isEmpty()) {
alertTitle.value = ctx.getString(R.string.notice)
alertMessage.value = ctx.getString(R.string.sip_or_tel_uri)
showAlert.value = true
return false
}
var newName = currentState.name.trim() var newName = currentState.name.trim()
if (newName == "") if (newName == "")
newName = if (newUris.isNotEmpty()) newUris[0].uri.substringAfter(":") else currentState.email newName = if (newUris.isNotEmpty()) newUris[0].uri.substringAfter(":") else currentState.email
if (!Utils.checkName(newName)) { if (!Utils.checkName(newName)) {
alertTitle.value = ctx.getString(R.string.notice) alertTitle.value = ctx.getString(R.string.notice)
alertMessage.value = String.format(ctx.getString(R.string.invalid_contact), newName) alertMessage.value = String.format(ctx.getString(R.string.invalid_contact), newName)
@@ -241,7 +241,7 @@ private fun ContactsScreen(navController: NavController) {
photoBase64 = line.substringAfter(":").trim() photoBase64 = line.substringAfter(":").trim()
} }
line.startsWith("END:VCARD", ignoreCase = true) -> { line.startsWith("END:VCARD", ignoreCase = true) -> {
if (name.isNotEmpty() && (uris.isNotEmpty() || email.isNotEmpty())) { if (name.isNotEmpty()) {
val existingContact = newBaresipContacts.find { it.name == name } val existingContact = newBaresipContacts.find { it.name == name }
val contactId = existingContact?.id ?: (System.currentTimeMillis() + contactNo++) val contactId = existingContact?.id ?: (System.currentTimeMillis() + contactNo++)
if (photoBase64.isNotEmpty()) if (photoBase64.isNotEmpty())