diff --git a/vector/src/main/java/im/vector/riotx/features/home/createdirect/CreateDirectRoomController.kt b/vector/src/main/java/im/vector/riotx/features/home/createdirect/CreateDirectRoomController.kt index 80ee4fb956..eea10452bf 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/createdirect/CreateDirectRoomController.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/createdirect/CreateDirectRoomController.kt @@ -18,14 +18,12 @@ package im.vector.riotx.features.home.createdirect -import arrow.core.Option import com.airbnb.epoxy.EpoxyController import com.airbnb.mvrx.* import im.vector.matrix.android.api.session.Session import im.vector.matrix.android.api.session.user.model.User import im.vector.matrix.android.internal.util.firstLetterOfDisplayName import im.vector.riotx.R -import im.vector.riotx.core.epoxy.NoResultItem_ import im.vector.riotx.core.epoxy.errorWithRetryItem import im.vector.riotx.core.epoxy.loadingItem import im.vector.riotx.core.epoxy.noResultItem @@ -55,7 +53,8 @@ class CreateDirectRoomController @Inject constructor(private val session: Sessio override fun buildModels() { val currentState = state ?: return - val hasSearch = currentState.searchTerm.isNotBlank() + val hasSearch = currentState.directorySearchTerm.isNotBlank() + val isFiltering = currentState.filterKnownUsersValue.nonEmpty() val asyncUsers = if (displayMode == CreateDirectRoomViewState.DisplayMode.DIRECTORY_USERS) { currentState.directoryUsers } else { @@ -64,7 +63,7 @@ class CreateDirectRoomController @Inject constructor(private val session: Sessio when (asyncUsers) { is Uninitialized -> renderEmptyState(false) is Loading -> renderLoading() - is Success -> renderSuccess(asyncUsers(), currentState.selectedUsers.map { it.userId }, hasSearch) + is Success -> renderSuccess(asyncUsers(), currentState.selectedUsers.map { it.userId }, hasSearch, isFiltering) is Fail -> renderFailure(asyncUsers.error) } } @@ -85,15 +84,16 @@ class CreateDirectRoomController @Inject constructor(private val session: Sessio private fun renderSuccess(users: List, selectedUsers: List, - hasSearch: Boolean) { + hasSearch: Boolean, + isFiltering: Boolean) { if (users.isEmpty()) { renderEmptyState(hasSearch) } else { - renderUsers(users, selectedUsers) + renderUsers(users, selectedUsers, isFiltering) } } - private fun renderUsers(users: List, selectedUsers: List) { + private fun renderUsers(users: List, selectedUsers: List, isFiltering: Boolean) { var lastFirstLetter: String? = null for (user in users) { if (user.userId == session.myUserId) { @@ -101,7 +101,7 @@ class CreateDirectRoomController @Inject constructor(private val session: Sessio } val isSelected = selectedUsers.contains(user.userId) val currentFirstLetter = user.displayName.firstLetterOfDisplayName() - val showLetter = currentFirstLetter.isNotEmpty() && lastFirstLetter != currentFirstLetter + val showLetter = !isFiltering && currentFirstLetter.isNotEmpty() && lastFirstLetter != currentFirstLetter lastFirstLetter = currentFirstLetter CreateDirectRoomLetterHeaderItem_() diff --git a/vector/src/main/java/im/vector/riotx/features/home/createdirect/CreateDirectRoomViewModel.kt b/vector/src/main/java/im/vector/riotx/features/home/createdirect/CreateDirectRoomViewModel.kt index 71ef00e0a5..a93514182a 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/createdirect/CreateDirectRoomViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/createdirect/CreateDirectRoomViewModel.kt @@ -35,7 +35,6 @@ import im.vector.riotx.core.platform.VectorViewModel import im.vector.riotx.core.utils.LiveEvent import io.reactivex.Observable import io.reactivex.Single -import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.functions.BiFunction import java.util.concurrent.TimeUnit @@ -147,7 +146,7 @@ class CreateDirectRoomViewModel @AssistedInject constructor(@Assisted } } stream.toAsync { - copy(directoryUsers = it, searchTerm = search) + copy(directoryUsers = it, directorySearchTerm = search) } } .subscribe() @@ -166,12 +165,15 @@ class CreateDirectRoomViewModel @AssistedInject constructor(@Assisted } else { users.filter { it.displayName?.contains(filterValue, ignoreCase = true) ?: false - || it.userId.contains(filterValue, ignoreCase = true) + || it.userId.contains(filterValue, ignoreCase = true) } } } ).execute { async -> - copy(knownUsers = async) + copy( + knownUsers = async, + filterKnownUsersValue = knownUsersFilter.value ?: Option.empty() + ) } } diff --git a/vector/src/main/java/im/vector/riotx/features/home/createdirect/CreateDirectRoomViewState.kt b/vector/src/main/java/im/vector/riotx/features/home/createdirect/CreateDirectRoomViewState.kt index e6bc212f25..95c76008dc 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/createdirect/CreateDirectRoomViewState.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/createdirect/CreateDirectRoomViewState.kt @@ -29,7 +29,7 @@ data class CreateDirectRoomViewState( val directoryUsers: Async> = Uninitialized, val selectedUsers: Set = emptySet(), val createAndInviteState: Async = Uninitialized, - val searchTerm: String = "", + val directorySearchTerm: String = "", val filterKnownUsersValue: Option = Option.empty() ) : MvRxState {