diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Activity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Activity.kt index b2962b87..19d4ef1e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Activity.kt @@ -55,20 +55,13 @@ fun SimpleActivity.startCall(contact: Contact) { } fun SimpleActivity.showContactSourcePicker(currentSource: String, callback: (newSource: String) -> Unit) { - ContactsHelper(this).getContactSources { - val ignoredTypes = arrayListOf( - SIGNAL_PACKAGE, - TELEGRAM_PACKAGE, - WHATSAPP_PACKAGE - ) - + ContactsHelper(this).getSaveableContactSources { sources -> val items = ArrayList() - val filteredSources = it.filter { !ignoredTypes.contains(it.type) } - var sources = filteredSources.map { it.name } - var currentSourceIndex = sources.indexOfFirst { it == currentSource } - sources = filteredSources.map { it.publicName } + var sourceNames = sources.map { it.name } + var currentSourceIndex = sourceNames.indexOfFirst { it == currentSource } + sourceNames = sources.map { it.publicName } - sources.forEachIndexed { index, account -> + sourceNames.forEachIndexed { index, account -> items.add(RadioItem(index, account)) if (currentSource == SMT_PRIVATE && account == getString(R.string.phone_storage_hidden)) { currentSourceIndex = index @@ -77,7 +70,7 @@ fun SimpleActivity.showContactSourcePicker(currentSource: String, callback: (new runOnUiThread { RadioGroupDialog(this, items, currentSourceIndex) { - callback(filteredSources[it as Int].name) + callback(sources[it as Int].name) } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/ContactsHelper.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/ContactsHelper.kt index 7706146f..c49cb638 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/ContactsHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/ContactsHelper.kt @@ -740,6 +740,20 @@ class ContactsHelper(val context: Context) { return ArrayList(sources) } + fun getSaveableContactSources(callback: (ArrayList) -> Unit) { + ensureBackgroundThread { + val ignoredTypes = arrayListOf( + SIGNAL_PACKAGE, + TELEGRAM_PACKAGE, + WHATSAPP_PACKAGE + ) + + val contactSources = getContactSourcesSync() + val filteredSources = contactSources.filter { !ignoredTypes.contains(it.type) }.toMutableList() as ArrayList + callback(filteredSources) + } + } + fun getDeviceContactSources(): LinkedHashSet { val sources = LinkedHashSet() if (!context.hasContactPermissions()) {