Keep phone numbers as-is in contact views + fixed prefix not set when creating/connecting an username based linphone SIP account

This commit is contained in:
Sylvain Berfini 2021-11-08 12:14:18 +01:00
parent 264865fdc3
commit 909911b81b
3 changed files with 30 additions and 1 deletions

View file

@ -25,6 +25,7 @@ import org.linphone.R
import org.linphone.core.* import org.linphone.core.*
import org.linphone.core.tools.Log import org.linphone.core.tools.Log
import org.linphone.utils.Event import org.linphone.utils.Event
import org.linphone.utils.PhoneNumberUtils
class AccountLoginViewModelFactory(private val accountCreator: AccountCreator) : class AccountLoginViewModelFactory(private val accountCreator: AccountCreator) :
ViewModelProvider.NewInstanceFactory() { ViewModelProvider.NewInstanceFactory() {
@ -220,6 +221,18 @@ class AccountLoginViewModel(accountCreator: AccountCreator) : AbstractPhoneViewM
proxyConfig.isPushNotificationAllowed = true proxyConfig.isPushNotificationAllowed = true
if (proxyConfig.dialPrefix.isNullOrEmpty()) {
val dialPlan = PhoneNumberUtils.getDialPlanForCurrentCountry(coreContext.context)
if (dialPlan != null) {
Log.i("[Assistant] [Account Login] Found dial plan country ${dialPlan.country} with international prefix ${dialPlan.countryCallingCode}")
proxyConfig.edit()
proxyConfig.dialPrefix = dialPlan.countryCallingCode
proxyConfig.done()
} else {
Log.w("[Assistant] [Account Login] Failed to find dial plan")
}
}
Log.i("[Assistant] [Account Login] Proxy config created") Log.i("[Assistant] [Account Login] Proxy config created")
return true return true
} }

View file

@ -22,11 +22,13 @@ package org.linphone.activities.assistant.viewmodels
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import org.linphone.LinphoneApplication
import org.linphone.core.AccountCreator import org.linphone.core.AccountCreator
import org.linphone.core.AccountCreatorListenerStub import org.linphone.core.AccountCreatorListenerStub
import org.linphone.core.ProxyConfig import org.linphone.core.ProxyConfig
import org.linphone.core.tools.Log import org.linphone.core.tools.Log
import org.linphone.utils.Event import org.linphone.utils.Event
import org.linphone.utils.PhoneNumberUtils
class EmailAccountValidationViewModelFactory(private val accountCreator: AccountCreator) : class EmailAccountValidationViewModelFactory(private val accountCreator: AccountCreator) :
ViewModelProvider.NewInstanceFactory() { ViewModelProvider.NewInstanceFactory() {
@ -106,6 +108,18 @@ class EmailAccountValidationViewModel(val accountCreator: AccountCreator) : View
proxyConfig.isPushNotificationAllowed = true proxyConfig.isPushNotificationAllowed = true
if (proxyConfig.dialPrefix.isNullOrEmpty()) {
val dialPlan = PhoneNumberUtils.getDialPlanForCurrentCountry(LinphoneApplication.coreContext.context)
if (dialPlan != null) {
Log.i("[Assistant] [Account Validation] Found dial plan country ${dialPlan.country} with international prefix ${dialPlan.countryCallingCode}")
proxyConfig.edit()
proxyConfig.dialPrefix = dialPlan.countryCallingCode
proxyConfig.done()
} else {
Log.w("[Assistant] [Account Validation] Failed to find dial plan")
}
}
Log.i("[Assistant] [Account Validation] Proxy config created") Log.i("[Assistant] [Account Validation] Proxy config created")
return true return true
} }

View file

@ -424,8 +424,10 @@ class CorePreferences constructor(private val context: Context) {
val fetchContactsFromDefaultDirectory: Boolean val fetchContactsFromDefaultDirectory: Boolean
get() = config.getBool("app", "fetch_contacts_from_default_directory", true) get() = config.getBool("app", "fetch_contacts_from_default_directory", true)
// From Android Contact APIs we can also retrieve the internationalized phone number
// By default we display the same value as the native address book app
val preferNormalizedPhoneNumbersFromAddressBook: Boolean val preferNormalizedPhoneNumbersFromAddressBook: Boolean
get() = config.getBool("app", "prefer_normalized_phone_numbers_from_address_book", true) get() = config.getBool("app", "prefer_normalized_phone_numbers_from_address_book", false)
val hideStaticImageCamera: Boolean val hideStaticImageCamera: Boolean
get() = config.getBool("app", "hide_static_image_camera", true) get() = config.getBool("app", "hide_static_image_camera", true)