From ec90f2d41faa3cbe7104fe1d83294c0404f09a81 Mon Sep 17 00:00:00 2001 From: Pavel Poley Date: Fri, 6 May 2022 11:32:55 +0300 Subject: [PATCH] add the contact count dynamically --- .../pro/dialogs/FilterContactSourcesDialog.kt | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/FilterContactSourcesDialog.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/FilterContactSourcesDialog.kt index 11a802c7..ec2008cb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/FilterContactSourcesDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/FilterContactSourcesDialog.kt @@ -22,28 +22,21 @@ class FilterContactSourcesDialog(val activity: SimpleActivity, private val callb private var isContactsReady = false init { - dialog = AlertDialog.Builder(activity) - .setPositiveButton(R.string.ok) { dialogInterface, i -> confirmContactSources() } - .setNegativeButton(R.string.cancel, null) - .create().apply { - activity.setupDialogStuff(view, this) { - ContactsHelper(activity).getContactSources { contactSources -> - contactSources.mapTo(this@FilterContactSourcesDialog.contactSources) { it.copy() } - isContactSourcesReady = true - processDataIfReady() - } + ContactsHelper(activity).getContactSources { contactSources -> + contactSources.mapTo(this@FilterContactSourcesDialog.contactSources) { it.copy() } + isContactSourcesReady = true + processDataIfReady() + } - ContactsHelper(activity).getContacts(getAll = true) { contacts -> - contacts.mapTo(this@FilterContactSourcesDialog.contacts) { it.copy() } - isContactsReady = true - processDataIfReady() - } - } - } + ContactsHelper(activity).getContacts(getAll = true) { contacts -> + contacts.mapTo(this@FilterContactSourcesDialog.contacts) { it.copy() } + isContactsReady = true + processDataIfReady() + } } private fun processDataIfReady() { - if (!isContactSourcesReady || !isContactsReady) { + if (!isContactSourcesReady) { return } @@ -59,6 +52,15 @@ class FilterContactSourcesDialog(val activity: SimpleActivity, private val callb activity.runOnUiThread { val selectedSources = activity.getVisibleContactSources() view.filter_contact_sources_list.adapter = FilterContactSourcesAdapter(activity, contactSourcesWithCount, selectedSources) + + if (dialog == null) { + dialog = AlertDialog.Builder(activity) + .setPositiveButton(R.string.ok) { dialogInterface, i -> confirmContactSources() } + .setNegativeButton(R.string.cancel, null) + .create().apply { + activity.setupDialogStuff(view, this) + } + } } }