Added setting to hide contacts without SIP address nor phone number

This commit is contained in:
Sylvain Berfini 2025-05-30 10:09:56 +02:00
parent 4cb83980ba
commit d212b7b06e
6 changed files with 54 additions and 1 deletions

View file

@ -224,6 +224,13 @@ class CorePreferences
config.setBool("ui", "sort_contacts_by_first_name", value)
}
@get:WorkerThread
var hideContactsWithoutPhoneNumberOrSipAddress: Boolean
get() = config.getBool("ui", "hide_contacts_without_phone_number_or_sip_address", false)
set(value) {
config.setBool("ui", "hide_contacts_without_phone_number_or_sip_address", value)
}
@get:WorkerThread @set:WorkerThread
var contactsFilter: String
get() = config.getString("ui", "contacts_filter", "")!! // Default value must be empty!

View file

@ -276,10 +276,16 @@ class ContactsListViewModel
val favouritesList = arrayListOf<ContactAvatarModel>()
var count = 0
val collator = Collator.getInstance(Locale.getDefault())
val hideEmptyContacts = corePreferences.hideContactsWithoutPhoneNumberOrSipAddress
for (result in results) {
val friend = result.friend
if (friend != null) {
if (hideEmptyContacts && friend.addresses.isEmpty() && friend.phoneNumbers.isEmpty()) {
Log.i("$TAG Friend [${friend.name}] has no SIP address nor phone number, do not show it")
continue
}
if (friend.refKey.orEmpty().isEmpty()) {
if (friend.vcard != null) {
friend.vcard?.generateUniqueId()

View file

@ -110,6 +110,7 @@ class SettingsViewModel
AppUtils.getString(R.string.contact_editor_last_name),
)
val sortContactsByValues = arrayListOf(0, 1)
val hideEmptyContacts = MutableLiveData<Boolean>()
val ldapAvailable = MutableLiveData<Boolean>()
val ldapServers = MutableLiveData<List<CardDavLdapModel>>()
@ -339,6 +340,7 @@ class SettingsViewModel
)
sortContactsBy.postValue(if (corePreferences.sortContactsByFirstName) 0 else 1)
hideEmptyContacts.postValue(corePreferences.hideContactsWithoutPhoneNumberOrSipAddress)
defaultLayout.postValue(core.defaultConferenceLayout.toInt())
@ -565,6 +567,15 @@ class SettingsViewModel
}
}
@UiThread
fun toggleHideEmptyContacts() {
val newValue = hideEmptyContacts.value == false
coreContext.postOnCoreThread {
corePreferences.hideContactsWithoutPhoneNumberOrSipAddress = newValue
hideEmptyContacts.postValue(newValue)
}
}
@UiThread
fun addLdapServer() {
addLdapServerEvent.value = Event(true)

View file

@ -61,6 +61,33 @@
app:layout_constraintBottom_toBottomOf="@id/sort_contacts_by_first_name_spinner"
app:layout_constraintEnd_toEndOf="@id/sort_contacts_by_first_name_spinner"/>
<androidx.appcompat.widget.AppCompatTextView
style="@style/settings_title_style"
android:onClick="@{() -> viewModel.toggleLogcat()}"
android:id="@+id/hide_empty_contacts_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="10dp"
android:text="@string/settings_contacts_hide_empty_contacts_title"
android:maxLines="2"
android:ellipsize="end"
app:layout_constraintTop_toTopOf="@id/hide_empty_contacts_switch"
app:layout_constraintBottom_toBottomOf="@id/hide_empty_contacts_switch"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/hide_empty_contacts_switch"/>
<com.google.android.material.materialswitch.MaterialSwitch
style="@style/material_switch_style"
android:id="@+id/hide_empty_contacts_switch"
android:onClick="@{() -> viewModel.toggleHideEmptyContacts()}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginEnd="16dp"
android:checked="@{viewModel.hideEmptyContacts}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/sort_contacts_by_first_name_spinner" />
<androidx.appcompat.widget.AppCompatTextView
style="@style/settings_title_style"
@ -78,7 +105,7 @@
android:drawableEnd="@drawable/caret_right"
android:drawableTint="?attr/color_main2_600"
android:visibility="@{viewModel.ldapAvailable ? View.VISIBLE : View.GONE}"
app:layout_constraintTop_toBottomOf="@id/sort_contacts_by_first_name_spinner"
app:layout_constraintTop_toBottomOf="@id/hide_empty_contacts_switch"
app:layout_constraintBottom_toTopOf="@id/existing_ldap_servers"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>

View file

@ -208,6 +208,7 @@
<string name="settings_conversations_mark_as_read_when_dismissing_notif_title">Marquer la conversation comme lue lorsqu\'une notification de message est supprimée</string>
<string name="settings_contacts_title">Contacts</string>
<string name="settings_contacts_sort_by_first_name_title">Trier les contacts par</string>
<string name="settings_contacts_hide_empty_contacts_title">Masquer les contacts sans adresse SIP ni numéro de téléphone</string>
<string name="settings_contacts_add_ldap_server_title">Ajouter un serveur LDAP</string>
<string name="settings_contacts_edit_ldap_server_title">Editer le serveur LDAP</string>
<string name="settings_contacts_add_carddav_server_title">Ajouter un carnet d\'adresse CardDAV</string>

View file

@ -248,6 +248,7 @@
<string name="settings_conversations_mark_as_read_when_dismissing_notif_title">Mark conversation as read when dismissing message notification</string>
<string name="settings_contacts_title">Contacts</string>
<string name="settings_contacts_sort_by_first_name_title">Sort contacts by</string>
<string name="settings_contacts_hide_empty_contacts_title">Hide contacts without SIP address nor phone number</string>
<string name="settings_contacts_add_ldap_server_title">Add LDAP server</string>
<string name="settings_contacts_edit_ldap_server_title">Edit LDAP server</string>
<string name="settings_contacts_add_carddav_server_title">Add CardDAV address book</string>