New direct chat: selecting a participant sometimes results in two breadcrumbs (#1022)
This commit is contained in:
parent
a55e0f1af4
commit
1072060cbb
|
@ -20,6 +20,7 @@ Bugfix 🐛:
|
|||
- Fix joining rooms from directory via federation isn't working. (#808)
|
||||
- Leaving a room creates a stuck "leaving room" loading screen. (#1041)
|
||||
- Fix some invitation handling issues (#1013)
|
||||
- New direct chat: selecting a participant sometimes results in two breadcrumbs (#1022)
|
||||
|
||||
Translations 🗣:
|
||||
-
|
||||
|
|
|
@ -23,17 +23,14 @@ import android.view.Menu
|
|||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.widget.ScrollView
|
||||
import androidx.core.view.size
|
||||
import com.airbnb.mvrx.activityViewModel
|
||||
import com.airbnb.mvrx.withState
|
||||
import com.google.android.material.chip.Chip
|
||||
import com.google.android.material.chip.ChipGroup
|
||||
import com.jakewharton.rxbinding3.widget.textChanges
|
||||
import im.vector.matrix.android.api.session.user.model.User
|
||||
import im.vector.riotx.R
|
||||
import im.vector.riotx.core.extensions.cleanup
|
||||
import im.vector.riotx.core.extensions.configureWith
|
||||
import im.vector.riotx.core.extensions.exhaustive
|
||||
import im.vector.riotx.core.extensions.hideKeyboard
|
||||
import im.vector.riotx.core.extensions.setupAsSearch
|
||||
import im.vector.riotx.core.platform.VectorBaseFragment
|
||||
|
@ -61,11 +58,6 @@ class CreateDirectRoomKnownUsersFragment @Inject constructor(
|
|||
setupFilterView()
|
||||
setupAddByMatrixIdView()
|
||||
setupCloseView()
|
||||
viewModel.observeViewEvents {
|
||||
when (it) {
|
||||
is CreateDirectRoomViewEvents.SelectUserAction -> updateChipsView(it)
|
||||
}.exhaustive
|
||||
}
|
||||
viewModel.selectSubscribe(this, CreateDirectRoomViewState::selectedUsers) {
|
||||
renderSelectedUsers(it)
|
||||
}
|
||||
|
@ -138,24 +130,24 @@ class CreateDirectRoomKnownUsersFragment @Inject constructor(
|
|||
knownUsersController.setData(it)
|
||||
}
|
||||
|
||||
private fun updateChipsView(data: CreateDirectRoomViewEvents.SelectUserAction) {
|
||||
if (data.isAdded) {
|
||||
addChipToGroup(data.user, chipGroup)
|
||||
} else {
|
||||
if (data.index in 0..chipGroup.size) {
|
||||
chipGroup.removeViewAt(data.index)
|
||||
private fun renderSelectedUsers(selectedUsers: Set<User>) {
|
||||
invalidateOptionsMenu()
|
||||
|
||||
val currentNumberOfChips = chipGroup.childCount
|
||||
val newNumberOfChips = selectedUsers.size
|
||||
|
||||
chipGroup.removeAllViews()
|
||||
selectedUsers.forEach { addChipToGroup(it) }
|
||||
|
||||
// Scroll to the bottom when adding chips. When removing chips, do not scroll
|
||||
if (newNumberOfChips >= currentNumberOfChips) {
|
||||
chipGroupScrollView.post {
|
||||
chipGroupScrollView.fullScroll(ScrollView.FOCUS_DOWN)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun renderSelectedUsers(selectedUsers: Set<User>) {
|
||||
invalidateOptionsMenu()
|
||||
if (selectedUsers.isNotEmpty() && chipGroup.size == 0) {
|
||||
selectedUsers.forEach { addChipToGroup(it, chipGroup) }
|
||||
}
|
||||
}
|
||||
|
||||
private fun addChipToGroup(user: User, chipGroup: ChipGroup) {
|
||||
private fun addChipToGroup(user: User) {
|
||||
val chip = Chip(requireContext())
|
||||
chip.setChipBackgroundColorResource(android.R.color.transparent)
|
||||
chip.chipStrokeWidth = dimensionConverter.dpToPx(1).toFloat()
|
||||
|
@ -167,9 +159,6 @@ class CreateDirectRoomKnownUsersFragment @Inject constructor(
|
|||
chip.setOnCloseIconClickListener {
|
||||
viewModel.handle(CreateDirectRoomAction.RemoveSelectedUser(user))
|
||||
}
|
||||
chipGroupScrollView.post {
|
||||
chipGroupScrollView.fullScroll(ScrollView.FOCUS_DOWN)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onItemClick(user: User) {
|
||||
|
|
|
@ -16,16 +16,9 @@
|
|||
|
||||
package im.vector.riotx.features.createdirect
|
||||
|
||||
import im.vector.matrix.android.api.session.user.model.User
|
||||
import im.vector.riotx.core.platform.VectorViewEvents
|
||||
|
||||
/**
|
||||
* Transient events for create direct room screen
|
||||
*/
|
||||
sealed class CreateDirectRoomViewEvents : VectorViewEvents {
|
||||
data class SelectUserAction(
|
||||
val user: User,
|
||||
val isAdded: Boolean,
|
||||
val index: Int
|
||||
) : CreateDirectRoomViewEvents()
|
||||
}
|
||||
sealed class CreateDirectRoomViewEvents : VectorViewEvents
|
||||
|
|
|
@ -27,9 +27,9 @@ import com.squareup.inject.assisted.Assisted
|
|||
import com.squareup.inject.assisted.AssistedInject
|
||||
import im.vector.matrix.android.api.session.Session
|
||||
import im.vector.matrix.android.api.session.room.model.create.CreateRoomParams
|
||||
import im.vector.matrix.android.api.session.user.model.User
|
||||
import im.vector.matrix.android.api.util.toMatrixItem
|
||||
import im.vector.matrix.rx.rx
|
||||
import im.vector.riotx.core.extensions.toggle
|
||||
import im.vector.riotx.core.platform.VectorViewModel
|
||||
import io.reactivex.Single
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
|
@ -91,30 +91,15 @@ class CreateDirectRoomViewModel @AssistedInject constructor(@Assisted
|
|||
}
|
||||
|
||||
private fun handleRemoveSelectedUser(action: CreateDirectRoomAction.RemoveSelectedUser) = withState { state ->
|
||||
val index = state.selectedUsers.indexOfFirst { it.userId == action.user.userId }
|
||||
val selectedUsers = state.selectedUsers.minus(action.user)
|
||||
setState { copy(selectedUsers = selectedUsers) }
|
||||
_viewEvents.post(CreateDirectRoomViewEvents.SelectUserAction(action.user, false, index))
|
||||
}
|
||||
|
||||
private fun handleSelectUser(action: CreateDirectRoomAction.SelectUser) = withState { state ->
|
||||
// Reset the filter asap
|
||||
directoryUsersSearch.accept("")
|
||||
val isAddOperation: Boolean
|
||||
val selectedUsers: Set<User>
|
||||
val indexOfUser = state.selectedUsers.indexOfFirst { it.userId == action.user.userId }
|
||||
val changeIndex: Int
|
||||
if (indexOfUser == -1) {
|
||||
changeIndex = state.selectedUsers.size
|
||||
selectedUsers = state.selectedUsers.plus(action.user)
|
||||
isAddOperation = true
|
||||
} else {
|
||||
changeIndex = indexOfUser
|
||||
selectedUsers = state.selectedUsers.minus(action.user)
|
||||
isAddOperation = false
|
||||
}
|
||||
val selectedUsers = state.selectedUsers.toggle(action.user)
|
||||
setState { copy(selectedUsers = selectedUsers) }
|
||||
_viewEvents.post(CreateDirectRoomViewEvents.SelectUserAction(action.user, isAddOperation, changeIndex))
|
||||
}
|
||||
|
||||
private fun observeDirectoryUsers() {
|
||||
|
|
Loading…
Reference in New Issue