properly handle transforming contact source names to public names

This commit is contained in:
tibbi 2018-12-28 16:06:40 +01:00
parent cb7e281051
commit cfa9bdaf7a
2 changed files with 28 additions and 11 deletions

View File

@ -65,8 +65,11 @@ fun SimpleActivity.showContactSourcePicker(currentSource: String, callback: (new
)
val items = ArrayList<RadioItem>()
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)
}
}
}

View File

@ -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<Contact>) {