move contact source filtering in a different function

This commit is contained in:
tibbi
2020-04-26 21:01:51 +02:00
parent f40285f672
commit 4b8ea90443
2 changed files with 20 additions and 13 deletions

View File

@ -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<RadioItem>()
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)
}
}
}

View File

@ -740,6 +740,20 @@ class ContactsHelper(val context: Context) {
return ArrayList(sources)
}
fun getSaveableContactSources(callback: (ArrayList<ContactSource>) -> 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<ContactSource>
callback(filteredSources)
}
}
fun getDeviceContactSources(): LinkedHashSet<ContactSource> {
val sources = LinkedHashSet<ContactSource>()
if (!context.hasContactPermissions()) {