Fix / Improve 'Leave Space' UX/UI #3359

This commit is contained in:
Valere 2021-05-19 11:00:06 +02:00
parent 877a64fbce
commit abf7e275a7
2 changed files with 44 additions and 1 deletions

View File

@ -22,6 +22,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AlertDialog
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
import com.airbnb.mvrx.args
import im.vector.app.R
@ -43,9 +44,11 @@ import im.vector.app.features.spaces.manage.SpaceManageActivity
import io.reactivex.android.schedulers.AndroidSchedulers
import kotlinx.coroutines.launch
import kotlinx.parcelize.Parcelize
import me.gujun.android.span.span
import org.matrix.android.sdk.api.extensions.orFalse
import org.matrix.android.sdk.api.session.events.model.EventType
import org.matrix.android.sdk.api.session.room.powerlevels.PowerLevelsHelper
import org.matrix.android.sdk.api.session.room.powerlevels.Role
import org.matrix.android.sdk.api.util.toMatrixItem
import timber.log.Timber
import javax.inject.Inject
@ -55,6 +58,7 @@ data class SpaceBottomSheetSettingsArgs(
val spaceId: String
) : Parcelable
// XXX make proper view model before leaving beta
class SpaceSettingsMenuBottomSheet : VectorBaseBottomSheetDialogFragment<BottomSheetSpaceSettingsBinding>() {
@Inject lateinit var navigator: Navigator
@ -71,10 +75,14 @@ class SpaceSettingsMenuBottomSheet : VectorBaseBottomSheetDialogFragment<BottomS
var interactionListener: InteractionListener? = null
override val showExpanded = true
override fun injectWith(injector: ScreenComponent) {
injector.inject(this)
}
var isAdmin: Boolean = false
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): BottomSheetSpaceSettingsBinding {
return BottomSheetSpaceSettingsBinding.inflate(inflater, container, false)
}
@ -108,6 +116,8 @@ class SpaceSettingsMenuBottomSheet : VectorBaseBottomSheetDialogFragment<BottomS
views.invitePeople.isVisible = canInvite || roomSummary?.isPublic.orFalse()
views.addRooms.isVisible = canAddChild
isAdmin = powerLevelsHelper.getUserRole(session.myUserId) is Role.Admin
}.disposeOnDestroyView()
views.spaceBetaTag.setOnClickListener {
@ -138,8 +148,38 @@ 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)
}
}
} 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 (!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)
}
}
} else {
getString(R.string.space_leave_prompt_msg)
}
AlertDialog.Builder(requireContext())
.setMessage(getString(R.string.space_leave_prompt_msg))
.setMessage(warningMessage)
.setPositiveButton(R.string.leave) { _, _ ->
session.coroutineScope.launch {
try {

View File

@ -3353,6 +3353,9 @@
<string name="space_add_child_title">Add rooms</string>
<string name="leave_space">Leave Space</string>
<string name="space_leave_prompt_msg">Are you sure you want to leave the space?</string>
<string name="space_leave_prompt_msg_only_you">You are the only person here. If you leave, no one will be able to join in the future, including you.</string>
<string name="space_leave_prompt_msg_private">This space is not public. You will not be able to rejoin without an invite.</string>
<string name="space_leave_prompt_msg_as_admin">You are admin of this space, ensure that you have transferred admin right to another member before leaving.</string>
<string name="space_add_existing_rooms">Add existing rooms and space</string>