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 cda4b77a..8f416c21 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 @@ -65,8 +65,11 @@ fun SimpleActivity.showContactSourcePicker(currentSource: String, callback: (new ) val items = ArrayList() - val sources = it.filter { !ignoredTypes.contains(it.type) }.map { it.name } - var currentSourceIndex = -1 + 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 } + sources.forEachIndexed { index, account -> var publicAccount = account if (account == config.localAccountName) { @@ -74,16 +77,14 @@ fun SimpleActivity.showContactSourcePicker(currentSource: String, callback: (new } items.add(RadioItem(index, publicAccount)) - if (account == currentSource) { - currentSourceIndex = index - } else if (currentSource == SMT_PRIVATE && account == getString(R.string.phone_storage_hidden)) { + if (currentSource == SMT_PRIVATE && account == getString(R.string.phone_storage_hidden)) { currentSourceIndex = index } } runOnUiThread { RadioGroupDialog(this, items, currentSourceIndex) { - callback(sources[it as Int]) + callback(filteredSources[it as Int].name) } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Context.kt index 1b99392e..2d57f5b2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Context.kt @@ -7,6 +7,8 @@ import android.content.Intent import android.database.Cursor import android.net.Uri import android.os.Build +import android.os.Handler +import android.os.Looper import android.provider.BlockedNumberContract import android.provider.BlockedNumberContract.BlockedNumbers import android.provider.ContactsContract @@ -194,12 +196,26 @@ fun Context.getPhotoThumbnailSize(): Int { fun Context.hasContactPermissions() = hasPermission(PERMISSION_READ_CONTACTS) && hasPermission(PERMISSION_WRITE_CONTACTS) fun Context.getPublicContactSource(source: String, callback: (String) -> Unit) { - val newSource = when (source) { - config.localAccountName -> getString(R.string.phone_storage) - SMT_PRIVATE -> getString(R.string.phone_storage_hidden) - else -> source + when (source) { + config.localAccountName -> callback(getString(R.string.phone_storage)) + SMT_PRIVATE -> callback(getString(R.string.phone_storage_hidden)) + else -> { + Thread { + ContactsHelper(this).getContactSources { + var newSource = source + for (contactSource in it) { + if (contactSource.name == source && contactSource.type == TELEGRAM_PACKAGE) { + newSource += " (${getString(R.string.telegram)})" + break + } + } + Handler(Looper.getMainLooper()).post { + callback(newSource) + } + } + }.start() + } } - callback(newSource) } fun Context.sendSMSToContacts(contacts: ArrayList) {