mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 21:48:50 +03:00
commit
30432cd3f4
6 changed files with 26 additions and 53 deletions
|
@ -20,6 +20,7 @@ Bugfix 🐛:
|
||||||
- Fix joining rooms from directory via federation isn't working. (#808)
|
- Fix joining rooms from directory via federation isn't working. (#808)
|
||||||
- Leaving a room creates a stuck "leaving room" loading screen. (#1041)
|
- Leaving a room creates a stuck "leaving room" loading screen. (#1041)
|
||||||
- Fix some invitation handling issues (#1013)
|
- Fix some invitation handling issues (#1013)
|
||||||
|
- New direct chat: selecting a participant sometimes results in two breadcrumbs (#1022)
|
||||||
|
|
||||||
Translations 🗣:
|
Translations 🗣:
|
||||||
-
|
-
|
||||||
|
|
|
@ -24,4 +24,9 @@ data class User(
|
||||||
val userId: String,
|
val userId: String,
|
||||||
val displayName: String? = null,
|
val displayName: String? = null,
|
||||||
val avatarUrl: String? = null
|
val avatarUrl: String? = null
|
||||||
)
|
) {
|
||||||
|
/**
|
||||||
|
* Return the display name or the user id
|
||||||
|
*/
|
||||||
|
fun getBestName() = displayName?.takeIf { it.isNotEmpty() } ?: userId
|
||||||
|
}
|
||||||
|
|
|
@ -23,17 +23,14 @@ import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.ScrollView
|
import android.widget.ScrollView
|
||||||
import androidx.core.view.size
|
|
||||||
import com.airbnb.mvrx.activityViewModel
|
import com.airbnb.mvrx.activityViewModel
|
||||||
import com.airbnb.mvrx.withState
|
import com.airbnb.mvrx.withState
|
||||||
import com.google.android.material.chip.Chip
|
import com.google.android.material.chip.Chip
|
||||||
import com.google.android.material.chip.ChipGroup
|
|
||||||
import com.jakewharton.rxbinding3.widget.textChanges
|
import com.jakewharton.rxbinding3.widget.textChanges
|
||||||
import im.vector.matrix.android.api.session.user.model.User
|
import im.vector.matrix.android.api.session.user.model.User
|
||||||
import im.vector.riotx.R
|
import im.vector.riotx.R
|
||||||
import im.vector.riotx.core.extensions.cleanup
|
import im.vector.riotx.core.extensions.cleanup
|
||||||
import im.vector.riotx.core.extensions.configureWith
|
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.hideKeyboard
|
||||||
import im.vector.riotx.core.extensions.setupAsSearch
|
import im.vector.riotx.core.extensions.setupAsSearch
|
||||||
import im.vector.riotx.core.platform.VectorBaseFragment
|
import im.vector.riotx.core.platform.VectorBaseFragment
|
||||||
|
@ -61,11 +58,6 @@ class CreateDirectRoomKnownUsersFragment @Inject constructor(
|
||||||
setupFilterView()
|
setupFilterView()
|
||||||
setupAddByMatrixIdView()
|
setupAddByMatrixIdView()
|
||||||
setupCloseView()
|
setupCloseView()
|
||||||
viewModel.observeViewEvents {
|
|
||||||
when (it) {
|
|
||||||
is CreateDirectRoomViewEvents.SelectUserAction -> updateChipsView(it)
|
|
||||||
}.exhaustive
|
|
||||||
}
|
|
||||||
viewModel.selectSubscribe(this, CreateDirectRoomViewState::selectedUsers) {
|
viewModel.selectSubscribe(this, CreateDirectRoomViewState::selectedUsers) {
|
||||||
renderSelectedUsers(it)
|
renderSelectedUsers(it)
|
||||||
}
|
}
|
||||||
|
@ -138,28 +130,28 @@ class CreateDirectRoomKnownUsersFragment @Inject constructor(
|
||||||
knownUsersController.setData(it)
|
knownUsersController.setData(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateChipsView(data: CreateDirectRoomViewEvents.SelectUserAction) {
|
private fun renderSelectedUsers(selectedUsers: Set<User>) {
|
||||||
if (data.isAdded) {
|
invalidateOptionsMenu()
|
||||||
addChipToGroup(data.user, chipGroup)
|
|
||||||
} else {
|
val currentNumberOfChips = chipGroup.childCount
|
||||||
if (chipGroup.size > data.index) {
|
val newNumberOfChips = selectedUsers.size
|
||||||
chipGroup.removeViewAt(data.index)
|
|
||||||
|
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>) {
|
private fun addChipToGroup(user: User) {
|
||||||
invalidateOptionsMenu()
|
|
||||||
if (selectedUsers.isNotEmpty() && chipGroup.size == 0) {
|
|
||||||
selectedUsers.forEach { addChipToGroup(it, chipGroup) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun addChipToGroup(user: User, chipGroup: ChipGroup) {
|
|
||||||
val chip = Chip(requireContext())
|
val chip = Chip(requireContext())
|
||||||
chip.setChipBackgroundColorResource(android.R.color.transparent)
|
chip.setChipBackgroundColorResource(android.R.color.transparent)
|
||||||
chip.chipStrokeWidth = dimensionConverter.dpToPx(1).toFloat()
|
chip.chipStrokeWidth = dimensionConverter.dpToPx(1).toFloat()
|
||||||
chip.text = if (user.displayName.isNullOrBlank()) user.userId else user.displayName
|
chip.text = user.getBestName()
|
||||||
chip.isClickable = true
|
chip.isClickable = true
|
||||||
chip.isCheckable = false
|
chip.isCheckable = false
|
||||||
chip.isCloseIconVisible = true
|
chip.isCloseIconVisible = true
|
||||||
|
@ -167,9 +159,6 @@ class CreateDirectRoomKnownUsersFragment @Inject constructor(
|
||||||
chip.setOnCloseIconClickListener {
|
chip.setOnCloseIconClickListener {
|
||||||
viewModel.handle(CreateDirectRoomAction.RemoveSelectedUser(user))
|
viewModel.handle(CreateDirectRoomAction.RemoveSelectedUser(user))
|
||||||
}
|
}
|
||||||
chipGroupScrollView.post {
|
|
||||||
chipGroupScrollView.fullScroll(ScrollView.FOCUS_DOWN)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onItemClick(user: User) {
|
override fun onItemClick(user: User) {
|
||||||
|
|
|
@ -16,16 +16,9 @@
|
||||||
|
|
||||||
package im.vector.riotx.features.createdirect
|
package im.vector.riotx.features.createdirect
|
||||||
|
|
||||||
import im.vector.matrix.android.api.session.user.model.User
|
|
||||||
import im.vector.riotx.core.platform.VectorViewEvents
|
import im.vector.riotx.core.platform.VectorViewEvents
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transient events for create direct room screen
|
* Transient events for create direct room screen
|
||||||
*/
|
*/
|
||||||
sealed class CreateDirectRoomViewEvents : VectorViewEvents {
|
sealed class CreateDirectRoomViewEvents : VectorViewEvents
|
||||||
data class SelectUserAction(
|
|
||||||
val user: User,
|
|
||||||
val isAdded: Boolean,
|
|
||||||
val index: Int
|
|
||||||
) : CreateDirectRoomViewEvents()
|
|
||||||
}
|
|
||||||
|
|
|
@ -27,9 +27,9 @@ import com.squareup.inject.assisted.Assisted
|
||||||
import com.squareup.inject.assisted.AssistedInject
|
import com.squareup.inject.assisted.AssistedInject
|
||||||
import im.vector.matrix.android.api.session.Session
|
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.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.android.api.util.toMatrixItem
|
||||||
import im.vector.matrix.rx.rx
|
import im.vector.matrix.rx.rx
|
||||||
|
import im.vector.riotx.core.extensions.toggle
|
||||||
import im.vector.riotx.core.platform.VectorViewModel
|
import im.vector.riotx.core.platform.VectorViewModel
|
||||||
import io.reactivex.Single
|
import io.reactivex.Single
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||||
|
@ -91,30 +91,15 @@ class CreateDirectRoomViewModel @AssistedInject constructor(@Assisted
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleRemoveSelectedUser(action: CreateDirectRoomAction.RemoveSelectedUser) = withState { state ->
|
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)
|
val selectedUsers = state.selectedUsers.minus(action.user)
|
||||||
setState { copy(selectedUsers = selectedUsers) }
|
setState { copy(selectedUsers = selectedUsers) }
|
||||||
_viewEvents.post(CreateDirectRoomViewEvents.SelectUserAction(action.user, false, index))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleSelectUser(action: CreateDirectRoomAction.SelectUser) = withState { state ->
|
private fun handleSelectUser(action: CreateDirectRoomAction.SelectUser) = withState { state ->
|
||||||
// Reset the filter asap
|
// Reset the filter asap
|
||||||
directoryUsersSearch.accept("")
|
directoryUsersSearch.accept("")
|
||||||
val isAddOperation: Boolean
|
val selectedUsers = state.selectedUsers.toggle(action.user)
|
||||||
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
|
|
||||||
}
|
|
||||||
setState { copy(selectedUsers = selectedUsers) }
|
setState { copy(selectedUsers = selectedUsers) }
|
||||||
_viewEvents.post(CreateDirectRoomViewEvents.SelectUserAction(action.user, isAddOperation, changeIndex))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeDirectoryUsers() {
|
private fun observeDirectoryUsers() {
|
||||||
|
|
|
@ -203,7 +203,7 @@ class NotificationDrawerManager @Inject constructor(private val context: Context
|
||||||
|
|
||||||
val user = session.getUser(session.myUserId)
|
val user = session.getUser(session.myUserId)
|
||||||
// myUserDisplayName cannot be empty else NotificationCompat.MessagingStyle() will crash
|
// myUserDisplayName cannot be empty else NotificationCompat.MessagingStyle() will crash
|
||||||
val myUserDisplayName = user?.displayName?.takeIf { it.isNotBlank() } ?: session.myUserId
|
val myUserDisplayName = user?.getBestName() ?: session.myUserId
|
||||||
val myUserAvatarUrl = session.contentUrlResolver().resolveThumbnail(user?.avatarUrl, avatarSize, avatarSize, ContentUrlResolver.ThumbnailMethod.SCALE)
|
val myUserAvatarUrl = session.contentUrlResolver().resolveThumbnail(user?.avatarUrl, avatarSize, avatarSize, ContentUrlResolver.ThumbnailMethod.SCALE)
|
||||||
synchronized(eventList) {
|
synchronized(eventList) {
|
||||||
Timber.v("%%%%%%%% REFRESH NOTIFICATION DRAWER ")
|
Timber.v("%%%%%%%% REFRESH NOTIFICATION DRAWER ")
|
||||||
|
|
Loading…
Reference in a new issue