This commit is contained in:
Benoit Marty 2020-01-11 22:12:56 +01:00
parent dd81fce8d8
commit f3e52b96c0
6 changed files with 19 additions and 18 deletions

View File

@ -64,7 +64,7 @@ class BreadcrumbsController @Inject constructor(
unreadNotificationCount(it.notificationCount)
showHighlighted(it.highlightCount > 0)
hasUnreadMessage(it.hasUnreadMessages)
hasTypingUsers(typingHelper.excludeCurrentUser(it.typingRoomMemberIds)?.isNotEmpty() == true)
hasTypingUsers(typingHelper.excludeCurrentUser(it.typingRoomMemberIds).isNotEmpty())
hasDraft(it.userDrafts.isNotEmpty())
itemClickListener(
DebouncedClickListener(View.OnClickListener { _ ->

View File

@ -802,7 +802,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
.unwrap()
.execute { async ->
val typingRoomMembers =
typingHelper.toTypingRoomMembers(async.invoke()?.typingRoomMemberIds, room)
typingHelper.toTypingRoomMembers(async.invoke()?.typingRoomMemberIds.orEmpty(), room)
copy(
asyncRoomSummary = async,

View File

@ -126,7 +126,7 @@ class RoomSummaryItemFactory @Inject constructor(private val noticeEventFormatte
}
}
val typingString = if (roomSummary.typingRoomMemberIds.isEmpty()) {
val typingString = if (typingHelper.excludeCurrentUser(roomSummary.typingRoomMemberIds).isEmpty()) {
null
} else {
// TODO Check how costly it is to create a Room here

View File

@ -32,37 +32,37 @@ class TypingHelper @Inject constructor(
* Exclude current user from the list of typing users
*/
fun excludeCurrentUser(
typingUserIds: List<String>?
): List<String>? {
typingUserIds: List<String>
): List<String> {
return typingUserIds
?.filter { it != session.myUserId }
.filter { it != session.myUserId }
}
/**
* Convert a list of userId to a list of maximum 3 UserItems
*/
fun toTypingRoomMembers(
typingUserIds: List<String>?,
typingUserIds: List<String>,
membershipService: MembershipService?
): List<MatrixItem.UserItem>? {
): List<MatrixItem.UserItem> {
return excludeCurrentUser(typingUserIds)
?.take(3)
?.mapNotNull { membershipService?.getRoomMember(it) }
?.map { it.toMatrixItem() }
.take(3)
.mapNotNull { membershipService?.getRoomMember(it) }
.map { it.toMatrixItem() }
}
/**
* Convert a list of typing UserItems to a human readable String
*/
fun toTypingMessage(typingUserItems: List<MatrixItem.UserItem>?): String? {
fun toTypingMessage(typingUserItems: List<MatrixItem.UserItem>): String? {
return when {
typingUserItems.isNullOrEmpty() ->
typingUserItems.isEmpty() ->
null
typingUserItems.size == 1 ->
typingUserItems.size == 1 ->
stringProvider.getString(R.string.room_one_user_is_typing, typingUserItems[0].getBestName())
typingUserItems.size == 2 ->
typingUserItems.size == 2 ->
stringProvider.getString(R.string.room_two_users_are_typing, typingUserItems[0].getBestName(), typingUserItems[1].getBestName())
else ->
else ->
stringProvider.getString(R.string.room_many_users_are_typing, typingUserItems[0].getBestName(), typingUserItems[1].getBestName())
}
}

View File

@ -59,7 +59,7 @@
android:layout_height="20dp"
android:background="@drawable/bg_breadcrumbs_typing"
android:gravity="center"
android:text=""
android:text="@string/ellipsis"
android:textColor="@android:color/white"
android:textSize="11sp"
android:textStyle="bold"
@ -67,7 +67,7 @@
app:layout_constraintCircle="@+id/breadcrumbsImageView"
app:layout_constraintCircleAngle="135"
app:layout_constraintCircleRadius="28dp"
tools:ignore="HardcodedText,MissingConstraints"
tools:ignore="MissingConstraints"
tools:visibility="visible" />
<ImageView

View File

@ -3,6 +3,7 @@
<string name="debug_screen" translatable="false">Debug screen</string>
<string name="ellipsis" translatable="false"></string>
<string name="plus_sign" translatable="false">+</string>
<string name="semicolon_sign" translatable="false">:</string>