diff --git a/app/src/main/java/org/linphone/ui/main/contacts/viewmodel/ContactNewOrEditViewModel.kt b/app/src/main/java/org/linphone/ui/main/contacts/viewmodel/ContactNewOrEditViewModel.kt index 4f5bb5758..b4c39ed73 100644 --- a/app/src/main/java/org/linphone/ui/main/contacts/viewmodel/ContactNewOrEditViewModel.kt +++ b/app/src/main/java/org/linphone/ui/main/contacts/viewmodel/ContactNewOrEditViewModel.kt @@ -21,7 +21,6 @@ package org.linphone.ui.main.contacts.viewmodel import androidx.annotation.UiThread import androidx.annotation.WorkerThread -import androidx.lifecycle.MediatorLiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import org.linphone.LinphoneApplication.Companion.coreContext @@ -57,8 +56,6 @@ class ContactNewOrEditViewModel @UiThread constructor() : ViewModel() { val jobTitle = MutableLiveData() - val saveButtonEnabled = MediatorLiveData() - val saveChangesEvent: MutableLiveData> by lazy { MutableLiveData>() } @@ -69,16 +66,6 @@ class ContactNewOrEditViewModel @UiThread constructor() : ViewModel() { val removeNewNumberOrAddressFieldEvent = MutableLiveData>() - init { - saveButtonEnabled.value = isSaveButtonEnabled() - saveButtonEnabled.addSource(firstName) { - saveButtonEnabled.value = isSaveButtonEnabled() - } - saveButtonEnabled.addSource(lastName) { - saveButtonEnabled.value = isSaveButtonEnabled() - } - } - @UiThread fun findFriendByRefKey(refKey: String?) { reset() @@ -129,6 +116,22 @@ class ContactNewOrEditViewModel @UiThread constructor() : ViewModel() { @UiThread fun saveChanges() { + var check = true + if (firstName.value.orEmpty().isEmpty()) { + Log.e("$TAG Firstname is empty") + check = false + } + 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") + return + } + // TODO FIXME: notify user + coreContext.postOnCoreThread { core -> var status = Status.OK @@ -207,7 +210,6 @@ class ContactNewOrEditViewModel @UiThread constructor() : ViewModel() { core.addFriendList(fl) } status = fl.addFriend(friend) - Log.e("UPDATE SUB") fl.updateSubscriptions() } else { friend.done() @@ -263,11 +265,6 @@ class ContactNewOrEditViewModel @UiThread constructor() : ViewModel() { removeNewNumberOrAddressFieldEvent.value = Event(model) } - @UiThread - private fun isSaveButtonEnabled(): Boolean { - return firstName.value.orEmpty().isNotEmpty() || lastName.value.orEmpty().isNotEmpty() - } - @UiThread private fun reset() { isEdit.value = false @@ -278,6 +275,5 @@ class ContactNewOrEditViewModel @UiThread constructor() : ViewModel() { phoneNumbers.clear() company.value = "" jobTitle.value = "" - saveButtonEnabled.value = false } } diff --git a/app/src/main/res/layout/contact_new_or_edit_fragment.xml b/app/src/main/res/layout/contact_new_or_edit_fragment.xml index 76c4ab6b4..33773ed53 100644 --- a/app/src/main/res/layout/contact_new_or_edit_fragment.xml +++ b/app/src/main/res/layout/contact_new_or_edit_fragment.xml @@ -57,7 +57,6 @@ android:layout_marginEnd="10dp" android:padding="5dp" android:src="@drawable/check" - android:enabled="@{viewModel.saveButtonEnabled}" app:tint="@color/primary_color_selector" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintBottom_toBottomOf="@id/title"