mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +00:00
Display currently selected country flag
This commit is contained in:
parent
cb20acfa52
commit
f4566ce812
8 changed files with 32 additions and 30 deletions
|
|
@ -131,9 +131,9 @@ class LoginFragment : Fragment() {
|
|||
}
|
||||
|
||||
coreContext.postOnCoreThread {
|
||||
val prefix = PhoneNumberUtils.getDeviceInternationalPrefix(requireContext())
|
||||
if (!prefix.isNullOrEmpty()) {
|
||||
viewModel.internationalPrefix.postValue(prefix)
|
||||
val dialPlan = PhoneNumberUtils.getDeviceDialPlan(requireContext())
|
||||
if (dialPlan != null) {
|
||||
viewModel.internationalPrefix.postValue(dialPlan.countryCallingCode)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -148,9 +148,9 @@ class RegisterFragment : Fragment() {
|
|||
}
|
||||
|
||||
coreContext.postOnCoreThread {
|
||||
val prefix = PhoneNumberUtils.getDeviceInternationalPrefix(requireContext())
|
||||
if (!prefix.isNullOrEmpty()) {
|
||||
viewModel.internationalPrefix.postValue("+$prefix")
|
||||
val dialPlan = PhoneNumberUtils.getDeviceDialPlan(requireContext())
|
||||
if (dialPlan != null) {
|
||||
viewModel.setDialPlan(dialPlan)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -119,9 +119,9 @@ class ThirdPartySipAccountLoginFragment : Fragment() {
|
|||
}
|
||||
|
||||
coreContext.postOnCoreThread {
|
||||
val prefix = PhoneNumberUtils.getDeviceInternationalPrefix(requireContext())
|
||||
if (!prefix.isNullOrEmpty()) {
|
||||
viewModel.internationalPrefix.postValue(prefix)
|
||||
val dialPlan = PhoneNumberUtils.getDeviceDialPlan(requireContext())
|
||||
if (dialPlan != null) {
|
||||
viewModel.internationalPrefix.postValue(dialPlan.countryCallingCode)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,6 +64,8 @@ class AccountCreationViewModel @UiThread constructor() : ViewModel(), CountryPic
|
|||
|
||||
val phoneNumberError = MutableLiveData<String>()
|
||||
|
||||
val selectedDialPlan = MutableLiveData<DialPlan>()
|
||||
|
||||
val internationalPrefix = MutableLiveData<String>()
|
||||
|
||||
val showPassword = MutableLiveData<Boolean>()
|
||||
|
|
@ -267,7 +269,6 @@ class AccountCreationViewModel @UiThread constructor() : ViewModel(), CountryPic
|
|||
}
|
||||
|
||||
init {
|
||||
internationalPrefix.value = "+1"
|
||||
operationInProgress.value = false
|
||||
|
||||
coreContext.postOnCoreThread { core ->
|
||||
|
|
@ -284,7 +285,7 @@ class AccountCreationViewModel @UiThread constructor() : ViewModel(), CountryPic
|
|||
createEnabled.addSource(password) {
|
||||
createEnabled.value = isCreateButtonEnabled()
|
||||
}
|
||||
createEnabled.addSource(internationalPrefix) {
|
||||
createEnabled.addSource(selectedDialPlan) {
|
||||
createEnabled.value = isCreateButtonEnabled()
|
||||
}
|
||||
createEnabled.addSource(phoneNumber) {
|
||||
|
|
@ -294,7 +295,14 @@ class AccountCreationViewModel @UiThread constructor() : ViewModel(), CountryPic
|
|||
|
||||
@UiThread
|
||||
override fun onCountryClicked(dialPlan: DialPlan) {
|
||||
internationalPrefix.value = "+${dialPlan.countryCallingCode}"
|
||||
coreContext.postOnCoreThread {
|
||||
setDialPlan(dialPlan)
|
||||
}
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
fun setDialPlan(dialPlan: DialPlan) {
|
||||
internationalPrefix.postValue("${dialPlan.flag} +${dialPlan.countryCallingCode}")
|
||||
}
|
||||
|
||||
@UiThread
|
||||
|
|
@ -314,7 +322,8 @@ class AccountCreationViewModel @UiThread constructor() : ViewModel(), CountryPic
|
|||
fun confirmPhoneNumber() {
|
||||
coreContext.postOnCoreThread {
|
||||
if (::accountCreator.isInitialized) {
|
||||
val prefix = internationalPrefix.value.orEmpty().trim()
|
||||
val dialPlan = selectedDialPlan.value
|
||||
val prefix = dialPlan?.internationalCallPrefix.orEmpty()
|
||||
val digitsPrefix = if (prefix.startsWith("+")) {
|
||||
prefix.substring(1)
|
||||
} else {
|
||||
|
|
@ -412,7 +421,7 @@ class AccountCreationViewModel @UiThread constructor() : ViewModel(), CountryPic
|
|||
|
||||
@UiThread
|
||||
private fun isCreateButtonEnabled(): Boolean {
|
||||
return username.value.orEmpty().isNotEmpty() && password.value.orEmpty().isNotEmpty() && phoneNumber.value.orEmpty().isNotEmpty() && internationalPrefix.value.orEmpty().isNotEmpty()
|
||||
return username.value.orEmpty().isNotEmpty() && password.value.orEmpty().isNotEmpty() && phoneNumber.value.orEmpty().isNotEmpty() && selectedDialPlan.value?.internationalCallPrefix.orEmpty().isNotEmpty()
|
||||
}
|
||||
|
||||
@UiThread
|
||||
|
|
|
|||
|
|
@ -29,8 +29,6 @@ class AccountProfileViewModel @UiThread constructor() : ViewModel() {
|
|||
|
||||
val devices = MutableLiveData<ArrayList<AccountDeviceModel>>()
|
||||
|
||||
val internationalPrefix = MutableLiveData<String>()
|
||||
|
||||
val accountFoundEvent = MutableLiveData<Event<Boolean>>()
|
||||
|
||||
val expandDetails = MutableLiveData<Boolean>()
|
||||
|
|
@ -74,7 +72,6 @@ class AccountProfileViewModel @UiThread constructor() : ViewModel() {
|
|||
|
||||
sipAddress.postValue(account.params.identityAddress?.asStringUriOnly())
|
||||
displayName.postValue(account.params.identityAddress?.displayName)
|
||||
internationalPrefix.postValue(account.params.internationalPrefix)
|
||||
|
||||
val devicesList = arrayListOf<AccountDeviceModel>()
|
||||
// TODO FIXME: use real devices list from API
|
||||
|
|
@ -152,8 +149,6 @@ class AccountProfileViewModel @UiThread constructor() : ViewModel() {
|
|||
val params = account.params
|
||||
val copy = params.clone()
|
||||
|
||||
copy.internationalPrefix = internationalPrefix.value.orEmpty()
|
||||
|
||||
val address = params.identityAddress?.clone()
|
||||
if (address != null) {
|
||||
val newValue = displayName.value.orEmpty().trim()
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ import androidx.core.view.doOnLayout
|
|||
import androidx.databinding.BindingAdapter
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import androidx.databinding.ViewDataBinding
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.lifecycle.findViewTreeLifecycleOwner
|
||||
import coil.load
|
||||
import coil.transform.CircleCropTransformation
|
||||
|
|
@ -54,8 +55,6 @@ import org.linphone.BR
|
|||
import org.linphone.R
|
||||
import org.linphone.core.ConsolidatedPresence
|
||||
import org.linphone.core.tools.Log
|
||||
import org.linphone.ui.call.CallActivity
|
||||
import org.linphone.ui.main.MainActivity
|
||||
import org.linphone.ui.main.contacts.model.ContactAvatarModel
|
||||
import org.linphone.ui.main.model.AccountModel
|
||||
|
||||
|
|
@ -84,10 +83,8 @@ fun <T> setEntries(
|
|||
binding.setVariable(BR.model, entry)
|
||||
|
||||
// This is a bit hacky...
|
||||
if (viewGroup.context as? MainActivity != null) {
|
||||
binding.lifecycleOwner = viewGroup.context as MainActivity
|
||||
} else if (viewGroup.context as? CallActivity != null) {
|
||||
binding.lifecycleOwner = viewGroup.context as CallActivity
|
||||
if (viewGroup.context as? LifecycleOwner != null) {
|
||||
binding.lifecycleOwner = viewGroup.context as LifecycleOwner
|
||||
} else {
|
||||
Log.e(
|
||||
"[Data Binding Utils] Failed to cast viewGroup's context as an Activity, lifecycle owner hasn't be set!"
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import android.provider.ContactsContract
|
|||
import android.telephony.TelephonyManager
|
||||
import androidx.annotation.AnyThread
|
||||
import androidx.annotation.WorkerThread
|
||||
import org.linphone.core.DialPlan
|
||||
import org.linphone.core.Factory
|
||||
import org.linphone.core.tools.Log
|
||||
|
||||
|
|
@ -33,7 +34,7 @@ class PhoneNumberUtils {
|
|||
private const val TAG = "[Phone Number Utils]"
|
||||
|
||||
@WorkerThread
|
||||
fun getDeviceInternationalPrefix(context: Context): String? {
|
||||
fun getDeviceDialPlan(context: Context): DialPlan? {
|
||||
val telephonyManager = context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
|
||||
val countryIso = telephonyManager.networkCountryIso
|
||||
for (dp in Factory.instance().dialPlans) {
|
||||
|
|
@ -42,7 +43,7 @@ class PhoneNumberUtils {
|
|||
Log.i(
|
||||
"$TAG Found matching entry [$prefix] in dialplan for network country iso [$countryIso]"
|
||||
)
|
||||
return prefix
|
||||
return dp
|
||||
}
|
||||
}
|
||||
return null
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@
|
|||
android:id="@+id/phone_number"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="50dp"
|
||||
android:paddingStart="95dp"
|
||||
android:paddingStart="115dp"
|
||||
android:paddingEnd="20dp"
|
||||
android:text="@={viewModel.phoneNumber, default=`6 01 02 03 04 05`}"
|
||||
android:textSize="14sp"
|
||||
|
|
@ -155,10 +155,10 @@
|
|||
android:onClick="@{showCountryPickerClickListener}"
|
||||
style="@style/default_text_style"
|
||||
android:id="@+id/prefix"
|
||||
android:layout_width="90dp"
|
||||
android:layout_width="110dp"
|
||||
android:layout_height="0dp"
|
||||
android:paddingStart="20dp"
|
||||
android:text="@{viewModel.internationalPrefix, default=`+33`}"
|
||||
android:text="@{viewModel.internationalPrefix, default=`🇫🇷 +33`}"
|
||||
android:textSize="14sp"
|
||||
android:textColor="@color/gray_main2_600"
|
||||
android:gravity="center_vertical"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue