mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-04-28 13:46:21 +00:00
Updated contact editor to allow creating a contact with only a organization name
This commit is contained in:
parent
c7b4c14d66
commit
e618992fb5
1 changed files with 18 additions and 16 deletions
|
|
@ -132,21 +132,14 @@ class ContactNewOrEditViewModel @UiThread constructor() : ViewModel() {
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
fun saveChanges() {
|
fun saveChanges() {
|
||||||
var check = true
|
val fn = firstName.value.orEmpty().trim()
|
||||||
if (firstName.value.orEmpty().isEmpty()) {
|
val ln = lastName.value.orEmpty().trim()
|
||||||
Log.e("$TAG Firstname is empty")
|
val organization = company.value.orEmpty().trim()
|
||||||
check = false
|
if (fn.isEmpty() && ln.isEmpty() && organization.isEmpty()) {
|
||||||
}
|
|
||||||
if (sipAddresses.isEmpty() && phoneNumbers.isEmpty()) {
|
|
||||||
Log.e("$TAG No SIP address nor phone number")
|
|
||||||
check = false
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!check) {
|
|
||||||
Log.e("$TAG At least a mandatory field wasn't filled, aborting save")
|
Log.e("$TAG At least a mandatory field wasn't filled, aborting save")
|
||||||
|
// TODO FIXME: notify user
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// TODO FIXME: notify user
|
|
||||||
|
|
||||||
coreContext.postOnCoreThread { core ->
|
coreContext.postOnCoreThread { core ->
|
||||||
var status = Status.OK
|
var status = Status.OK
|
||||||
|
|
@ -154,11 +147,20 @@ class ContactNewOrEditViewModel @UiThread constructor() : ViewModel() {
|
||||||
if (!::friend.isInitialized) {
|
if (!::friend.isInitialized) {
|
||||||
friend = core.createFriend()
|
friend = core.createFriend()
|
||||||
}
|
}
|
||||||
val fn = firstName.value.orEmpty().trim()
|
val name = if (fn.isNotEmpty() && ln.isNotEmpty()) {
|
||||||
val ln = lastName.value.orEmpty().trim()
|
"$fn $ln"
|
||||||
|
} else if (fn.isNotEmpty()) {
|
||||||
|
fn
|
||||||
|
} else if (ln.isNotEmpty()) {
|
||||||
|
ln
|
||||||
|
} else if (organization.isNotEmpty()) {
|
||||||
|
organization
|
||||||
|
} else {
|
||||||
|
"<Unknown>"
|
||||||
|
}
|
||||||
|
|
||||||
friend.edit()
|
friend.edit()
|
||||||
friend.name = "$fn $ln"
|
friend.name = name
|
||||||
|
|
||||||
val vCard = friend.vcard
|
val vCard = friend.vcard
|
||||||
if (vCard != null) {
|
if (vCard != null) {
|
||||||
|
|
@ -188,7 +190,7 @@ class ContactNewOrEditViewModel @UiThread constructor() : ViewModel() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
friend.organization = company.value.orEmpty().trim()
|
friend.organization = organization
|
||||||
friend.jobTitle = jobTitle.value.orEmpty().trim()
|
friend.jobTitle = jobTitle.value.orEmpty().trim()
|
||||||
|
|
||||||
for (address in friend.addresses) {
|
for (address in friend.addresses) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue