Skip to content

Commit cfa9bda

Browse files
committed
properly handle transforming contact source names to public names
1 parent cb7e281 commit cfa9bda

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Activity.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,25 +65,26 @@ fun SimpleActivity.showContactSourcePicker(currentSource: String, callback: (new
6565
)
6666

6767
val items = ArrayList<RadioItem>()
68-
val sources = it.filter { !ignoredTypes.contains(it.type) }.map { it.name }
69-
var currentSourceIndex = -1
68+
val filteredSources = it.filter { !ignoredTypes.contains(it.type) }
69+
var sources = filteredSources.map { it.name }
70+
var currentSourceIndex = sources.indexOfFirst { it == currentSource }
71+
sources = filteredSources.map { it.publicName }
72+
7073
sources.forEachIndexed { index, account ->
7174
var publicAccount = account
7275
if (account == config.localAccountName) {
7376
publicAccount = getString(R.string.phone_storage)
7477
}
7578

7679
items.add(RadioItem(index, publicAccount))
77-
if (account == currentSource) {
78-
currentSourceIndex = index
79-
} else if (currentSource == SMT_PRIVATE && account == getString(R.string.phone_storage_hidden)) {
80+
if (currentSource == SMT_PRIVATE && account == getString(R.string.phone_storage_hidden)) {
8081
currentSourceIndex = index
8182
}
8283
}
8384

8485
runOnUiThread {
8586
RadioGroupDialog(this, items, currentSourceIndex) {
86-
callback(sources[it as Int])
87+
callback(filteredSources[it as Int].name)
8788
}
8889
}
8990
}

app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Context.kt

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import android.content.Intent
77
import android.database.Cursor
88
import android.net.Uri
99
import android.os.Build
10+
import android.os.Handler
11+
import android.os.Looper
1012
import android.provider.BlockedNumberContract
1113
import android.provider.BlockedNumberContract.BlockedNumbers
1214
import android.provider.ContactsContract
@@ -194,12 +196,26 @@ fun Context.getPhotoThumbnailSize(): Int {
194196
fun Context.hasContactPermissions() = hasPermission(PERMISSION_READ_CONTACTS) && hasPermission(PERMISSION_WRITE_CONTACTS)
195197

196198
fun Context.getPublicContactSource(source: String, callback: (String) -> Unit) {
197-
val newSource = when (source) {
198-
config.localAccountName -> getString(R.string.phone_storage)
199-
SMT_PRIVATE -> getString(R.string.phone_storage_hidden)
200-
else -> source
199+
when (source) {
200+
config.localAccountName -> callback(getString(R.string.phone_storage))
201+
SMT_PRIVATE -> callback(getString(R.string.phone_storage_hidden))
202+
else -> {
203+
Thread {
204+
ContactsHelper(this).getContactSources {
205+
var newSource = source
206+
for (contactSource in it) {
207+
if (contactSource.name == source && contactSource.type == TELEGRAM_PACKAGE) {
208+
newSource += " (${getString(R.string.telegram)})"
209+
break
210+
}
211+
}
212+
Handler(Looper.getMainLooper()).post {
213+
callback(newSource)
214+
}
215+
}
216+
}.start()
217+
}
201218
}
202-
callback(newSource)
203219
}
204220

205221
fun Context.sendSMSToContacts(contacts: ArrayList<Contact>) {

0 commit comments

Comments
 (0)