Room profile: create extension join for Collections
This commit is contained in:
parent
b56ee9a377
commit
78408fa0ec
@ -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.
|
* 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()
|
val iterator = iterator()
|
||||||
if (!iterator.hasNext()) return null
|
if (!iterator.hasNext()) return null
|
||||||
var minElem = iterator.next()
|
var minElem = iterator.next()
|
||||||
@ -34,3 +34,17 @@ public inline fun <T, R : Comparable<R>> Iterable<T>.lastMinBy(selector: (T) ->
|
|||||||
}
|
}
|
||||||
return minElem
|
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.dividerItem
|
||||||
import im.vector.riotx.core.epoxy.profiles.buildProfileSection
|
import im.vector.riotx.core.epoxy.profiles.buildProfileSection
|
||||||
import im.vector.riotx.core.epoxy.profiles.profileMatrixItem
|
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.ColorProvider
|
||||||
import im.vector.riotx.core.resources.StringProvider
|
import im.vector.riotx.core.resources.StringProvider
|
||||||
import im.vector.riotx.features.home.AvatarRenderer
|
import im.vector.riotx.features.home.AvatarRenderer
|
||||||
@ -55,7 +56,8 @@ class RoomMemberListController @Inject constructor(
|
|||||||
buildProfileSection(
|
buildProfileSection(
|
||||||
stringProvider.getString(powerLevelCategory.titleRes)
|
stringProvider.getString(powerLevelCategory.titleRes)
|
||||||
)
|
)
|
||||||
roomMemberList.forEach { roomMember ->
|
roomMemberList.join(
|
||||||
|
each = { roomMember ->
|
||||||
profileMatrixItem {
|
profileMatrixItem {
|
||||||
id(roomMember.userId)
|
id(roomMember.userId)
|
||||||
matrixItem(roomMember.toMatrixItem())
|
matrixItem(roomMember.toMatrixItem())
|
||||||
@ -64,12 +66,14 @@ class RoomMemberListController @Inject constructor(
|
|||||||
callback?.onRoomMemberClicked(roomMember)
|
callback?.onRoomMemberClicked(roomMember)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
between = { roomMemberBefore ->
|
||||||
dividerItem {
|
dividerItem {
|
||||||
id("divider_${roomMember.userId}")
|
id("divider_${roomMemberBefore.userId}")
|
||||||
color(dividerColor)
|
color(dividerColor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user