mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-04-22 14:08:30 +00:00
Disable phone numbers if default account is in secure mode
This commit is contained in:
parent
8bba5ea2b6
commit
5ebaf24c04
9 changed files with 60 additions and 30 deletions
|
|
@ -42,6 +42,7 @@ import org.linphone.ui.main.contacts.model.ContactNumberOrAddressModel
|
||||||
import org.linphone.ui.main.contacts.model.NumberOrAddressPickerDialogModel
|
import org.linphone.ui.main.contacts.model.NumberOrAddressPickerDialogModel
|
||||||
import org.linphone.ui.main.contacts.viewmodel.ContactsListViewModel
|
import org.linphone.ui.main.contacts.viewmodel.ContactsListViewModel
|
||||||
import org.linphone.ui.main.fragment.GenericFragment
|
import org.linphone.ui.main.fragment.GenericFragment
|
||||||
|
import org.linphone.ui.main.model.isInSecureMode
|
||||||
import org.linphone.utils.DialogUtils
|
import org.linphone.utils.DialogUtils
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
|
|
@ -154,10 +155,14 @@ class StartCallFragment : GenericFragment() {
|
||||||
val friend = model.friend
|
val friend = model.friend
|
||||||
val addressesCount = friend.addresses.size
|
val addressesCount = friend.addresses.size
|
||||||
val numbersCount = friend.phoneNumbers.size
|
val numbersCount = friend.phoneNumbers.size
|
||||||
if (addressesCount == 1 && numbersCount == 0) {
|
|
||||||
|
// Do not consider phone numbers if default account is in secure mode
|
||||||
|
val enablePhoneNumbers = core.defaultAccount?.isInSecureMode() != true
|
||||||
|
|
||||||
|
if (addressesCount == 1 && (numbersCount == 0 || !enablePhoneNumbers)) {
|
||||||
val address = friend.addresses.first()
|
val address = friend.addresses.first()
|
||||||
coreContext.startCall(address)
|
coreContext.startCall(address)
|
||||||
} else if (addressesCount == 1 && numbersCount == 0) {
|
} else if (addressesCount == 0 && numbersCount == 1 && enablePhoneNumbers) {
|
||||||
val number = friend.phoneNumbers.first()
|
val number = friend.phoneNumbers.first()
|
||||||
val address = core.interpretUrl(number, true)
|
val address = core.interpretUrl(number, true)
|
||||||
if (address != null) {
|
if (address != null) {
|
||||||
|
|
@ -169,23 +174,27 @@ class StartCallFragment : GenericFragment() {
|
||||||
val addressModel = ContactNumberOrAddressModel(
|
val addressModel = ContactNumberOrAddressModel(
|
||||||
address,
|
address,
|
||||||
address.asStringUriOnly(),
|
address.asStringUriOnly(),
|
||||||
|
true,
|
||||||
listener,
|
listener,
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
list.add(addressModel)
|
list.add(addressModel)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (enablePhoneNumbers) {
|
||||||
for (number in friend.phoneNumbersWithLabel) {
|
for (number in friend.phoneNumbersWithLabel) {
|
||||||
val address = core.interpretUrl(number.phoneNumber, true)
|
val address = core.interpretUrl(number.phoneNumber, true)
|
||||||
val addressModel = ContactNumberOrAddressModel(
|
val addressModel = ContactNumberOrAddressModel(
|
||||||
address,
|
address,
|
||||||
number.phoneNumber,
|
number.phoneNumber,
|
||||||
|
true,
|
||||||
listener,
|
listener,
|
||||||
false,
|
false,
|
||||||
number.label.orEmpty()
|
number.label.orEmpty()
|
||||||
)
|
)
|
||||||
list.add(addressModel)
|
list.add(addressModel)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
coreContext.postOnMainThread {
|
coreContext.postOnMainThread {
|
||||||
val model = NumberOrAddressPickerDialogModel(list)
|
val model = NumberOrAddressPickerDialogModel(list)
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ import org.linphone.core.MagicSearchListenerStub
|
||||||
import org.linphone.core.SearchResult
|
import org.linphone.core.SearchResult
|
||||||
import org.linphone.core.tools.Log
|
import org.linphone.core.tools.Log
|
||||||
import org.linphone.ui.main.contacts.model.ContactAvatarModel
|
import org.linphone.ui.main.contacts.model.ContactAvatarModel
|
||||||
|
import org.linphone.ui.main.model.isInSecureMode
|
||||||
|
|
||||||
class SuggestionsListViewModel @UiThread constructor() : ViewModel() {
|
class SuggestionsListViewModel @UiThread constructor() : ViewModel() {
|
||||||
companion object {
|
companion object {
|
||||||
|
|
@ -70,6 +71,9 @@ class SuggestionsListViewModel @UiThread constructor() : ViewModel() {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
coreContext.postOnCoreThread { core ->
|
coreContext.postOnCoreThread { core ->
|
||||||
|
val defaultAccount = core.defaultAccount
|
||||||
|
limitSearchToLinphoneAccounts = defaultAccount?.isInSecureMode() ?: false
|
||||||
|
|
||||||
coreContext.contactsManager.addListener(contactsListener)
|
coreContext.contactsManager.addListener(contactsListener)
|
||||||
magicSearch = core.createMagicSearch()
|
magicSearch = core.createMagicSearch()
|
||||||
magicSearch.limitedSearch = false
|
magicSearch.limitedSearch = false
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ import org.linphone.core.Address
|
||||||
class ContactNumberOrAddressModel @UiThread constructor(
|
class ContactNumberOrAddressModel @UiThread constructor(
|
||||||
val address: Address?,
|
val address: Address?,
|
||||||
val displayedValue: String,
|
val displayedValue: String,
|
||||||
|
val isEnabled: Boolean,
|
||||||
private val listener: ContactNumberOrAddressClickListener,
|
private val listener: ContactNumberOrAddressClickListener,
|
||||||
val isSip: Boolean = true,
|
val isSip: Boolean = true,
|
||||||
val label: String = ""
|
val label: String = ""
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ import org.linphone.ui.main.contacts.model.ContactAvatarModel
|
||||||
import org.linphone.ui.main.contacts.model.ContactDeviceModel
|
import org.linphone.ui.main.contacts.model.ContactDeviceModel
|
||||||
import org.linphone.ui.main.contacts.model.ContactNumberOrAddressClickListener
|
import org.linphone.ui.main.contacts.model.ContactNumberOrAddressClickListener
|
||||||
import org.linphone.ui.main.contacts.model.ContactNumberOrAddressModel
|
import org.linphone.ui.main.contacts.model.ContactNumberOrAddressModel
|
||||||
|
import org.linphone.ui.main.model.isInSecureMode
|
||||||
import org.linphone.utils.Event
|
import org.linphone.utils.Event
|
||||||
import org.linphone.utils.FileUtils
|
import org.linphone.utils.FileUtils
|
||||||
|
|
||||||
|
|
@ -56,9 +57,9 @@ class ContactViewModel @UiThread constructor() : ViewModel() {
|
||||||
|
|
||||||
val showBackButton = MutableLiveData<Boolean>()
|
val showBackButton = MutableLiveData<Boolean>()
|
||||||
|
|
||||||
val showNumbersAndAddresses = MutableLiveData<Boolean>()
|
val expandNumbersAndAddresses = MutableLiveData<Boolean>()
|
||||||
|
|
||||||
val showDevicesTrust = MutableLiveData<Boolean>()
|
val expandDevicesTrust = MutableLiveData<Boolean>()
|
||||||
|
|
||||||
val contactFoundEvent = MutableLiveData<Event<Boolean>>()
|
val contactFoundEvent = MutableLiveData<Event<Boolean>>()
|
||||||
|
|
||||||
|
|
@ -101,8 +102,8 @@ class ContactViewModel @UiThread constructor() : ViewModel() {
|
||||||
private lateinit var friend: Friend
|
private lateinit var friend: Friend
|
||||||
|
|
||||||
init {
|
init {
|
||||||
showNumbersAndAddresses.value = true
|
expandNumbersAndAddresses.value = true
|
||||||
showDevicesTrust.value = false // TODO FIXME: set it to true when it will work for real
|
expandDevicesTrust.value = false // TODO FIXME: set it to true when it will work for real
|
||||||
}
|
}
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
|
|
@ -129,6 +130,7 @@ class ContactViewModel @UiThread constructor() : ViewModel() {
|
||||||
val data = ContactNumberOrAddressModel(
|
val data = ContactNumberOrAddressModel(
|
||||||
address,
|
address,
|
||||||
address.asStringUriOnly(),
|
address.asStringUriOnly(),
|
||||||
|
true, // SIP addresses are always enabled
|
||||||
listener,
|
listener,
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
|
|
@ -151,6 +153,7 @@ class ContactViewModel @UiThread constructor() : ViewModel() {
|
||||||
val data = ContactNumberOrAddressModel(
|
val data = ContactNumberOrAddressModel(
|
||||||
address,
|
address,
|
||||||
address.asStringUriOnly(),
|
address.asStringUriOnly(),
|
||||||
|
true, // SIP addresses are always enabled
|
||||||
listener,
|
listener,
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
|
|
@ -159,10 +162,13 @@ 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 address = core.interpretUrl(number.phoneNumber, true)
|
||||||
val data = ContactNumberOrAddressModel(
|
val data = ContactNumberOrAddressModel(
|
||||||
address,
|
address,
|
||||||
number.phoneNumber,
|
number.phoneNumber,
|
||||||
|
enablePhoneNumbers,
|
||||||
listener,
|
listener,
|
||||||
false,
|
false,
|
||||||
label = number.label.orEmpty()
|
label = number.label.orEmpty()
|
||||||
|
|
@ -172,7 +178,7 @@ class ContactViewModel @UiThread constructor() : ViewModel() {
|
||||||
sipAddressesAndPhoneNumbers.postValue(addressesAndNumbers)
|
sipAddressesAndPhoneNumbers.postValue(addressesAndNumbers)
|
||||||
|
|
||||||
val devicesList = arrayListOf<ContactDeviceModel>()
|
val devicesList = arrayListOf<ContactDeviceModel>()
|
||||||
// TODO FIXME
|
// TODO FIXME: use real devices list from API
|
||||||
devicesList.add(ContactDeviceModel("Pixel 6 Pro de Sylvain", true))
|
devicesList.add(ContactDeviceModel("Pixel 6 Pro de Sylvain", true))
|
||||||
devicesList.add(ContactDeviceModel("Sylvain Galaxy Tab S9 Pro+ Ultra", true))
|
devicesList.add(ContactDeviceModel("Sylvain Galaxy Tab S9 Pro+ Ultra", true))
|
||||||
devicesList.add(ContactDeviceModel("MacBook Pro de Marcel", false))
|
devicesList.add(ContactDeviceModel("MacBook Pro de Marcel", false))
|
||||||
|
|
@ -185,13 +191,13 @@ class ContactViewModel @UiThread constructor() : ViewModel() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
fun toggleNumbersAndAddressesVisibility() {
|
fun toggleNumbersAndAddressesExpand() {
|
||||||
showNumbersAndAddresses.value = showNumbersAndAddresses.value == false
|
expandNumbersAndAddresses.value = expandNumbersAndAddresses.value == false
|
||||||
}
|
}
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
fun toggleDevicesTrustVisibility() {
|
fun toggleDevicesTrustExpand() {
|
||||||
showDevicesTrust.value = showDevicesTrust.value == false
|
expandDevicesTrust.value = expandDevicesTrust.value == false
|
||||||
}
|
}
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ import org.linphone.core.MagicSearchListenerStub
|
||||||
import org.linphone.core.SearchResult
|
import org.linphone.core.SearchResult
|
||||||
import org.linphone.core.tools.Log
|
import org.linphone.core.tools.Log
|
||||||
import org.linphone.ui.main.contacts.model.ContactAvatarModel
|
import org.linphone.ui.main.contacts.model.ContactAvatarModel
|
||||||
|
import org.linphone.ui.main.model.isInSecureMode
|
||||||
|
|
||||||
class ContactsListViewModel @UiThread constructor() : ViewModel() {
|
class ContactsListViewModel @UiThread constructor() : ViewModel() {
|
||||||
companion object {
|
companion object {
|
||||||
|
|
@ -78,6 +79,9 @@ class ContactsListViewModel @UiThread constructor() : ViewModel() {
|
||||||
showFavourites.value = true
|
showFavourites.value = true
|
||||||
|
|
||||||
coreContext.postOnCoreThread { core ->
|
coreContext.postOnCoreThread { core ->
|
||||||
|
val defaultAccount = core.defaultAccount
|
||||||
|
limitSearchToLinphoneAccounts = defaultAccount?.isInSecureMode() ?: false
|
||||||
|
|
||||||
coreContext.contactsManager.addListener(contactsListener)
|
coreContext.contactsManager.addListener(contactsListener)
|
||||||
magicSearch = core.createMagicSearch()
|
magicSearch = core.createMagicSearch()
|
||||||
magicSearch.limitedSearch = false
|
magicSearch.limitedSearch = false
|
||||||
|
|
|
||||||
|
|
@ -119,3 +119,8 @@ fun Account.getPicturePath(): String {
|
||||||
overrideExisting = true
|
overrideExisting = true
|
||||||
).absolutePath
|
).absolutePath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Account.isInSecureMode(): Boolean {
|
||||||
|
// TODO FIXME
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,7 @@
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
app:constraint_referenced_ids="trusted_devices_count, trust_background, trusted_devices_progress, devices, trusted_devices_progress_label"
|
app:constraint_referenced_ids="trusted_devices_count, trust_background, trusted_devices_progress, devices, trusted_devices_progress_label"
|
||||||
android:visibility="@{viewModel.showDevicesTrust ? View.VISIBLE : View.GONE}" />
|
android:visibility="@{viewModel.expandDevicesTrust ? View.VISIBLE : View.GONE}" />
|
||||||
|
|
||||||
<io.getstream.avatarview.AvatarView
|
<io.getstream.avatarview.AvatarView
|
||||||
android:id="@+id/avatar"
|
android:id="@+id/avatar"
|
||||||
|
|
@ -241,7 +241,7 @@
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatTextView
|
<androidx.appcompat.widget.AppCompatTextView
|
||||||
style="@style/default_text_style_800"
|
style="@style/default_text_style_800"
|
||||||
android:onClick="@{() -> viewModel.toggleNumbersAndAddressesVisibility()}"
|
android:onClick="@{() -> viewModel.toggleNumbersAndAddressesExpand()}"
|
||||||
android:id="@+id/numbers_and_addresses_label"
|
android:id="@+id/numbers_and_addresses_label"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|
@ -250,7 +250,7 @@
|
||||||
android:layout_marginEnd="26dp"
|
android:layout_marginEnd="26dp"
|
||||||
android:layout_marginTop="32dp"
|
android:layout_marginTop="32dp"
|
||||||
android:text="Numbers & addresses"
|
android:text="Numbers & addresses"
|
||||||
android:drawableEnd="@{viewModel.showNumbersAndAddresses ? @drawable/collapse : @drawable/expand, default=@drawable/collapse}"
|
android:drawableEnd="@{viewModel.expandNumbersAndAddresses ? @drawable/collapse : @drawable/expand, default=@drawable/collapse}"
|
||||||
android:drawableTint="@color/gray_9"
|
android:drawableTint="@color/gray_9"
|
||||||
android:textSize="16sp"
|
android:textSize="16sp"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
|
@ -259,7 +259,7 @@
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/numbers_and_addresses"
|
android:id="@+id/numbers_and_addresses"
|
||||||
android:visibility="@{viewModel.showNumbersAndAddresses ? View.VISIBLE : View.GONE}"
|
android:visibility="@{viewModel.expandNumbersAndAddresses ? View.VISIBLE : View.GONE}"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
|
|
@ -348,7 +348,7 @@
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatTextView
|
<androidx.appcompat.widget.AppCompatTextView
|
||||||
style="@style/default_text_style_800"
|
style="@style/default_text_style_800"
|
||||||
android:onClick="@{() -> viewModel.toggleDevicesTrustVisibility()}"
|
android:onClick="@{() -> viewModel.toggleDevicesTrustExpand()}"
|
||||||
android:id="@+id/trust_label"
|
android:id="@+id/trust_label"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|
@ -357,7 +357,7 @@
|
||||||
android:layout_marginEnd="26dp"
|
android:layout_marginEnd="26dp"
|
||||||
android:layout_marginTop="16dp"
|
android:layout_marginTop="16dp"
|
||||||
android:text="Trust"
|
android:text="Trust"
|
||||||
android:drawableEnd="@{viewModel.showDevicesTrust ? @drawable/collapse : @drawable/expand, default=@drawable/collapse}"
|
android:drawableEnd="@{viewModel.expandDevicesTrust ? @drawable/collapse : @drawable/expand, default=@drawable/collapse}"
|
||||||
android:drawableTint="@color/gray_9"
|
android:drawableTint="@color/gray_9"
|
||||||
android:textSize="16sp"
|
android:textSize="16sp"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
|
|
||||||
|
|
@ -50,9 +50,10 @@
|
||||||
android:id="@+id/call"
|
android:id="@+id/call"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:src="@drawable/calls"
|
|
||||||
app:tint="@color/gray_9"
|
|
||||||
android:layout_marginEnd="10dp"
|
android:layout_marginEnd="10dp"
|
||||||
|
android:src="@drawable/calls"
|
||||||
|
android:visibility="@{model.enabled ? View.VISIBLE : View.GONE}"
|
||||||
|
app:tint="@color/gray_9"
|
||||||
app:layout_constraintTop_toTopOf="@id/header"
|
app:layout_constraintTop_toTopOf="@id/header"
|
||||||
app:layout_constraintBottom_toBottomOf="@id/number_or_address"
|
app:layout_constraintBottom_toBottomOf="@id/number_or_address"
|
||||||
app:layout_constraintEnd_toEndOf="parent" />
|
app:layout_constraintEnd_toEndOf="parent" />
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue