From 52f784686734bba754a44fa6644a9376bb73ff38 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 3 Apr 2021 22:14:36 +0200 Subject: [PATCH] allow selecting phoneNumberless private contacts too --- app/build.gradle | 2 +- .../contacts/pro/activities/MainActivity.kt | 5 +---- .../pro/contentproviders/MyContactsContentProvider.kt | 5 ++++- .../contacts/pro/helpers/LocalContactsHelper.kt | 8 +++++--- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index d8b701e3..19a6fd0e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -56,7 +56,7 @@ android { } dependencies { - implementation 'com.github.SimpleMobileTools:Simple-Commons:11624254b2' + implementation 'com.github.SimpleMobileTools:Simple-Commons:5cec51606a' implementation 'joda-time:joda-time:2.10.3' implementation 'com.googlecode.ez-vcard:ez-vcard:0.10.5' implementation 'com.github.tibbi:IndicatorFastScroll:c3de1d040a' diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/MainActivity.kt index b1e93870..b97ea0f0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/MainActivity.kt @@ -34,10 +34,7 @@ import com.simplemobiletools.contacts.pro.extensions.config import com.simplemobiletools.contacts.pro.extensions.getTempFile import com.simplemobiletools.contacts.pro.extensions.handleGenericContactClick import com.simplemobiletools.contacts.pro.fragments.MyViewPagerFragment -import com.simplemobiletools.contacts.pro.helpers.ALL_TABS_MASK -import com.simplemobiletools.contacts.pro.helpers.ContactsHelper -import com.simplemobiletools.contacts.pro.helpers.VcfExporter -import com.simplemobiletools.contacts.pro.helpers.tabsList +import com.simplemobiletools.contacts.pro.helpers.* import com.simplemobiletools.contacts.pro.interfaces.RefreshContactsListener import com.simplemobiletools.contacts.pro.models.Contact import kotlinx.android.synthetic.main.activity_main.* diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/contentproviders/MyContactsContentProvider.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/contentproviders/MyContactsContentProvider.kt index ca2bfd19..5511ea4b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/contentproviders/MyContactsContentProvider.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/contentproviders/MyContactsContentProvider.kt @@ -27,7 +27,10 @@ class MyContactsContentProvider : ContentProvider() { MyContactsContentProvider.COL_ANNIVERSARIES) ) - LocalContactsHelper(context!!).getPrivateSimpleContactsSync(selection == MyContactsContentProvider.FAVORITES_ONLY).forEach { + val favoritesOnly = selectionArgs?.getOrNull(0)?.equals("1") ?: false + val withPhoneNumbersOnly = selectionArgs?.getOrNull(1)?.equals("1") ?: true + + LocalContactsHelper(context!!).getPrivateSimpleContactsSync(favoritesOnly, withPhoneNumbersOnly).forEach { val phoneNumbers = Gson().toJson(it.phoneNumbers) val birthdays = Gson().toJson(it.birthdays) val anniversaries = Gson().toJson(it.anniversaries) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/LocalContactsHelper.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/LocalContactsHelper.kt index b3fbeb61..4cf73ee5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/LocalContactsHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/LocalContactsHelper.kt @@ -159,8 +159,8 @@ class LocalContactsHelper(val context: Context) { } } - private fun convertContactToSimpleContact(contact: Contact?): SimpleContact? { - return if (contact == null || contact.phoneNumbers.isEmpty()) { + private fun convertContactToSimpleContact(contact: Contact?, withPhoneNumbersOnly: Boolean): SimpleContact? { + return if (contact == null || (withPhoneNumbersOnly && contact.phoneNumbers.isEmpty())) { null } else { val phoneNumbers = contact.phoneNumbers.map { it.value }.toMutableList() as ArrayList @@ -170,5 +170,7 @@ class LocalContactsHelper(val context: Context) { } } - fun getPrivateSimpleContactsSync(favoritesOnly: Boolean) = getAllContacts(favoritesOnly).mapNotNull { convertContactToSimpleContact(it) } + fun getPrivateSimpleContactsSync(favoritesOnly: Boolean, withPhoneNumbersOnly: Boolean) = getAllContacts(favoritesOnly).mapNotNull { + convertContactToSimpleContact(it, withPhoneNumbersOnly) + } }