From f4767421a825e0328397b5237944a3a8f2e68c21 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 19 Mar 2018 22:22:23 +0100 Subject: [PATCH] list proper contacts at the GroupContacts activity --- .../activities/GroupContactsActivity.kt | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/GroupContactsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/GroupContactsActivity.kt index c8d536e7..f277f98f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/GroupContactsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/GroupContactsActivity.kt @@ -1,9 +1,16 @@ package com.simplemobiletools.contacts.activities import android.os.Bundle +import com.simplemobiletools.commons.extensions.toast import com.simplemobiletools.commons.extensions.updateTextColors import com.simplemobiletools.contacts.R -import com.simplemobiletools.contacts.helpers.GROUP +import com.simplemobiletools.contacts.adapters.ContactsAdapter +import com.simplemobiletools.contacts.extensions.config +import com.simplemobiletools.contacts.extensions.editContact +import com.simplemobiletools.contacts.extensions.tryStartCall +import com.simplemobiletools.contacts.extensions.viewContact +import com.simplemobiletools.contacts.helpers.* +import com.simplemobiletools.contacts.models.Contact import com.simplemobiletools.contacts.models.Group import kotlinx.android.synthetic.main.activity_group_contacts.* @@ -15,5 +22,37 @@ class GroupContactsActivity : SimpleActivity() { val group = intent.extras.getSerializable(GROUP) as Group supportActionBar?.title = group.title + + ContactsHelper(this).getContacts { + val contacts = it.filter { it.groups.map { it.id }.contains(group.id) } as ArrayList + updateContacts(contacts) + } + } + + private fun updateContacts(contacts: ArrayList) { + ContactsAdapter(this, contacts, null, false, group_contacts_list, group_contacts_fastscroller) { + when (config.onContactClick) { + ON_CLICK_CALL_CONTACT -> { + val contact = it as Contact + if (contact.phoneNumbers.isNotEmpty()) { + tryStartCall(it) + } else { + toast(R.string.no_phone_number_found) + } + } + ON_CLICK_VIEW_CONTACT -> viewContact(it as Contact) + ON_CLICK_EDIT_CONTACT -> editContact(it as Contact) + } + }.apply { + setupDragListener(true) + addVerticalDividers(true) + group_contacts_list.adapter = this + } + + group_contacts_fastscroller.setScrollTo(0) + group_contacts_fastscroller.setViews(group_contacts_list) { + val item = (group_contacts_list.adapter as ContactsAdapter).contactItems.getOrNull(it) + group_contacts_fastscroller.updateBubbleText(item?.getBubbleText() ?: "") + } } }