mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-06-05 21:59:27 +02:00
move contact source filtering in a different function
This commit is contained in:
@ -55,20 +55,13 @@ fun SimpleActivity.startCall(contact: Contact) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun SimpleActivity.showContactSourcePicker(currentSource: String, callback: (newSource: String) -> Unit) {
|
fun SimpleActivity.showContactSourcePicker(currentSource: String, callback: (newSource: String) -> Unit) {
|
||||||
ContactsHelper(this).getContactSources {
|
ContactsHelper(this).getSaveableContactSources { sources ->
|
||||||
val ignoredTypes = arrayListOf(
|
|
||||||
SIGNAL_PACKAGE,
|
|
||||||
TELEGRAM_PACKAGE,
|
|
||||||
WHATSAPP_PACKAGE
|
|
||||||
)
|
|
||||||
|
|
||||||
val items = ArrayList<RadioItem>()
|
val items = ArrayList<RadioItem>()
|
||||||
val filteredSources = it.filter { !ignoredTypes.contains(it.type) }
|
var sourceNames = sources.map { it.name }
|
||||||
var sources = filteredSources.map { it.name }
|
var currentSourceIndex = sourceNames.indexOfFirst { it == currentSource }
|
||||||
var currentSourceIndex = sources.indexOfFirst { it == currentSource }
|
sourceNames = sources.map { it.publicName }
|
||||||
sources = filteredSources.map { it.publicName }
|
|
||||||
|
|
||||||
sources.forEachIndexed { index, account ->
|
sourceNames.forEachIndexed { index, account ->
|
||||||
items.add(RadioItem(index, account))
|
items.add(RadioItem(index, account))
|
||||||
if (currentSource == SMT_PRIVATE && account == getString(R.string.phone_storage_hidden)) {
|
if (currentSource == SMT_PRIVATE && account == getString(R.string.phone_storage_hidden)) {
|
||||||
currentSourceIndex = index
|
currentSourceIndex = index
|
||||||
@ -77,7 +70,7 @@ fun SimpleActivity.showContactSourcePicker(currentSource: String, callback: (new
|
|||||||
|
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
RadioGroupDialog(this, items, currentSourceIndex) {
|
RadioGroupDialog(this, items, currentSourceIndex) {
|
||||||
callback(filteredSources[it as Int].name)
|
callback(sources[it as Int].name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -740,6 +740,20 @@ class ContactsHelper(val context: Context) {
|
|||||||
return ArrayList(sources)
|
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> {
|
fun getDeviceContactSources(): LinkedHashSet<ContactSource> {
|
||||||
val sources = LinkedHashSet<ContactSource>()
|
val sources = LinkedHashSet<ContactSource>()
|
||||||
if (!context.hasContactPermissions()) {
|
if (!context.hasContactPermissions()) {
|
||||||
|
Reference in New Issue
Block a user