From 2978ddc8af29e60a27b108406c0f0a0a589b8e67 Mon Sep 17 00:00:00 2001 From: Juha Heinanen Date: Wed, 22 Jul 2026 14:22:48 +0300 Subject: [PATCH] Allow contact with just name plus contact screen improvements --- .../main/kotlin/com/tutpro/baresip/Contact.kt | 2 +- .../kotlin/com/tutpro/baresip/ContactScreen.kt | 16 ++++++---------- .../kotlin/com/tutpro/baresip/ContactsScreen.kt | 2 +- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/app/src/main/kotlin/com/tutpro/baresip/Contact.kt b/app/src/main/kotlin/com/tutpro/baresip/Contact.kt index 4446b2ce..16b23b61 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/Contact.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/Contact.kt @@ -260,7 +260,7 @@ sealed class Contact { cur?.close() val newList = mutableListOf() for ((_, value) in contacts) - if (value.name != "" && (value.uris.isNotEmpty() || value.email != "")) + if (value.name != "") newList.add(value) BaresipService.androidContacts.value = newList.toList() } diff --git a/app/src/main/kotlin/com/tutpro/baresip/ContactScreen.kt b/app/src/main/kotlin/com/tutpro/baresip/ContactScreen.kt index 3de1b8c4..93ab06b9 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/ContactScreen.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/ContactScreen.kt @@ -178,7 +178,7 @@ private fun ContactScreen( new = true, isEditing = true, name = "", - uris = if (uriOrNameArg == "") emptyList() else listOf(Contact.ContactUri(uriOrNameArg, "")), + uris = listOf(Contact.ContactUri(uriOrNameArg, "")), email = "", favorite = false, android = BaresipService.contactsMode == "android", @@ -288,8 +288,10 @@ private fun ContactScreen( } val onEdit: () -> Unit = { - if (screenState.isBaresipContact) - screenState = screenState.copy(isEditing = true) + if (screenState.isBaresipContact) { + val uris = screenState.uris.ifEmpty { listOf(Contact.ContactUri("", "")) } + screenState = screenState.copy(isEditing = true, uris = uris) + } else { val intent = Intent(Intent.ACTION_EDIT).apply { val contactUri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, screenState.id) @@ -908,16 +910,10 @@ private fun checkOnClick( 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() if (newName == "") newName = if (newUris.isNotEmpty()) newUris[0].uri.substringAfter(":") else currentState.email + if (!Utils.checkName(newName)) { alertTitle.value = ctx.getString(R.string.notice) alertMessage.value = String.format(ctx.getString(R.string.invalid_contact), newName) diff --git a/app/src/main/kotlin/com/tutpro/baresip/ContactsScreen.kt b/app/src/main/kotlin/com/tutpro/baresip/ContactsScreen.kt index d3de8a09..26ffb2bb 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/ContactsScreen.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/ContactsScreen.kt @@ -241,7 +241,7 @@ private fun ContactsScreen(navController: NavController) { photoBase64 = line.substringAfter(":").trim() } line.startsWith("END:VCARD", ignoreCase = true) -> { - if (name.isNotEmpty() && (uris.isNotEmpty() || email.isNotEmpty())) { + if (name.isNotEmpty()) { val existingContact = newBaresipContacts.find { it.name == name } val contactId = existingContact?.id ?: (System.currentTimeMillis() + contactNo++) if (photoBase64.isNotEmpty())