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
supportActionBar?.title = group.title
refreshContacts()
group_contacts_fab.setOnClickListener {
SelectContactsDialog(this, allContacts, groupContacts) { addedContacts, removedContacts ->
ContactsHelper(this).apply {
@ -41,6 +40,11 @@ class GroupContactsActivity : SimpleActivity(), RemoveFromGroupListener {
}
}
override fun onResume() {
super.onResume()
refreshContacts()
}
private fun refreshContacts() {
ContactsHelper(this).getContacts {
allContacts = it
@ -54,29 +58,34 @@ class GroupContactsActivity : SimpleActivity(), RemoveFromGroupListener {
}
private fun updateContacts(contacts: ArrayList<Contact>) {
ContactsAdapter(this, contacts, null, LOCATION_GROUP_CONTACTS, this, 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)
val currAdapter = group_contacts_list.adapter
if (currAdapter == null) {
ContactsAdapter(this, contacts, null, LOCATION_GROUP_CONTACTS, this, 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)
}
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
}
}.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() ?: "")
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() ?: "")
}
} 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>) {
contactItems = newItems
notifyDataSetChanged()
finishActMode()
if (newItems.hashCode() != contactItems.hashCode()) {
contactItems = newItems
notifyDataSetChanged()
finishActMode()
}
}
private fun editContact() {