Allow for no selected dial plan in Account's profile

This commit is contained in:
Sylvain Berfini 2023-12-22 11:43:59 +01:00
parent 8fb87b18e8
commit ac7e19144d
2 changed files with 30 additions and 7 deletions

View file

@ -59,11 +59,19 @@ class AccountProfileFragment : GenericFragment() {
private val dropdownListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
val dialPlan = viewModel.dialPlansList[position]
Log.i(
"$TAG Selected dialplan updated [+${dialPlan.countryCallingCode}] / [${dialPlan.country}]"
)
viewModel.setDialPlan(dialPlan)
if (position == 0) {
Log.i("$TAG Removing selected dial plan")
viewModel.removeDialPlan()
viewModel.selectedDialPlan.value = 0
} else {
val index = position - 1
val dialPlan = viewModel.dialPlansList[index]
Log.i(
"$TAG Selected dialplan updated [+${dialPlan.countryCallingCode}] / [${dialPlan.country}]"
)
viewModel.setDialPlan(dialPlan)
viewModel.selectedDialPlan.value = index
}
}
override fun onNothingSelected(parent: AdapterView<*>?) {

View file

@ -53,6 +53,8 @@ class AccountProfileViewModel @UiThread constructor() : ViewModel() {
expandDevices.value = false // TODO: set to true when feature will be available
coreContext.postOnCoreThread {
dialPlansLabelList.add("") // To allow removing selected dial plan
val dialPlans = Factory.instance().dialPlans.toList()
for (dialPlan in dialPlans) {
dialPlansList.add(dialPlan)
@ -121,7 +123,7 @@ class AccountProfileViewModel @UiThread constructor() : ViewModel() {
it.countryCallingCode == prefix
}
if (dialPlan != null) {
val index = dialPlansList.indexOf(dialPlan)
val index = dialPlansList.indexOf(dialPlan) + 1
Log.i(
"$TAG Found matching dial plan [${dialPlan.country}] at index [$index]"
)
@ -238,7 +240,20 @@ class AccountProfileViewModel @UiThread constructor() : ViewModel() {
copy.internationalPrefix = dialPlan.countryCallingCode
account.params = copy
Log.i(
"$TAG Updated internation prefix for account [${account.params.identityAddress?.asStringUriOnly()}] to [${copy.internationalPrefix}]"
"$TAG Updated international prefix for account [${account.params.identityAddress?.asStringUriOnly()}] to [${copy.internationalPrefix}]"
)
}
}
@UiThread
fun removeDialPlan() {
coreContext.postOnCoreThread {
val params = account.params
val copy = params.clone()
copy.internationalPrefix = ""
account.params = copy
Log.i(
"$TAG Removed international prefix for account [${account.params.identityAddress?.asStringUriOnly()}]"
)
}
}