mirror of
https://github.com/element-hq/element-android
synced 2024-11-24 02:15:35 +03:00
Fix regression when closing the screen to create a DM from the toolbar. Rework this part a bit.
This commit is contained in:
parent
aae6e20f9c
commit
944b447d93
6 changed files with 22 additions and 19 deletions
|
@ -49,6 +49,7 @@ class CallTransferPagerAdapter(
|
|||
fragment.arguments = UserListFragmentArgs(
|
||||
title = "",
|
||||
menuResId = -1,
|
||||
submitMenuItemId = -1,
|
||||
singleSelection = true,
|
||||
showInviteActions = false,
|
||||
showToolbar = false,
|
||||
|
|
|
@ -81,7 +81,7 @@ class CreateDirectRoomActivity : SimpleFragmentActivity() {
|
|||
when (action) {
|
||||
UserListSharedAction.Close -> finish()
|
||||
UserListSharedAction.GoBack -> onBackPressed()
|
||||
is UserListSharedAction.OnMenuItemSelected -> onMenuItemSelected(action)
|
||||
is UserListSharedAction.OnMenuItemSubmitClick -> handleOnMenuItemSubmitClick(action)
|
||||
UserListSharedAction.OpenPhoneBook -> openPhoneBook()
|
||||
UserListSharedAction.AddByQrCode -> openAddByQrCode()
|
||||
}
|
||||
|
@ -93,7 +93,8 @@ class CreateDirectRoomActivity : SimpleFragmentActivity() {
|
|||
UserListFragment::class.java,
|
||||
UserListFragmentArgs(
|
||||
title = getString(R.string.fab_menu_create_chat),
|
||||
menuResId = R.menu.vector_create_direct_room
|
||||
menuResId = R.menu.vector_create_direct_room,
|
||||
submitMenuItemId = R.id.action_create_direct_room,
|
||||
)
|
||||
)
|
||||
}
|
||||
|
@ -159,10 +160,8 @@ class CreateDirectRoomActivity : SimpleFragmentActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun onMenuItemSelected(action: UserListSharedAction.OnMenuItemSelected) {
|
||||
if (action.itemId == R.id.action_create_direct_room) {
|
||||
viewModel.handle(CreateDirectRoomAction.CreateRoomAndInviteSelectedUsers(action.selections))
|
||||
}
|
||||
private fun handleOnMenuItemSubmitClick(action: UserListSharedAction.OnMenuItemSubmitClick) {
|
||||
viewModel.handle(CreateDirectRoomAction.CreateRoomAndInviteSelectedUsers(action.selections))
|
||||
}
|
||||
|
||||
private fun renderCreateAndInviteState(state: Async<String>) {
|
||||
|
|
|
@ -71,7 +71,7 @@ class InviteUsersToRoomActivity : SimpleFragmentActivity() {
|
|||
when (sharedAction) {
|
||||
UserListSharedAction.Close -> finish()
|
||||
UserListSharedAction.GoBack -> onBackPressed()
|
||||
is UserListSharedAction.OnMenuItemSelected -> onMenuItemSelected(sharedAction)
|
||||
is UserListSharedAction.OnMenuItemSubmitClick -> handleOnMenuItemSubmitClick(sharedAction)
|
||||
UserListSharedAction.OpenPhoneBook -> openPhoneBook()
|
||||
// not exhaustive because it's a sharedAction
|
||||
else -> Unit
|
||||
|
@ -85,6 +85,7 @@ class InviteUsersToRoomActivity : SimpleFragmentActivity() {
|
|||
UserListFragmentArgs(
|
||||
title = getString(R.string.invite_users_to_room_title),
|
||||
menuResId = R.menu.vector_invite_users_to_room,
|
||||
submitMenuItemId = R.id.action_invite_users_to_room_invite,
|
||||
excludedUserIds = viewModel.getUserIdsOfRoomMembers(),
|
||||
showInviteActions = false
|
||||
)
|
||||
|
@ -94,10 +95,8 @@ class InviteUsersToRoomActivity : SimpleFragmentActivity() {
|
|||
viewModel.observeViewEvents { renderInviteEvents(it) }
|
||||
}
|
||||
|
||||
private fun onMenuItemSelected(action: UserListSharedAction.OnMenuItemSelected) {
|
||||
if (action.itemId == R.id.action_invite_users_to_room_invite) {
|
||||
viewModel.handle(InviteUsersToRoomAction.InviteSelectedUsers(action.selections))
|
||||
}
|
||||
private fun handleOnMenuItemSubmitClick(action: UserListSharedAction.OnMenuItemSubmitClick) {
|
||||
viewModel.handle(InviteUsersToRoomAction.InviteSelectedUsers(action.selections))
|
||||
}
|
||||
|
||||
private fun openPhoneBook() {
|
||||
|
|
|
@ -23,7 +23,6 @@ import android.view.MenuItem
|
|||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ScrollView
|
||||
import androidx.core.view.forEach
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.airbnb.mvrx.activityViewModel
|
||||
|
@ -114,19 +113,23 @@ class UserListFragment @Inject constructor(
|
|||
}
|
||||
|
||||
override fun handlePrepareMenu(menu: Menu) {
|
||||
if (args.submitMenuItemId == -1) return
|
||||
withState(viewModel) {
|
||||
val showMenuItem = it.pendingSelections.isNotEmpty()
|
||||
menu.forEach { menuItem ->
|
||||
menuItem.isVisible = showMenuItem
|
||||
}
|
||||
menu.findItem(args.submitMenuItemId).isVisible = showMenuItem
|
||||
}
|
||||
}
|
||||
|
||||
override fun handleMenuItemSelected(item: MenuItem): Boolean {
|
||||
withState(viewModel) {
|
||||
sharedActionViewModel.post(UserListSharedAction.OnMenuItemSelected(item.itemId, it.pendingSelections))
|
||||
return when (item.itemId) {
|
||||
args.submitMenuItemId -> {
|
||||
withState(viewModel) {
|
||||
sharedActionViewModel.post(UserListSharedAction.OnMenuItemSubmitClick(it.pendingSelections))
|
||||
}
|
||||
true
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
private fun setupRecyclerView() {
|
||||
|
|
|
@ -23,6 +23,7 @@ import kotlinx.parcelize.Parcelize
|
|||
data class UserListFragmentArgs(
|
||||
val title: String,
|
||||
val menuResId: Int,
|
||||
val submitMenuItemId: Int,
|
||||
val excludedUserIds: Set<String>? = null,
|
||||
val singleSelection: Boolean = false,
|
||||
val showInviteActions: Boolean = true,
|
||||
|
|
|
@ -21,7 +21,7 @@ import im.vector.app.core.platform.VectorSharedAction
|
|||
sealed class UserListSharedAction : VectorSharedAction {
|
||||
object Close : UserListSharedAction()
|
||||
object GoBack : UserListSharedAction()
|
||||
data class OnMenuItemSelected(val itemId: Int, val selections: Set<PendingSelection>) : UserListSharedAction()
|
||||
data class OnMenuItemSubmitClick(val selections: Set<PendingSelection>) : UserListSharedAction()
|
||||
object OpenPhoneBook : UserListSharedAction()
|
||||
object AddByQrCode : UserListSharedAction()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue