apply the contact source filtering to Add Favorite dialog items too

This commit is contained in:
tibbi 2017-12-30 17:53:30 +01:00
parent 82a0f8accb
commit ab0ea57732
3 changed files with 13 additions and 7 deletions

View File

@ -27,8 +27,8 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: MutableList<Co
val isFavoritesFragment: Boolean, recyclerView: MyRecyclerView, itemClick: (Any) -> Unit) : val isFavoritesFragment: Boolean, recyclerView: MyRecyclerView, itemClick: (Any) -> Unit) :
MyRecyclerViewAdapter(activity, recyclerView, itemClick) { MyRecyclerViewAdapter(activity, recyclerView, itemClick) {
var config = activity.config
lateinit private var contactDrawable: Drawable lateinit private var contactDrawable: Drawable
var config = activity.config
var startNameWithSurname: Boolean var startNameWithSurname: Boolean
var showPhoneNumbers: Boolean var showPhoneNumbers: Boolean

View File

@ -11,14 +11,19 @@ import com.simplemobiletools.contacts.models.Contact
import kotlinx.android.synthetic.main.dialog_add_favorites.view.* import kotlinx.android.synthetic.main.dialog_add_favorites.view.*
class AddFavoritesDialog(val activity: SimpleActivity, val callback: () -> Unit) { 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 var view = activity.layoutInflater.inflate(R.layout.dialog_add_favorites, null)
private val config = activity.config
init { init {
ContactsHelper(activity).getContacts { ContactsHelper(activity).getContacts {
Contact.sorting = activity.config.sorting var contacts = it
it.sort() Contact.sorting = config.sorting
view.add_favorites_list.adapter = AddFavoritesAdapter(activity, it, activity.config.favorites) contacts.sort()
val contactSources = config.displayContactSources
contacts = contacts.filter { contactSources.contains(it.source) } as ArrayList<Contact>
view.add_favorites_list.adapter = AddFavoritesAdapter(activity, contacts, config.favorites)
activity.runOnUiThread { activity.runOnUiThread {
dialog = AlertDialog.Builder(activity) dialog = AlertDialog.Builder(activity)
@ -33,8 +38,8 @@ class AddFavoritesDialog(val activity: SimpleActivity, val callback: () -> Unit)
private fun dialogConfirmed() { private fun dialogConfirmed() {
val selectedItems = (view.add_favorites_list.adapter as AddFavoritesAdapter).getSelectedItemsSet() val selectedItems = (view.add_favorites_list.adapter as AddFavoritesAdapter).getSelectedItemsSet()
if (activity.config.favorites != selectedItems) { if (config.favorites != selectedItems) {
activity.config.favorites = selectedItems config.favorites = selectedItems
callback() callback()
} }
dialog?.dismiss() dialog?.dismiss()

View File

@ -6,6 +6,7 @@ import com.simplemobiletools.contacts.dialogs.AddFavoritesDialog
class FavoritesFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet) { class FavoritesFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet) {
override fun fabClicked() { override fun fabClicked() {
finishActMode()
showAddFavoritesDialog() showAddFavoritesDialog()
} }