Change menu action title for existing rooms.
This commit is contained in:
parent
e7714da8e8
commit
458b4259fe
|
@ -91,7 +91,8 @@ class CreateDirectRoomActivity : SimpleFragmentActivity() {
|
|||
KnownUsersFragment::class.java,
|
||||
KnownUsersFragmentArgs(
|
||||
title = getString(R.string.fab_menu_create_chat),
|
||||
menuResId = R.menu.vector_create_direct_room
|
||||
menuResId = R.menu.vector_create_direct_room,
|
||||
isCreatingRoom = true
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
|
@ -91,6 +91,9 @@ class KnownUsersFragment @Inject constructor(
|
|||
val showMenuItem = it.pendingInvitees.isNotEmpty()
|
||||
menu.forEach { menuItem ->
|
||||
menuItem.isVisible = showMenuItem
|
||||
if (args.isCreatingRoom) {
|
||||
menuItem.setTitle(if (it.isThereAnExistingRoom) R.string.action_open else R.string.create_room_action_create)
|
||||
}
|
||||
}
|
||||
}
|
||||
super.onPrepareOptionsMenu(menu)
|
||||
|
|
|
@ -23,5 +23,6 @@ import kotlinx.android.parcel.Parcelize
|
|||
data class KnownUsersFragmentArgs(
|
||||
val title: String,
|
||||
val menuResId: Int,
|
||||
val excludedUserIds: Set<String>? = null
|
||||
val excludedUserIds: Set<String>? = null,
|
||||
val isCreatingRoom: Boolean = false
|
||||
) : Parcelable
|
||||
|
|
|
@ -87,14 +87,37 @@ class UserDirectoryViewModel @AssistedInject constructor(@Assisted
|
|||
|
||||
private fun handleRemoveSelectedUser(action: UserDirectoryAction.RemovePendingInvitee) = withState { state ->
|
||||
val selectedUsers = state.pendingInvitees.minus(action.pendingInvitee)
|
||||
setState { copy(pendingInvitees = selectedUsers) }
|
||||
setState {
|
||||
copy(
|
||||
pendingInvitees = selectedUsers,
|
||||
isThereAnExistingRoom = isThereAnExistingRoom(selectedUsers)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleSelectUser(action: UserDirectoryAction.SelectPendingInvitee) = withState { state ->
|
||||
// Reset the filter asap
|
||||
directoryUsersSearch.accept("")
|
||||
val selectedUsers = state.pendingInvitees.toggle(action.pendingInvitee)
|
||||
setState { copy(pendingInvitees = selectedUsers) }
|
||||
setState {
|
||||
copy(
|
||||
pendingInvitees = selectedUsers,
|
||||
isThereAnExistingRoom = isThereAnExistingRoom(selectedUsers)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun isThereAnExistingRoom(selectedUsers: Set<PendingInvitee>): Boolean {
|
||||
return selectedUsers
|
||||
.takeIf { it.size == 1 }
|
||||
?.firstOrNull()
|
||||
?.let { invitee ->
|
||||
return when (invitee) {
|
||||
is PendingInvitee.UserPendingInvitee -> session.getExistingDirectRoomWithUser(invitee.user.userId) != null
|
||||
is PendingInvitee.ThreePidPendingInvitee -> false
|
||||
}.exhaustive
|
||||
}
|
||||
?: false
|
||||
}
|
||||
|
||||
private fun observeDirectoryUsers() = withState { state ->
|
||||
|
|
|
@ -30,7 +30,8 @@ data class UserDirectoryViewState(
|
|||
val pendingInvitees: Set<PendingInvitee> = emptySet(),
|
||||
val createAndInviteState: Async<String> = Uninitialized,
|
||||
val directorySearchTerm: String = "",
|
||||
val filterKnownUsersValue: Option<String> = Option.empty()
|
||||
val filterKnownUsersValue: Option<String> = Option.empty(),
|
||||
val isThereAnExistingRoom: Boolean = false
|
||||
) : MvRxState {
|
||||
|
||||
constructor(args: KnownUsersFragmentArgs) : this(excludedUserIds = args.excludedUserIds)
|
||||
|
|
Loading…
Reference in New Issue