From f82aee608920d5a9b1bf4f2eebca01bdcc37640d Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Mon, 12 Oct 2020 13:35:34 +0300 Subject: [PATCH 1/2] Add fab to the member list screen to invite users. --- CHANGES.md | 1 + .../members/RoomMemberListFragment.kt | 51 +++++++++++-------- .../main/res/drawable/ic_fab_add_members.xml | 30 +++++++++++ .../src/main/res/drawable/ic_invite_users.xml | 18 ------- .../res/layout/fragment_room_member_list.xml | 24 +++++++++ .../main/res/menu/menu_room_member_list.xml | 12 ----- 6 files changed, 84 insertions(+), 52 deletions(-) create mode 100644 vector/src/main/res/drawable/ic_fab_add_members.xml delete mode 100644 vector/src/main/res/drawable/ic_invite_users.xml create mode 100644 vector/src/main/res/layout/fragment_room_member_list.xml delete mode 100644 vector/src/main/res/menu/menu_room_member_list.xml diff --git a/CHANGES.md b/CHANGES.md index 05d189ed12..187d9ad8f4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -16,6 +16,7 @@ Improvements 🙌: - Drawer: move settings access and add sign out action (#2171) - Filter room member (and banned users) by name (#2184) - Implement "Jump to read receipt" and "Mention" actions on the room member profile screen + - Add FAB to room members list (#2226) Bugfix 🐛: - Improve support for image/audio/video/file selection with intent changes (#1376) diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/members/RoomMemberListFragment.kt b/vector/src/main/java/im/vector/app/features/roomprofile/members/RoomMemberListFragment.kt index 67577e866e..f38877ca6b 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/members/RoomMemberListFragment.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/members/RoomMemberListFragment.kt @@ -17,12 +17,11 @@ package im.vector.app.features.roomprofile.members import android.os.Bundle -import android.view.Menu -import android.view.MenuItem import android.view.View import androidx.appcompat.app.AlertDialog import androidx.appcompat.widget.SearchView import androidx.core.view.isVisible +import androidx.recyclerview.widget.RecyclerView import com.airbnb.mvrx.args import com.airbnb.mvrx.fragmentViewModel import com.airbnb.mvrx.withState @@ -37,6 +36,7 @@ import im.vector.app.core.extensions.configureWith import im.vector.app.core.platform.VectorBaseFragment import im.vector.app.features.home.AvatarRenderer import im.vector.app.features.roomprofile.RoomProfileArgs +import kotlinx.android.synthetic.main.fragment_room_member_list.* import kotlinx.android.synthetic.main.fragment_room_setting_generic.* import javax.inject.Inject @@ -49,38 +49,44 @@ class RoomMemberListFragment @Inject constructor( private val viewModel: RoomMemberListViewModel by fragmentViewModel() private val roomProfileArgs: RoomProfileArgs by args() - override fun getLayoutResId() = R.layout.fragment_room_setting_generic - - override fun getMenuRes() = R.menu.menu_room_member_list - - override fun onPrepareOptionsMenu(menu: Menu) { - val canInvite = withState(viewModel) { - it.actionsPermissions.canInvite - } - menu.findItem(R.id.menu_room_member_list_add_member).isVisible = canInvite - } - - override fun onOptionsItemSelected(item: MenuItem): Boolean { - when (item.itemId) { - R.id.menu_room_member_list_add_member -> { - navigator.openInviteUsersToRoom(requireContext(), roomProfileArgs.roomId) - return true - } - } - return super.onOptionsItemSelected(item) - } + override fun getLayoutResId() = R.layout.fragment_room_member_list override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) roomMemberListController.callback = this setupToolbar(roomSettingsToolbar) setupSearchView() + setupInviteUsersButton() recyclerView.configureWith(roomMemberListController, hasFixedSize = true) + // Hide FAB when list is scrolling + recyclerView.addOnScrollListener( + object : RecyclerView.OnScrollListener() { + override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) { + when (newState) { + RecyclerView.SCROLL_STATE_IDLE -> { + if (withState(viewModel) { it.actionsPermissions.canInvite }) { + inviteUsersButton.show() + } + } + RecyclerView.SCROLL_STATE_DRAGGING, + RecyclerView.SCROLL_STATE_SETTLING -> { + inviteUsersButton.hide() + } + } + } + } + ) viewModel.selectSubscribe(this, RoomMemberListViewState::actionsPermissions) { invalidateOptionsMenu() } } + private fun setupInviteUsersButton() { + inviteUsersButton.debouncedClicks { + navigator.openInviteUsersToRoom(requireContext(), roomProfileArgs.roomId) + } + } + private fun setupSearchView() { searchViewAppBarLayout.isVisible = true searchView.queryHint = getString(R.string.search_members_hint) @@ -131,5 +137,6 @@ class RoomMemberListFragment @Inject constructor( roomSettingsToolbarTitleView.text = it.displayName avatarRenderer.render(it.toMatrixItem(), roomSettingsToolbarAvatarImageView) } + inviteUsersButton.isVisible = state.actionsPermissions.canInvite } } diff --git a/vector/src/main/res/drawable/ic_fab_add_members.xml b/vector/src/main/res/drawable/ic_fab_add_members.xml new file mode 100644 index 0000000000..50768871ab --- /dev/null +++ b/vector/src/main/res/drawable/ic_fab_add_members.xml @@ -0,0 +1,30 @@ + + + + + + + + + diff --git a/vector/src/main/res/drawable/ic_invite_users.xml b/vector/src/main/res/drawable/ic_invite_users.xml deleted file mode 100644 index 64e5a3788d..0000000000 --- a/vector/src/main/res/drawable/ic_invite_users.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - diff --git a/vector/src/main/res/layout/fragment_room_member_list.xml b/vector/src/main/res/layout/fragment_room_member_list.xml new file mode 100644 index 0000000000..cfc7e2a891 --- /dev/null +++ b/vector/src/main/res/layout/fragment_room_member_list.xml @@ -0,0 +1,24 @@ + + + + + + + + \ No newline at end of file diff --git a/vector/src/main/res/menu/menu_room_member_list.xml b/vector/src/main/res/menu/menu_room_member_list.xml deleted file mode 100644 index ef452de70f..0000000000 --- a/vector/src/main/res/menu/menu_room_member_list.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - \ No newline at end of file From d6b94802d8578fb7796f6969818a684262489f68 Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Mon, 12 Oct 2020 18:32:31 +0300 Subject: [PATCH 2/2] Benoit code review fixes. --- .../members/RoomMemberListFragment.kt | 20 +++++++++---------- .../res/layout/fragment_room_member_list.xml | 11 ++++------ 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/members/RoomMemberListFragment.kt b/vector/src/main/java/im/vector/app/features/roomprofile/members/RoomMemberListFragment.kt index f38877ca6b..77337d7208 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/members/RoomMemberListFragment.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/members/RoomMemberListFragment.kt @@ -58,6 +58,15 @@ class RoomMemberListFragment @Inject constructor( setupSearchView() setupInviteUsersButton() recyclerView.configureWith(roomMemberListController, hasFixedSize = true) + viewModel.selectSubscribe(this, RoomMemberListViewState::actionsPermissions) { + invalidateOptionsMenu() + } + } + + private fun setupInviteUsersButton() { + inviteUsersButton.debouncedClicks { + navigator.openInviteUsersToRoom(requireContext(), roomProfileArgs.roomId) + } // Hide FAB when list is scrolling recyclerView.addOnScrollListener( object : RecyclerView.OnScrollListener() { @@ -76,15 +85,6 @@ class RoomMemberListFragment @Inject constructor( } } ) - viewModel.selectSubscribe(this, RoomMemberListViewState::actionsPermissions) { - invalidateOptionsMenu() - } - } - - private fun setupInviteUsersButton() { - inviteUsersButton.debouncedClicks { - navigator.openInviteUsersToRoom(requireContext(), roomProfileArgs.roomId) - } } private fun setupSearchView() { @@ -110,6 +110,7 @@ class RoomMemberListFragment @Inject constructor( override fun invalidate() = withState(viewModel) { viewState -> roomMemberListController.setData(viewState) renderRoomSummary(viewState) + inviteUsersButton.isVisible = viewState.actionsPermissions.canInvite } override fun onRoomMemberClicked(roomMember: RoomMemberSummary) { @@ -137,6 +138,5 @@ class RoomMemberListFragment @Inject constructor( roomSettingsToolbarTitleView.text = it.displayName avatarRenderer.render(it.toMatrixItem(), roomSettingsToolbarAvatarImageView) } - inviteUsersButton.isVisible = state.actionsPermissions.canInvite } } diff --git a/vector/src/main/res/layout/fragment_room_member_list.xml b/vector/src/main/res/layout/fragment_room_member_list.xml index cfc7e2a891..e144ddb6e3 100644 --- a/vector/src/main/res/layout/fragment_room_member_list.xml +++ b/vector/src/main/res/layout/fragment_room_member_list.xml @@ -1,7 +1,6 @@ - @@ -11,14 +10,12 @@ android:id="@+id/inviteUsersButton" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_gravity="bottom|end" android:layout_marginEnd="16dp" android:layout_marginBottom="16dp" android:contentDescription="@string/add_members_to_room" android:scaleType="center" android:src="@drawable/ic_fab_add_members" - app:layout_constraintBottom_toBottomOf="parent" - app:layout_constraintEnd_toEndOf="parent" - app:maxImageSize="36dp" - tools:visibility="visible" /> + app:maxImageSize="36dp" /> - \ No newline at end of file + \ No newline at end of file