mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +00:00
Do not disable save button in contact editor when mandatory fields aren't filled, TODO: notify user
This commit is contained in:
parent
ada4e786ec
commit
78dd449baf
2 changed files with 16 additions and 21 deletions
|
|
@ -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<String>()
|
||||
|
||||
val saveButtonEnabled = MediatorLiveData<Boolean>()
|
||||
|
||||
val saveChangesEvent: MutableLiveData<Event<String>> by lazy {
|
||||
MutableLiveData<Event<String>>()
|
||||
}
|
||||
|
|
@ -69,16 +66,6 @@ class ContactNewOrEditViewModel @UiThread constructor() : ViewModel() {
|
|||
|
||||
val removeNewNumberOrAddressFieldEvent = MutableLiveData<Event<NewOrEditNumberOrAddressModel>>()
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue