Code review

This commit is contained in:
Valere 2021-05-19 14:38:47 +02:00
parent cbf0357467
commit 2f3f0c294c
3 changed files with 71 additions and 46 deletions

View file

@ -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<BottomS
injector.inject(this)
}
var isAdmin: Boolean = false
var isLastAdmin: Boolean = false
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): BottomSheetSpaceSettingsBinding {
return BottomSheetSpaceSettingsBinding.inflate(inflater, container, false)
@ -117,7 +119,12 @@ class SpaceSettingsMenuBottomSheet : VectorBaseBottomSheetDialogFragment<BottomS
views.invitePeople.isVisible = canInvite || roomSummary?.isPublic.orFalse()
views.addRooms.isVisible = canAddChild
isAdmin = powerLevelsHelper.getUserRole(session.myUserId) is Role.Admin
val isAdmin = powerLevelsHelper.getUserRole(session.myUserId) is Role.Admin
val otherAdminCount = roomSummary?.otherMemberIds
?.map { powerLevelsHelper.getUserRole(it) }
?.count { it is Role.Admin }
?: 0
isLastAdmin = isAdmin && otherAdminCount == 0
}.disposeOnDestroyView()
views.spaceBetaTag.setOnClickListener {
@ -150,36 +157,25 @@ class SpaceSettingsMenuBottomSheet : VectorBaseBottomSheetDialogFragment<BottomS
views.leaveSpace.views.bottomSheetActionClickableZone.debouncedClicks {
val spaceSummary = activeSessionHolder.getSafeActiveSession()?.getRoomSummary(spaceArgs.spaceId)
?: return@debouncedClicks
val warningMessage: CharSequence = if (spaceSummary.otherMemberIds.isEmpty()) {
span {
+getString(R.string.space_leave_prompt_msg)
+"\n"
span(getString(R.string.space_leave_prompt_msg_only_you)) {
textColor = ContextCompat.getColor(requireContext(), R.color.riotx_destructive_accent)
}
val warningMessage: CharSequence? = if (spaceSummary.otherMemberIds.isEmpty()) {
span(getString(R.string.space_leave_prompt_msg_only_you)) {
textColor = ContextCompat.getColor(requireContext(), R.color.riotx_destructive_accent)
}
} else if (isAdmin) {
span {
+getString(R.string.space_leave_prompt_msg)
+"\n"
span(getString(R.string.space_leave_prompt_msg_as_admin)) {
textColor = ContextCompat.getColor(requireContext(), R.color.riotx_destructive_accent)
}
} else if (isLastAdmin) {
span(getString(R.string.space_leave_prompt_msg_as_admin)) {
textColor = ContextCompat.getColor(requireContext(), R.color.riotx_destructive_accent)
}
} else if (!spaceSummary.isPublic) {
span {
+getString(R.string.space_leave_prompt_msg)
+"\n"
span(getString(R.string.space_leave_prompt_msg_private)) {
textColor = ContextCompat.getColor(requireContext(), R.color.riotx_destructive_accent)
}
span(getString(R.string.space_leave_prompt_msg_private)) {
textColor = ContextCompat.getColor(requireContext(), R.color.riotx_destructive_accent)
}
} else {
getString(R.string.space_leave_prompt_msg)
null
}
AlertDialog.Builder(requireContext())
.setMessage(warningMessage)
.setTitle(getString(R.string.space_leave_prompt_msg))
.setPositiveButton(R.string.leave) { _, _ ->
session.coroutineScope.launch {
try {
@ -192,6 +188,7 @@ class SpaceSettingsMenuBottomSheet : VectorBaseBottomSheetDialogFragment<BottomS
}
.setNegativeButton(R.string.cancel, null)
.show()
.withColoredButton(DialogInterface.BUTTON_POSITIVE)
}
}

View file

@ -62,6 +62,22 @@ class AddRoomListController @Inject constructor(
var initialLoadOccurred = false
var expanded: Boolean = true
set(value) {
if (value != field) {
field = value
requestForcedModelBuild()
}
}
var disabled: Boolean = false
set(value) {
if (value != field) {
field = value
requestForcedModelBuild()
}
}
fun boundaryChange(boundary: ResultBoundaries) {
val boundaryHasLoadedSomething = boundary.frontLoaded || boundary.zeroItemLoaded
if (initialLoadOccurred != boundaryHasLoadedSomething) {
@ -88,6 +104,10 @@ class AddRoomListController @Inject constructor(
}
override fun addModels(models: List<EpoxyModel<*>>) {
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({

View file

@ -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
}