refresh GroupContactsActivity on resume

This commit is contained in:
tibbi
2018-03-20 15:34:36 +01:00
parent 6d4f9912fd
commit c572a83bb1
2 changed files with 34 additions and 23 deletions

View File

@ -29,7 +29,6 @@ class GroupContactsActivity : SimpleActivity(), RemoveFromGroupListener {
group = intent.extras.getSerializable(GROUP) as Group group = intent.extras.getSerializable(GROUP) as Group
supportActionBar?.title = group.title supportActionBar?.title = group.title
refreshContacts()
group_contacts_fab.setOnClickListener { group_contacts_fab.setOnClickListener {
SelectContactsDialog(this, allContacts, groupContacts) { addedContacts, removedContacts -> SelectContactsDialog(this, allContacts, groupContacts) { addedContacts, removedContacts ->
ContactsHelper(this).apply { ContactsHelper(this).apply {
@ -41,6 +40,11 @@ class GroupContactsActivity : SimpleActivity(), RemoveFromGroupListener {
} }
} }
override fun onResume() {
super.onResume()
refreshContacts()
}
private fun refreshContacts() { private fun refreshContacts() {
ContactsHelper(this).getContacts { ContactsHelper(this).getContacts {
allContacts = it allContacts = it
@ -54,29 +58,34 @@ class GroupContactsActivity : SimpleActivity(), RemoveFromGroupListener {
} }
private fun updateContacts(contacts: ArrayList<Contact>) { private fun updateContacts(contacts: ArrayList<Contact>) {
ContactsAdapter(this, contacts, null, LOCATION_GROUP_CONTACTS, this, group_contacts_list, group_contacts_fastscroller) { val currAdapter = group_contacts_list.adapter
when (config.onContactClick) { if (currAdapter == null) {
ON_CLICK_CALL_CONTACT -> { ContactsAdapter(this, contacts, null, LOCATION_GROUP_CONTACTS, this, group_contacts_list, group_contacts_fastscroller) {
val contact = it as Contact when (config.onContactClick) {
if (contact.phoneNumbers.isNotEmpty()) { ON_CLICK_CALL_CONTACT -> {
tryStartCall(it) val contact = it as Contact
} else { if (contact.phoneNumbers.isNotEmpty()) {
toast(R.string.no_phone_number_found) 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)
} }
ON_CLICK_VIEW_CONTACT -> viewContact(it as Contact) }.apply {
ON_CLICK_EDIT_CONTACT -> editContact(it as Contact) setupDragListener(true)
addVerticalDividers(true)
group_contacts_list.adapter = this
} }
}.apply {
setupDragListener(true)
addVerticalDividers(true)
group_contacts_list.adapter = this
}
group_contacts_fastscroller.setScrollTo(0) group_contacts_fastscroller.setScrollTo(0)
group_contacts_fastscroller.setViews(group_contacts_list) { group_contacts_fastscroller.setViews(group_contacts_list) {
val item = (group_contacts_list.adapter as ContactsAdapter).contactItems.getOrNull(it) val item = (group_contacts_list.adapter as ContactsAdapter).contactItems.getOrNull(it)
group_contacts_fastscroller.updateBubbleText(item?.getBubbleText() ?: "") group_contacts_fastscroller.updateBubbleText(item?.getBubbleText() ?: "")
}
} else {
(currAdapter as ContactsAdapter).updateItems(contacts)
} }
} }

View File

@ -110,9 +110,11 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
} }
fun updateItems(newItems: ArrayList<Contact>) { fun updateItems(newItems: ArrayList<Contact>) {
contactItems = newItems if (newItems.hashCode() != contactItems.hashCode()) {
notifyDataSetChanged() contactItems = newItems
finishActMode() notifyDataSetChanged()
finishActMode()
}
} }
private fun editContact() { private fun editContact() {