mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-02-07 14:58:24 +00:00
Change contacts list filter function depending on whether the default account is a Linphone account in secure mode or something else
This commit is contained in:
parent
f70ab87952
commit
0db1754603
5 changed files with 78 additions and 14 deletions
|
|
@ -283,6 +283,7 @@ class ContactsListFragment : AbstractTopBarFragment() {
|
|||
false
|
||||
)
|
||||
popupView.seeAllSelected = listViewModel.areAllContactsDisplayed()
|
||||
popupView.showLinphoneFilter = listViewModel.isDefaultAccountLinphone.value == true
|
||||
|
||||
val popupWindow = PopupWindow(
|
||||
popupView.root,
|
||||
|
|
@ -293,14 +294,30 @@ class ContactsListFragment : AbstractTopBarFragment() {
|
|||
|
||||
popupView.setNoFilterClickListener {
|
||||
if (!listViewModel.areAllContactsDisplayed()) {
|
||||
listViewModel.changeContactsFilter(onlyLinphoneContacts = false)
|
||||
listViewModel.changeContactsFilter(
|
||||
onlyLinphoneContacts = false,
|
||||
onlySipContacts = false
|
||||
)
|
||||
}
|
||||
popupWindow.dismiss()
|
||||
}
|
||||
|
||||
popupView.setLinphoneOnlyClickListener {
|
||||
if (listViewModel.areAllContactsDisplayed()) {
|
||||
listViewModel.changeContactsFilter(onlyLinphoneContacts = true)
|
||||
listViewModel.changeContactsFilter(
|
||||
onlyLinphoneContacts = true,
|
||||
onlySipContacts = false
|
||||
)
|
||||
}
|
||||
popupWindow.dismiss()
|
||||
}
|
||||
|
||||
popupView.setSipOnlyClickListener {
|
||||
if (listViewModel.areAllContactsDisplayed()) {
|
||||
listViewModel.changeContactsFilter(
|
||||
onlyLinphoneContacts = false,
|
||||
onlySipContacts = true
|
||||
)
|
||||
}
|
||||
popupWindow.dismiss()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,12 +57,14 @@ class ContactsListViewModel @UiThread constructor() : AbstractTopBarViewModel()
|
|||
|
||||
val isListFiltered = MutableLiveData<Boolean>()
|
||||
|
||||
val isDefaultAccountLinphone = MutableLiveData<Boolean>()
|
||||
|
||||
val vCardTerminatedEvent: MutableLiveData<Event<Pair<String, File>>> by lazy {
|
||||
MutableLiveData<Event<Pair<String, File>>>()
|
||||
}
|
||||
|
||||
private var previousFilter = "NotSet"
|
||||
private var limitSearchToLinphoneAccounts = true
|
||||
private var domainFilter = ""
|
||||
|
||||
private lateinit var magicSearch: MagicSearch
|
||||
|
||||
|
|
@ -84,7 +86,7 @@ class ContactsListViewModel @UiThread constructor() : AbstractTopBarViewModel()
|
|||
|
||||
applyFilter(
|
||||
currentFilter,
|
||||
if (limitSearchToLinphoneAccounts) corePreferences.defaultDomain else ""
|
||||
domainFilter
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -93,8 +95,7 @@ class ContactsListViewModel @UiThread constructor() : AbstractTopBarViewModel()
|
|||
showFavourites.value = true
|
||||
|
||||
coreContext.postOnCoreThread { core ->
|
||||
val defaultAccount = core.defaultAccount
|
||||
limitSearchToLinphoneAccounts = defaultAccount?.isInSecureMode() ?: false
|
||||
updateDomainFilter()
|
||||
|
||||
coreContext.contactsManager.addListener(contactsListener)
|
||||
magicSearch = core.createMagicSearch()
|
||||
|
|
@ -120,29 +121,34 @@ class ContactsListViewModel @UiThread constructor() : AbstractTopBarViewModel()
|
|||
coreContext.postOnCoreThread {
|
||||
applyFilter(
|
||||
currentFilter,
|
||||
if (limitSearchToLinphoneAccounts) corePreferences.defaultDomain else ""
|
||||
domainFilter
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@UiThread
|
||||
fun applyCurrentDefaultAccountFilter() {
|
||||
coreContext.postOnCoreThread { core ->
|
||||
val defaultAccount = core.defaultAccount
|
||||
limitSearchToLinphoneAccounts = defaultAccount?.isInSecureMode() ?: false
|
||||
coreContext.postOnCoreThread {
|
||||
updateDomainFilter()
|
||||
}
|
||||
|
||||
applyFilter(currentFilter)
|
||||
}
|
||||
|
||||
@UiThread
|
||||
fun changeContactsFilter(onlyLinphoneContacts: Boolean) {
|
||||
limitSearchToLinphoneAccounts = onlyLinphoneContacts
|
||||
fun changeContactsFilter(onlyLinphoneContacts: Boolean, onlySipContacts: Boolean) {
|
||||
domainFilter = if (onlyLinphoneContacts) {
|
||||
corePreferences.defaultDomain
|
||||
} else if (onlySipContacts) {
|
||||
"*"
|
||||
} else {
|
||||
""
|
||||
}
|
||||
applyFilter(currentFilter)
|
||||
}
|
||||
|
||||
fun areAllContactsDisplayed(): Boolean {
|
||||
return !limitSearchToLinphoneAccounts
|
||||
return domainFilter.isEmpty()
|
||||
}
|
||||
|
||||
@UiThread
|
||||
|
|
@ -150,6 +156,19 @@ class ContactsListViewModel @UiThread constructor() : AbstractTopBarViewModel()
|
|||
showFavourites.value = showFavourites.value == false
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
private fun updateDomainFilter() {
|
||||
val defaultAccount = coreContext.core.defaultAccount
|
||||
isDefaultAccountLinphone.postValue(
|
||||
defaultAccount?.isInSecureMode() == true && defaultAccount.params.domain == corePreferences.defaultDomain
|
||||
)
|
||||
domainFilter = if (defaultAccount?.isInSecureMode() == true) {
|
||||
corePreferences.defaultDomain
|
||||
} else {
|
||||
"*"
|
||||
}
|
||||
}
|
||||
|
||||
@UiThread
|
||||
fun exportContactAsVCard(friend: Friend) {
|
||||
coreContext.postOnCoreThread {
|
||||
|
|
|
|||
|
|
@ -12,9 +12,15 @@
|
|||
<variable
|
||||
name="linphoneOnlyClickListener"
|
||||
type="View.OnClickListener" />
|
||||
<variable
|
||||
name="sipOnlyClickListener"
|
||||
type="View.OnClickListener" />
|
||||
<variable
|
||||
name="seeAllSelected"
|
||||
type="Boolean" />
|
||||
<variable
|
||||
name="showLinphoneFilter"
|
||||
type="Boolean" />
|
||||
</data>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
|
|
@ -52,12 +58,32 @@
|
|||
android:text="@string/contacts_list_filter_popup_see_linphone_only"
|
||||
android:textSize="14sp"
|
||||
android:textColor="?attr/color_main2_500"
|
||||
android:visibility="@{showLinphoneFilter ? View.VISIBLE : View.GONE}"
|
||||
android:drawablePadding="5dp"
|
||||
android:drawableEnd="@drawable/check"
|
||||
android:drawableTint="@{seeAllSelected ? @color/transparent_color : @color/green_success_500, default=@color/green_success_500}"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/no_filter"
|
||||
app:layout_constraintBottom_toTopOf="@id/sip_filter"/>
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
style="@style/default_text_style"
|
||||
android:id="@+id/sip_filter"
|
||||
android:onClick="@{sipOnlyClickListener}"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/popup_menu_item_top_margin"
|
||||
android:text="@string/contacts_list_filter_popup_see_sip_only"
|
||||
android:textSize="14sp"
|
||||
android:textColor="?attr/color_main2_500"
|
||||
android:visibility="@{showLinphoneFilter ? View.GONE : View.VISIBLE}"
|
||||
android:drawablePadding="5dp"
|
||||
android:drawableEnd="@drawable/check"
|
||||
android:drawableTint="@{seeAllSelected ? @color/transparent_color : @color/green_success_500, default=@color/green_success_500}"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/linphone_filter"
|
||||
app:layout_constraintBottom_toTopOf="@id/bottom_anchor"/>
|
||||
|
||||
<View
|
||||
|
|
@ -68,7 +94,7 @@
|
|||
app:layout_constraintWidth_max="@dimen/popup_menu_width"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/linphone_filter"
|
||||
app:layout_constraintTop_toBottomOf="@id/sip_filter"
|
||||
app:layout_constraintBottom_toBottomOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
|
|
|||
|
|
@ -312,6 +312,7 @@
|
|||
<string name="contacts_list_all_contacts_title">Tous les contacts</string>
|
||||
<string name="contacts_list_filter_popup_see_all">Voir tous les contacts</string>
|
||||
<string name="contacts_list_filter_popup_see_linphone_only">Voir les contacts &appName;</string>
|
||||
<string name="contacts_list_filter_popup_see_sip_only">Voir les contacts SIP</string>
|
||||
|
||||
<string name="contact_new_title">Nouveau contact</string>
|
||||
<string name="contact_edit_title">Modifier contact</string>
|
||||
|
|
|
|||
|
|
@ -359,6 +359,7 @@
|
|||
<string name="contacts_list_all_contacts_title">All contacts</string>
|
||||
<string name="contacts_list_filter_popup_see_all">See all</string>
|
||||
<string name="contacts_list_filter_popup_see_linphone_only">See &appName; contacts</string>
|
||||
<string name="contacts_list_filter_popup_see_sip_only">See SIP contacts</string>
|
||||
|
||||
<string name="contact_new_title">New contact</string>
|
||||
<string name="contact_edit_title">Edit contact</string>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue