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) unreadNotificationCount(it.notificationCount)
showHighlighted(it.highlightCount > 0) showHighlighted(it.highlightCount > 0)
hasUnreadMessage(it.hasUnreadMessages) hasUnreadMessage(it.hasUnreadMessages)
hasTypingUsers(typingHelper.excludeCurrentUser(it.typingRoomMemberIds)?.isNotEmpty() == true) hasTypingUsers(typingHelper.excludeCurrentUser(it.typingRoomMemberIds).isNotEmpty())
hasDraft(it.userDrafts.isNotEmpty()) hasDraft(it.userDrafts.isNotEmpty())
itemClickListener( itemClickListener(
DebouncedClickListener(View.OnClickListener { _ -> DebouncedClickListener(View.OnClickListener { _ ->

View File

@ -802,7 +802,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
.unwrap() .unwrap()
.execute { async -> .execute { async ->
val typingRoomMembers = val typingRoomMembers =
typingHelper.toTypingRoomMembers(async.invoke()?.typingRoomMemberIds, room) typingHelper.toTypingRoomMembers(async.invoke()?.typingRoomMemberIds.orEmpty(), room)
copy( copy(
asyncRoomSummary = async, 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 null
} else { } else {
// TODO Check how costly it is to create a Room here // 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 * Exclude current user from the list of typing users
*/ */
fun excludeCurrentUser( fun excludeCurrentUser(
typingUserIds: List<String>? typingUserIds: List<String>
): List<String>? { ): List<String> {
return typingUserIds return typingUserIds
?.filter { it != session.myUserId } .filter { it != session.myUserId }
} }
/** /**
* Convert a list of userId to a list of maximum 3 UserItems * Convert a list of userId to a list of maximum 3 UserItems
*/ */
fun toTypingRoomMembers( fun toTypingRoomMembers(
typingUserIds: List<String>?, typingUserIds: List<String>,
membershipService: MembershipService? membershipService: MembershipService?
): List<MatrixItem.UserItem>? { ): List<MatrixItem.UserItem> {
return excludeCurrentUser(typingUserIds) return excludeCurrentUser(typingUserIds)
?.take(3) .take(3)
?.mapNotNull { membershipService?.getRoomMember(it) } .mapNotNull { membershipService?.getRoomMember(it) }
?.map { it.toMatrixItem() } .map { it.toMatrixItem() }
} }
/** /**
* Convert a list of typing UserItems to a human readable String * 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 { return when {
typingUserItems.isNullOrEmpty() -> typingUserItems.isEmpty() ->
null null
typingUserItems.size == 1 -> typingUserItems.size == 1 ->
stringProvider.getString(R.string.room_one_user_is_typing, typingUserItems[0].getBestName()) 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()) 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()) 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:layout_height="20dp"
android:background="@drawable/bg_breadcrumbs_typing" android:background="@drawable/bg_breadcrumbs_typing"
android:gravity="center" android:gravity="center"
android:text="" android:text="@string/ellipsis"
android:textColor="@android:color/white" android:textColor="@android:color/white"
android:textSize="11sp" android:textSize="11sp"
android:textStyle="bold" android:textStyle="bold"
@ -67,7 +67,7 @@
app:layout_constraintCircle="@+id/breadcrumbsImageView" app:layout_constraintCircle="@+id/breadcrumbsImageView"
app:layout_constraintCircleAngle="135" app:layout_constraintCircleAngle="135"
app:layout_constraintCircleRadius="28dp" app:layout_constraintCircleRadius="28dp"
tools:ignore="HardcodedText,MissingConstraints" tools:ignore="MissingConstraints"
tools:visibility="visible" /> tools:visibility="visible" />
<ImageView <ImageView

View File

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