mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-06-05 21:59:27 +02:00
properly handle transforming contact source names to public names
This commit is contained in:
@ -65,8 +65,11 @@ fun SimpleActivity.showContactSourcePicker(currentSource: String, callback: (new
|
|||||||
)
|
)
|
||||||
|
|
||||||
val items = ArrayList<RadioItem>()
|
val items = ArrayList<RadioItem>()
|
||||||
val sources = it.filter { !ignoredTypes.contains(it.type) }.map { it.name }
|
val filteredSources = it.filter { !ignoredTypes.contains(it.type) }
|
||||||
var currentSourceIndex = -1
|
var sources = filteredSources.map { it.name }
|
||||||
|
var currentSourceIndex = sources.indexOfFirst { it == currentSource }
|
||||||
|
sources = filteredSources.map { it.publicName }
|
||||||
|
|
||||||
sources.forEachIndexed { index, account ->
|
sources.forEachIndexed { index, account ->
|
||||||
var publicAccount = account
|
var publicAccount = account
|
||||||
if (account == config.localAccountName) {
|
if (account == config.localAccountName) {
|
||||||
@ -74,16 +77,14 @@ fun SimpleActivity.showContactSourcePicker(currentSource: String, callback: (new
|
|||||||
}
|
}
|
||||||
|
|
||||||
items.add(RadioItem(index, publicAccount))
|
items.add(RadioItem(index, publicAccount))
|
||||||
if (account == currentSource) {
|
if (currentSource == SMT_PRIVATE && account == getString(R.string.phone_storage_hidden)) {
|
||||||
currentSourceIndex = index
|
|
||||||
} else if (currentSource == SMT_PRIVATE && account == getString(R.string.phone_storage_hidden)) {
|
|
||||||
currentSourceIndex = index
|
currentSourceIndex = index
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
RadioGroupDialog(this, items, currentSourceIndex) {
|
RadioGroupDialog(this, items, currentSourceIndex) {
|
||||||
callback(sources[it as Int])
|
callback(filteredSources[it as Int].name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,8 @@ import android.content.Intent
|
|||||||
import android.database.Cursor
|
import android.database.Cursor
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
|
import android.os.Handler
|
||||||
|
import android.os.Looper
|
||||||
import android.provider.BlockedNumberContract
|
import android.provider.BlockedNumberContract
|
||||||
import android.provider.BlockedNumberContract.BlockedNumbers
|
import android.provider.BlockedNumberContract.BlockedNumbers
|
||||||
import android.provider.ContactsContract
|
import android.provider.ContactsContract
|
||||||
@ -194,13 +196,27 @@ fun Context.getPhotoThumbnailSize(): Int {
|
|||||||
fun Context.hasContactPermissions() = hasPermission(PERMISSION_READ_CONTACTS) && hasPermission(PERMISSION_WRITE_CONTACTS)
|
fun Context.hasContactPermissions() = hasPermission(PERMISSION_READ_CONTACTS) && hasPermission(PERMISSION_WRITE_CONTACTS)
|
||||||
|
|
||||||
fun Context.getPublicContactSource(source: String, callback: (String) -> Unit) {
|
fun Context.getPublicContactSource(source: String, callback: (String) -> Unit) {
|
||||||
val newSource = when (source) {
|
when (source) {
|
||||||
config.localAccountName -> getString(R.string.phone_storage)
|
config.localAccountName -> callback(getString(R.string.phone_storage))
|
||||||
SMT_PRIVATE -> getString(R.string.phone_storage_hidden)
|
SMT_PRIVATE -> callback(getString(R.string.phone_storage_hidden))
|
||||||
else -> source
|
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)
|
callback(newSource)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}.start()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun Context.sendSMSToContacts(contacts: ArrayList<Contact>) {
|
fun Context.sendSMSToContacts(contacts: ArrayList<Contact>) {
|
||||||
val numbers = StringBuilder()
|
val numbers = StringBuilder()
|
||||||
|
Reference in New Issue
Block a user