mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 13:38:49 +03:00
Room profile: create extension join for Collections
This commit is contained in:
parent
b56ee9a377
commit
78408fa0ec
2 changed files with 33 additions and 15 deletions
|
@ -19,7 +19,7 @@ package im.vector.riotx.core.extensions
|
|||
/**
|
||||
* Returns the last element yielding the smallest value of the given function or `null` if there are no elements.
|
||||
*/
|
||||
public inline fun <T, R : Comparable<R>> Iterable<T>.lastMinBy(selector: (T) -> R): T? {
|
||||
inline fun <T, R : Comparable<R>> Iterable<T>.lastMinBy(selector: (T) -> R): T? {
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext()) return null
|
||||
var minElem = iterator.next()
|
||||
|
@ -34,3 +34,17 @@ public inline fun <T, R : Comparable<R>> Iterable<T>.lastMinBy(selector: (T) ->
|
|||
}
|
||||
return minElem
|
||||
}
|
||||
|
||||
/**
|
||||
* Call each for each item, and between between each items
|
||||
*/
|
||||
inline fun <T> Collection<T>.join(each: (T) -> Unit, between: (T) -> Unit) {
|
||||
val lastIndex = size - 1
|
||||
forEachIndexed { idx, t ->
|
||||
each(t)
|
||||
|
||||
if (idx != lastIndex) {
|
||||
between(t)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import im.vector.riotx.R
|
|||
import im.vector.riotx.core.epoxy.dividerItem
|
||||
import im.vector.riotx.core.epoxy.profiles.buildProfileSection
|
||||
import im.vector.riotx.core.epoxy.profiles.profileMatrixItem
|
||||
import im.vector.riotx.core.extensions.join
|
||||
import im.vector.riotx.core.resources.ColorProvider
|
||||
import im.vector.riotx.core.resources.StringProvider
|
||||
import im.vector.riotx.features.home.AvatarRenderer
|
||||
|
@ -55,21 +56,24 @@ class RoomMemberListController @Inject constructor(
|
|||
buildProfileSection(
|
||||
stringProvider.getString(powerLevelCategory.titleRes)
|
||||
)
|
||||
roomMemberList.forEach { roomMember ->
|
||||
profileMatrixItem {
|
||||
id(roomMember.userId)
|
||||
matrixItem(roomMember.toMatrixItem())
|
||||
avatarRenderer(avatarRenderer)
|
||||
clickListener { _ ->
|
||||
callback?.onRoomMemberClicked(roomMember)
|
||||
roomMemberList.join(
|
||||
each = { roomMember ->
|
||||
profileMatrixItem {
|
||||
id(roomMember.userId)
|
||||
matrixItem(roomMember.toMatrixItem())
|
||||
avatarRenderer(avatarRenderer)
|
||||
clickListener { _ ->
|
||||
callback?.onRoomMemberClicked(roomMember)
|
||||
}
|
||||
}
|
||||
},
|
||||
between = { roomMemberBefore ->
|
||||
dividerItem {
|
||||
id("divider_${roomMemberBefore.userId}")
|
||||
color(dividerColor)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dividerItem {
|
||||
id("divider_${roomMember.userId}")
|
||||
color(dividerColor)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue