Create direct : remove letter headers when filtering

This commit is contained in:
ganfra 2019-07-29 19:13:06 +02:00
parent 0255696c88
commit ff6ce8a4b7
3 changed files with 15 additions and 13 deletions

View File

@ -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<User>,
selectedUsers: List<String>,
hasSearch: Boolean) {
hasSearch: Boolean,
isFiltering: Boolean) {
if (users.isEmpty()) {
renderEmptyState(hasSearch)
} else {
renderUsers(users, selectedUsers)
renderUsers(users, selectedUsers, isFiltering)
}
}
private fun renderUsers(users: List<User>, selectedUsers: List<String>) {
private fun renderUsers(users: List<User>, selectedUsers: List<String>, 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_()

View File

@ -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()
)
}
}

View File

@ -29,7 +29,7 @@ data class CreateDirectRoomViewState(
val directoryUsers: Async<List<User>> = Uninitialized,
val selectedUsers: Set<User> = emptySet(),
val createAndInviteState: Async<String> = Uninitialized,
val searchTerm: String = "",
val directorySearchTerm: String = "",
val filterKnownUsersValue: Option<String> = Option.empty()
) : MvRxState {