From 2f3f0c294c5b82b20b4ff8f0bf96561f29bee140 Mon Sep 17 00:00:00 2001 From: Valere Date: Wed, 19 May 2021 14:38:47 +0200 Subject: [PATCH] Code review --- .../spaces/SpaceSettingsMenuBottomSheet.kt | 43 +++++++++---------- .../spaces/manage/AddRoomListController.kt | 41 +++++++++++++++--- .../spaces/manage/SpaceAddRoomFragment.kt | 33 +++++++------- 3 files changed, 71 insertions(+), 46 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/spaces/SpaceSettingsMenuBottomSheet.kt b/vector/src/main/java/im/vector/app/features/spaces/SpaceSettingsMenuBottomSheet.kt index 8f942685e5..f025aa80a0 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/SpaceSettingsMenuBottomSheet.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/SpaceSettingsMenuBottomSheet.kt @@ -16,6 +16,7 @@ package im.vector.app.features.spaces +import android.content.DialogInterface import android.os.Bundle import android.os.Parcelable import android.view.LayoutInflater @@ -28,6 +29,7 @@ import com.airbnb.mvrx.args import im.vector.app.R import im.vector.app.core.di.ActiveSessionHolder import im.vector.app.core.di.ScreenComponent +import im.vector.app.core.dialogs.withColoredButton import im.vector.app.core.extensions.setTextOrHide import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment import im.vector.app.databinding.BottomSheetSpaceSettingsBinding @@ -81,7 +83,7 @@ class SpaceSettingsMenuBottomSheet : VectorBaseBottomSheetDialogFragment session.coroutineScope.launch { try { @@ -192,6 +188,7 @@ class SpaceSettingsMenuBottomSheet : VectorBaseBottomSheetDialogFragment>) { + if (disabled) { + super.addModels(emptyList()) + return + } val host = this val filteredModel = if (ignoreRooms == null) { models @@ -103,9 +123,14 @@ class AddRoomListController @Inject constructor( id("header") title(host.sectionName ?: "") expanded(true) + title(sectionName ?: "") + expanded(host.expanded) + listener { + host.expanded = !host.expanded + } } ) - if (subHeaderText != null) { + if (expanded && subHeaderText != null) { add( GenericPillItem_().apply { id("sub_header") @@ -115,11 +140,13 @@ class AddRoomListController @Inject constructor( ) } } - super.addModels(filteredModel) - if (!initialLoadOccurred) { - add( - RoomSelectionPlaceHolderItem_().apply { id("loading") } - ) + if (expanded) { + super.addModels(filteredModel) + if (!initialLoadOccurred) { + add( + RoomSelectionPlaceHolderItem_().apply { id("loading") } + ) + } } } @@ -129,7 +156,7 @@ class AddRoomListController @Inject constructor( return RoomSelectionItem_().apply { id(item.roomId) matrixItem(item.toMatrixItem()) - avatarRenderer(this@AddRoomListController.avatarRenderer) + avatarRenderer(host.avatarRenderer) space(item.roomType == RoomType.SPACE) selected(host.selectedItems[item.roomId] ?: false) itemClickListener(DebouncedClickListener({ diff --git a/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceAddRoomFragment.kt b/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceAddRoomFragment.kt index 37a1a4f4d1..05a2f19941 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceAddRoomFragment.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceAddRoomFragment.kt @@ -28,7 +28,6 @@ import androidx.recyclerview.widget.LinearLayoutManager import com.airbnb.mvrx.Loading import com.airbnb.mvrx.activityViewModel import com.airbnb.mvrx.fragmentViewModel -import com.airbnb.mvrx.withState import com.jakewharton.rxbinding3.appcompat.queryTextChanges import im.vector.app.R import im.vector.app.core.extensions.cleanup @@ -109,6 +108,10 @@ class SpaceAddRoomFragment @Inject constructor( } }.disposeOnDestroyView() + viewModel.selectSubscribe(this, SpaceAddRoomsState::shouldShowDMs) { + dmEpoxyController.disabled = !it + }.disposeOnDestroyView() + views.createNewRoom.debouncedClicks { sharedViewModel.handle(SpaceManagedSharedAction.CreateRoom) } @@ -125,11 +128,11 @@ class SpaceAddRoomFragment @Inject constructor( .setNegativeButton(R.string.cancel, null) .show() } - is SpaceAddRoomsViewEvents.SaveFailed -> { + is SpaceAddRoomsViewEvents.SaveFailed -> { showErrorInSnackbar(it.reason) invalidateOptionsMenu() } - SpaceAddRoomsViewEvents.SavedDone -> { + SpaceAddRoomsViewEvents.SavedDone -> { sharedViewModel.handle(SpaceManagedSharedAction.HandleBack) } } @@ -186,20 +189,18 @@ class SpaceAddRoomFragment @Inject constructor( concatAdapter.addAdapter(roomEpoxyController.adapter) concatAdapter.addAdapter(spaceEpoxyController.adapter) - val shouldShowDm = withState(viewModel) { it.shouldShowDMs } - if (shouldShowDm) { - viewModel.updatableDMLivePageResult.liveBoundaries.observe(viewLifecycleOwner) { - dmEpoxyController.boundaryChange(it) - } - viewModel.updatableDMLivePageResult.livePagedList.observe(viewLifecycleOwner) { - dmEpoxyController.totalSize = it.size - dmEpoxyController.submitList(it) - } - dmEpoxyController.sectionName = getString(R.string.direct_chats_header) - dmEpoxyController.listener = this - - concatAdapter.addAdapter(dmEpoxyController.adapter) + // This controller can be disabled depending on the space type (public or not) + viewModel.updatableDMLivePageResult.liveBoundaries.observe(viewLifecycleOwner) { + dmEpoxyController.boundaryChange(it) } + viewModel.updatableDMLivePageResult.livePagedList.observe(viewLifecycleOwner) { + dmEpoxyController.totalSize = it.size + dmEpoxyController.submitList(it) + } + dmEpoxyController.sectionName = getString(R.string.direct_chats_header) + dmEpoxyController.listener = this + + concatAdapter.addAdapter(dmEpoxyController.adapter) views.roomList.adapter = concatAdapter }