fix #278, add an option to show only contacts with phone numbers

This commit is contained in:
tibbi 2018-10-27 15:16:00 +02:00
parent cdba101edd
commit 169b658d41
6 changed files with 52 additions and 3 deletions

View File

@ -35,6 +35,7 @@ class SettingsActivity : SimpleActivity() {
setupShowInfoBubble()
setupShowContactThumbnails()
setupShowPhoneNumbers()
setupShowContactsWithNumbers()
setupStartNameWithSurname()
setupUse24HourTimeFormat()
setupFilterDuplicates()
@ -110,6 +111,14 @@ class SettingsActivity : SimpleActivity() {
}
}
private fun setupShowContactsWithNumbers() {
settings_show_only_contacts_with_numbers.isChecked = config.showOnlyContactsWithNumbers
settings_show_only_contacts_with_numbers_holder.setOnClickListener {
settings_show_only_contacts_with_numbers.toggle()
config.showOnlyContactsWithNumbers = settings_show_only_contacts_with_numbers.isChecked
}
}
private fun setupStartNameWithSurname() {
settings_start_with_surname.isChecked = config.startNameWithSurname
settings_start_with_surname_holder.setOnClickListener {

View File

@ -104,7 +104,7 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
}
if (config.lastUsedContactSource.isEmpty()) {
val grouped = contacts.groupBy { it.source }.maxWith(compareBy { it.value.size })
val grouped = contacts.asSequence().groupBy { it.source }.maxWith(compareBy { it.value.size })
config.lastUsedContactSource = grouped?.key ?: ""
}
@ -154,7 +154,7 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
}
}
storedGroups = storedGroups.sortedWith(compareBy { it.title }).toMutableList() as ArrayList<Group>
storedGroups = storedGroups.asSequence().sortedWith(compareBy { it.title }).toMutableList() as ArrayList<Group>
fragment_placeholder_2.beVisibleIf(storedGroups.isEmpty())
fragment_placeholder.beVisibleIf(storedGroups.isEmpty())

View File

@ -20,6 +20,10 @@ class Config(context: Context) : BaseConfig(context) {
get() = prefs.getBoolean(SHOW_PHONE_NUMBERS, false)
set(showPhoneNumbers) = prefs.edit().putBoolean(SHOW_PHONE_NUMBERS, showPhoneNumbers).apply()
var showOnlyContactsWithNumbers: Boolean
get() = prefs.getBoolean(SHOW_ONLY_CONTACTS_WITH_NUMBERS, false)
set(showOnlyContactsWithNumbers) = prefs.edit().putBoolean(SHOW_ONLY_CONTACTS_WITH_NUMBERS, showOnlyContactsWithNumbers).apply()
var startNameWithSurname: Boolean
get() = prefs.getBoolean(START_NAME_WITH_SURNAME, false)
set(startNameWithSurname) = prefs.edit().putBoolean(START_NAME_WITH_SURNAME, startNameWithSurname).apply()

View File

@ -5,6 +5,7 @@ import android.provider.ContactsContract.CommonDataKinds
// shared prefs
const val SHOW_CONTACT_THUMBNAILS = "show_contact_thumbnails"
const val SHOW_PHONE_NUMBERS = "show_phone_numbers"
const val SHOW_ONLY_CONTACTS_WITH_NUMBERS = "show_only_contacts_with_numbers"
const val IGNORED_CONTACT_SOURCES = "ignored_contact_sources"
const val START_NAME_WITH_SURNAME = "start_name_with_surname"
const val LAST_USED_CONTACT_SOURCE = "last_used_contact_source"

View File

@ -43,9 +43,20 @@ class ContactsHelper(val activity: Activity) {
}
val contactsSize = contacts.size()
val showOnlyContactsWithNumbers = activity.config.showOnlyContactsWithNumbers
var tempContacts = ArrayList<Contact>(contactsSize)
val resultContacts = ArrayList<Contact>(contactsSize)
(0 until contactsSize).mapTo(tempContacts) { contacts.valueAt(it) }
(0 until contactsSize).filter {
if (showOnlyContactsWithNumbers) {
contacts.valueAt(it).phoneNumbers.isNotEmpty()
} else {
true
}
}.mapTo(tempContacts) {
contacts.valueAt(it)
}
if (activity.config.filterDuplicates) {
tempContacts = tempContacts.distinctBy {
it.getHashToCompare()

View File

@ -220,6 +220,30 @@
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_show_only_contacts_with_numbers_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/medium_margin"
android:background="?attr/selectableItemBackground"
android:paddingLeft="@dimen/normal_margin"
android:paddingTop="@dimen/activity_margin"
android:paddingRight="@dimen/normal_margin"
android:paddingBottom="@dimen/activity_margin">
<com.simplemobiletools.commons.views.MySwitchCompat
android:id="@+id/settings_show_only_contacts_with_numbers"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:clickable="false"
android:paddingStart="@dimen/medium_margin"
android:paddingLeft="@dimen/medium_margin"
android:text="@string/show_only_contacts_with_numbers"
app:switchPadding="@dimen/medium_margin"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_start_with_surname_holder"
android:layout_width="match_parent"