Disable save contact if no firstname or lastname is set + when adding contact from call history, pre-propulate SIP address

This commit is contained in:
Sylvain Berfini 2023-08-22 11:05:42 +02:00
parent 5ebaf24c04
commit 14d1726a7f
10 changed files with 50 additions and 5 deletions

View file

@ -26,6 +26,10 @@
<entry name="stun_server" overwrite="true">stun.linphone.org</entry>
<entry name="protocols" overwrite="true">stun,ice</entry>
</section>
<section name="sip">
<entry name="media_encryption" overwrite="true">zrtp</entry>
<entry name="media_encryption_mandatory" overwrite="true">1</entry>
</section>
<section name="net">
<entry name="friendlist_subscription_enabled" overwrite="true">1</entry>
</section>

View file

@ -34,7 +34,6 @@ log_collection_upload_server_url=https://www.linphone.org:444/lft.php
file_transfer_server_url=https://www.linphone.org:444/lft.php
version_check_url_root=https://www.linphone.org/releases
max_calls=10
history_max_size=100
conference_layout=1
## End of default rc

View file

@ -139,6 +139,7 @@ class CallFragment : GenericFragment() {
popupView.setAddToContactsListener {
// TODO: go to new contact fragment
sharedViewModel.sipAddressToAddToNewContact = viewModel.callLogModel.value?.displayedAddress.orEmpty()
sharedViewModel.navigateToContactsEvent.value = Event(true)
sharedViewModel.showNewContactEvent.value = Event(true)
popupWindow.dismiss()

View file

@ -34,6 +34,7 @@ import androidx.navigation.fragment.findNavController
import androidx.navigation.navGraphViewModels
import kotlinx.coroutines.launch
import org.linphone.BR
import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.R
import org.linphone.core.tools.Log
import org.linphone.databinding.ContactNewOrEditFragmentBinding
@ -98,6 +99,14 @@ class NewContactFragment : GenericFragment() {
viewModel.findFriendByRefKey("")
val addressToAdd = sharedViewModel.sipAddressToAddToNewContact
if (addressToAdd.isNotEmpty()) {
sharedViewModel.sipAddressToAddToNewContact = ""
coreContext.postOnCoreThread {
viewModel.addSipAddress(addressToAdd)
}
}
binding.setBackClickListener {
val model = ConfirmationDialogModel()
val dialog = DialogUtils.getCancelContactChangesConfirmationDialog(

View file

@ -21,6 +21,7 @@ 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
@ -54,6 +55,8 @@ class ContactNewOrEditViewModel @UiThread constructor() : ViewModel() {
val jobTitle = MutableLiveData<String>()
val saveButtonEnabled = MediatorLiveData<Boolean>()
val saveChangesEvent: MutableLiveData<Event<String>> by lazy {
MutableLiveData<Event<String>>()
}
@ -64,6 +67,16 @@ 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?) {
coreContext.postOnCoreThread { core ->
@ -179,7 +192,7 @@ class ContactNewOrEditViewModel @UiThread constructor() : ViewModel() {
}
@WorkerThread
private fun addSipAddress(address: String = "", requestFieldToBeAddedInUi: Boolean = false) {
fun addSipAddress(address: String = "", requestFieldToBeAddedInUi: Boolean = false) {
val newModel = NewOrEditNumberOrAddressModel(address, true, {
if (address.isEmpty()) {
addSipAddress(requestFieldToBeAddedInUi = true)
@ -219,4 +232,9 @@ class ContactNewOrEditViewModel @UiThread constructor() : ViewModel() {
}
removeNewNumberOrAddressFieldEvent.value = Event(model)
}
@UiThread
private fun isSaveButtonEnabled(): Boolean {
return firstName.value.orEmpty().isNotEmpty() || lastName.value.orEmpty().isNotEmpty()
}
}

View file

@ -37,6 +37,7 @@ import org.linphone.ui.main.contacts.model.ContactNumberOrAddressModel
import org.linphone.ui.main.model.isInSecureMode
import org.linphone.utils.Event
import org.linphone.utils.FileUtils
import org.linphone.utils.PhoneNumberUtils
class ContactViewModel @UiThread constructor() : ViewModel() {
companion object {
@ -165,13 +166,17 @@ class ContactViewModel @UiThread constructor() : ViewModel() {
// phone numbers are disabled is secure mode
val enablePhoneNumbers = core.defaultAccount?.isInSecureMode() != true
val address = core.interpretUrl(number.phoneNumber, true)
val label = PhoneNumberUtils.vcardParamStringToAddressBookLabel(
coreContext.context.resources,
number.label ?: ""
)
val data = ContactNumberOrAddressModel(
address,
number.phoneNumber,
enablePhoneNumbers,
listener,
false,
label = number.label.orEmpty()
label
)
addressesAndNumbers.add(data)
}

View file

@ -67,6 +67,8 @@ class SharedMainViewModel @UiThread constructor() : ViewModel() {
MutableLiveData<Event<Boolean>>()
}
var sipAddressToAddToNewContact: String = ""
/* Call logs related */
val showCallLogEvent: MutableLiveData<Event<String>> by lazy {

View file

@ -28,6 +28,7 @@ import android.view.ViewGroup
import android.view.Window
import android.view.inputmethod.InputMethodManager
import android.widget.ImageView
import androidx.annotation.ColorInt
import androidx.annotation.UiThread
import androidx.appcompat.widget.AppCompatEditText
import androidx.appcompat.widget.AppCompatTextView
@ -148,7 +149,7 @@ fun AppCompatTextView.setTypeface(typeface: Int) {
@UiThread
@BindingAdapter("android:drawableTint")
fun AppCompatTextView.setDrawableTint(color: Int) {
fun AppCompatTextView.setDrawableTint(@ColorInt color: Int) {
for (drawable in compoundDrawablesRelative) {
drawable?.setTint(color)
}

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:color="@color/primary_color_disabled"/>
<item android:color="@color/primary_color"/>
</selector>

View file

@ -58,7 +58,8 @@
android:layout_marginEnd="10dp"
android:padding="5dp"
android:src="@drawable/check"
app:tint="@color/primary_color"
android:enabled="@{viewModel.saveButtonEnabled}"
app:tint="@color/primary_color_selector"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="@id/title"
app:layout_constraintTop_toTopOf="@id/title" />