mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-06-05 21:59:27 +02:00
add support for local groups
This commit is contained in:
@ -145,42 +145,44 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
||||
}
|
||||
|
||||
private fun setupGroupsAdapter(contacts: ArrayList<Contact>) {
|
||||
var storedGroups = ContactsHelper(activity!!).getStoredGroups()
|
||||
contacts.forEach {
|
||||
it.groups.forEach {
|
||||
val group = it
|
||||
val storedGroup = storedGroups.firstOrNull { it.id == group.id }
|
||||
storedGroup?.addContact()
|
||||
}
|
||||
}
|
||||
|
||||
storedGroups = storedGroups.asSequence().sortedWith(compareBy { it.title.normalizeString() }).toMutableList() as ArrayList<Group>
|
||||
|
||||
fragment_placeholder_2.beVisibleIf(storedGroups.isEmpty())
|
||||
fragment_placeholder.beVisibleIf(storedGroups.isEmpty())
|
||||
fragment_list.beVisibleIf(storedGroups.isNotEmpty())
|
||||
|
||||
val currAdapter = fragment_list.adapter
|
||||
if (currAdapter == null) {
|
||||
GroupsAdapter(activity as SimpleActivity, storedGroups, activity, fragment_list, fragment_fastscroller) {
|
||||
Intent(activity, GroupContactsActivity::class.java).apply {
|
||||
putExtra(GROUP, it as Group)
|
||||
activity!!.startActivity(this)
|
||||
ContactsHelper(activity!!).getStoredGroups {
|
||||
var storedGroups = it
|
||||
contacts.forEach {
|
||||
it.groups.forEach {
|
||||
val group = it
|
||||
val storedGroup = storedGroups.firstOrNull { it.id == group.id }
|
||||
storedGroup?.addContact()
|
||||
}
|
||||
}.apply {
|
||||
addVerticalDividers(true)
|
||||
fragment_list.adapter = this
|
||||
}
|
||||
|
||||
fragment_fastscroller.setScrollToY(0)
|
||||
fragment_fastscroller.setViews(fragment_list) {
|
||||
val item = (fragment_list.adapter as GroupsAdapter).groups.getOrNull(it)
|
||||
fragment_fastscroller.updateBubbleText(item?.getBubbleText() ?: "")
|
||||
}
|
||||
} else {
|
||||
(currAdapter as GroupsAdapter).apply {
|
||||
showContactThumbnails = activity.config.showContactThumbnails
|
||||
updateItems(storedGroups)
|
||||
storedGroups = storedGroups.asSequence().sortedWith(compareBy { it.title.normalizeString() }).toMutableList() as ArrayList<Group>
|
||||
|
||||
fragment_placeholder_2.beVisibleIf(storedGroups.isEmpty())
|
||||
fragment_placeholder.beVisibleIf(storedGroups.isEmpty())
|
||||
fragment_list.beVisibleIf(storedGroups.isNotEmpty())
|
||||
|
||||
val currAdapter = fragment_list.adapter
|
||||
if (currAdapter == null) {
|
||||
GroupsAdapter(activity as SimpleActivity, storedGroups, activity, fragment_list, fragment_fastscroller) {
|
||||
Intent(activity, GroupContactsActivity::class.java).apply {
|
||||
putExtra(GROUP, it as Group)
|
||||
activity!!.startActivity(this)
|
||||
}
|
||||
}.apply {
|
||||
addVerticalDividers(true)
|
||||
fragment_list.adapter = this
|
||||
}
|
||||
|
||||
fragment_fastscroller.setScrollToY(0)
|
||||
fragment_fastscroller.setViews(fragment_list) {
|
||||
val item = (fragment_list.adapter as GroupsAdapter).groups.getOrNull(it)
|
||||
fragment_fastscroller.updateBubbleText(item?.getBubbleText() ?: "")
|
||||
}
|
||||
} else {
|
||||
(currAdapter as GroupsAdapter).apply {
|
||||
showContactThumbnails = activity.config.showContactThumbnails
|
||||
updateItems(storedGroups)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user