From ab0ea57732044fb49ebc707d5648cb40a699d42e Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 30 Dec 2017 17:53:30 +0100 Subject: [PATCH] apply the contact source filtering to Add Favorite dialog items too --- .../contacts/adapters/ContactsAdapter.kt | 2 +- .../contacts/dialogs/AddFavoritesDialog.kt | 17 +++++++++++------ .../contacts/fragments/FavoritesFragment.kt | 1 + 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/adapters/ContactsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/adapters/ContactsAdapter.kt index d218cab0..b835b1bb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/adapters/ContactsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/adapters/ContactsAdapter.kt @@ -27,8 +27,8 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: MutableList Unit) : MyRecyclerViewAdapter(activity, recyclerView, itemClick) { - var config = activity.config lateinit private var contactDrawable: Drawable + var config = activity.config var startNameWithSurname: Boolean var showPhoneNumbers: Boolean diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/dialogs/AddFavoritesDialog.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/dialogs/AddFavoritesDialog.kt index a9c7dd61..4617a174 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/dialogs/AddFavoritesDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/dialogs/AddFavoritesDialog.kt @@ -11,14 +11,19 @@ import com.simplemobiletools.contacts.models.Contact import kotlinx.android.synthetic.main.dialog_add_favorites.view.* class AddFavoritesDialog(val activity: SimpleActivity, val callback: () -> Unit) { - var dialog: AlertDialog? = null + private var dialog: AlertDialog? = null private var view = activity.layoutInflater.inflate(R.layout.dialog_add_favorites, null) + private val config = activity.config init { ContactsHelper(activity).getContacts { - Contact.sorting = activity.config.sorting - it.sort() - view.add_favorites_list.adapter = AddFavoritesAdapter(activity, it, activity.config.favorites) + var contacts = it + Contact.sorting = config.sorting + contacts.sort() + + val contactSources = config.displayContactSources + contacts = contacts.filter { contactSources.contains(it.source) } as ArrayList + view.add_favorites_list.adapter = AddFavoritesAdapter(activity, contacts, config.favorites) activity.runOnUiThread { dialog = AlertDialog.Builder(activity) @@ -33,8 +38,8 @@ class AddFavoritesDialog(val activity: SimpleActivity, val callback: () -> Unit) private fun dialogConfirmed() { val selectedItems = (view.add_favorites_list.adapter as AddFavoritesAdapter).getSelectedItemsSet() - if (activity.config.favorites != selectedItems) { - activity.config.favorites = selectedItems + if (config.favorites != selectedItems) { + config.favorites = selectedItems callback() } dialog?.dismiss() diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/fragments/FavoritesFragment.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/fragments/FavoritesFragment.kt index cb988fc1..29455601 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/fragments/FavoritesFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/fragments/FavoritesFragment.kt @@ -6,6 +6,7 @@ import com.simplemobiletools.contacts.dialogs.AddFavoritesDialog class FavoritesFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet) { override fun fabClicked() { + finishActMode() showAddFavoritesDialog() }