Code review

This commit is contained in:
Valere 2021-05-26 14:25:09 +02:00
parent f602caf323
commit 60dee6eea3
4 changed files with 39 additions and 78 deletions

View File

@ -39,7 +39,8 @@ import org.matrix.android.sdk.api.session.room.model.RoomType
import javax.inject.Inject
class MatrixToRoomSpaceFragment @Inject constructor(
private val avatarRenderer: AvatarRenderer
private val avatarRenderer: AvatarRenderer,
private val spaceCardRenderer: SpaceCardRenderer
) : VectorBaseFragment<FragmentMatrixToRoomSpaceCardBinding>() {
private val sharedViewModel: MatrixToBottomSheetViewModel by parentFragmentViewModel()
@ -81,13 +82,12 @@ class MatrixToRoomSpaceFragment @Inject constructor(
avatarRenderer.render(matrixItem, views.matrixToCardAvatar)
if (peek.roomType == RoomType.SPACE) {
views.matrixToBetaTag.isVisible = true
views.matrixToAccessImage.isVisible = true
if (peek.isPublic) {
views.matrixToAccessText.setTextOrHide(context?.getString(R.string.public_space))
views.matrixToAccessImage.isVisible = true
views.matrixToAccessImage.setImageResource(R.drawable.ic_public_room)
} else {
views.matrixToAccessText.setTextOrHide(context?.getString(R.string.private_space))
views.matrixToAccessImage.isVisible = true
views.matrixToAccessImage.setImageResource(R.drawable.ic_room_private)
}
} else {
@ -179,20 +179,7 @@ class MatrixToRoomSpaceFragment @Inject constructor(
when (state.peopleYouKnow) {
is Success -> {
val someYouKnow = state.peopleYouKnow.invoke()
if (someYouKnow.isEmpty()) {
views.peopleYouMayKnowText.isVisible = false
} else {
someYouKnow.forEachIndexed { index, item ->
images[index].isVisible = true
avatarRenderer.render(item, images[index])
}
views.peopleYouMayKnowText.setTextOrHide(
resources.getQuantityString(R.plurals.space_people_you_know,
someYouKnow.count(),
someYouKnow.count()
)
)
}
spaceCardRenderer.renderPeopleYouKnow(views, someYouKnow)
}
else -> {
views.peopleYouMayKnowText.isVisible = false

View File

@ -20,8 +20,6 @@ import androidx.core.view.isGone
import androidx.core.view.isVisible
import im.vector.app.R
import im.vector.app.core.extensions.setTextOrHide
import im.vector.app.core.resources.ColorProvider
import im.vector.app.core.resources.DrawableProvider
import im.vector.app.core.resources.StringProvider
import im.vector.app.databinding.FragmentMatrixToRoomSpaceCardBinding
import im.vector.app.features.home.AvatarRenderer
@ -31,14 +29,13 @@ import im.vector.app.features.home.room.detail.timeline.tools.linkify
import org.matrix.android.sdk.api.session.room.model.RoomSummary
import org.matrix.android.sdk.api.session.room.model.SpaceChildInfo
import org.matrix.android.sdk.api.session.user.model.User
import org.matrix.android.sdk.api.util.MatrixItem
import org.matrix.android.sdk.api.util.toMatrixItem
import javax.inject.Inject
class SpaceCardHelper @Inject constructor(
class SpaceCardRenderer @Inject constructor(
private val avatarRenderer: AvatarRenderer,
private val stringProvider: StringProvider,
private val drawableProvider: DrawableProvider,
private val colorProvider: ColorProvider
private val stringProvider: StringProvider
) {
fun render(spaceSummary: RoomSummary?,
@ -74,28 +71,7 @@ class SpaceCardHelper @Inject constructor(
inCard.matrixToMemberPills.isVisible = false
}
val images = listOf(
inCard.knownMember1,
inCard.knownMember2,
inCard.knownMember3,
inCard.knownMember4,
inCard.knownMember5
).onEach { it.isGone = true }
if (peopleYouKnow.isEmpty()) {
inCard.peopleYouMayKnowText.isVisible = false
} else {
peopleYouKnow.forEachIndexed { index, item ->
images[index].isVisible = true
avatarRenderer.render(item.toMatrixItem(), images[index])
}
inCard.peopleYouMayKnowText.setTextOrHide(
stringProvider.getQuantityString(R.plurals.space_people_you_know,
peopleYouKnow.count(),
peopleYouKnow.count()
)
)
}
renderPeopleYouKnow(inCard, peopleYouKnow.map { it.toMatrixItem() })
}
inCard.matrixToCardDescText.movementMethod = createLinkMovementMethod(object : TimelineEventController.UrlClickCallback {
override fun onUrlClicked(url: String, title: String): Boolean {
@ -142,6 +118,11 @@ class SpaceCardHelper @Inject constructor(
inCard.matrixToMemberPills.isVisible = false
}
renderPeopleYouKnow(inCard, peopleYouKnow.map { it.toMatrixItem() })
}
}
fun renderPeopleYouKnow(inCard: FragmentMatrixToRoomSpaceCardBinding, peopleYouKnow: List<MatrixItem.UserItem>) {
val images = listOf(
inCard.knownMember1,
inCard.knownMember2,
@ -155,7 +136,7 @@ class SpaceCardHelper @Inject constructor(
} else {
peopleYouKnow.forEachIndexed { index, item ->
images[index].isVisible = true
avatarRenderer.render(item.toMatrixItem(), images[index])
avatarRenderer.render(item, images[index])
}
inCard.peopleYouMayKnowText.setTextOrHide(
stringProvider.getQuantityString(R.plurals.space_people_you_know,
@ -165,5 +146,4 @@ class SpaceCardHelper @Inject constructor(
)
}
}
}
}

View File

@ -42,7 +42,7 @@ import im.vector.app.core.utils.isValidUrl
import im.vector.app.core.utils.openUrlInExternalBrowser
import im.vector.app.databinding.FragmentRoomDirectoryPickerBinding
import im.vector.app.features.home.room.detail.timeline.TimelineEventController
import im.vector.app.features.matrixto.SpaceCardHelper
import im.vector.app.features.matrixto.SpaceCardRenderer
import im.vector.app.features.permalink.PermalinkHandler
import im.vector.app.features.spaces.manage.ManageType
import im.vector.app.features.spaces.manage.SpaceManageActivity
@ -61,7 +61,7 @@ data class SpaceDirectoryArgs(
class SpaceDirectoryFragment @Inject constructor(
private val epoxyController: SpaceDirectoryController,
private val permalinkHandler: PermalinkHandler,
private val spaceCardHelper: SpaceCardHelper,
private val spaceCardRenderer: SpaceCardRenderer,
private val colorProvider: ColorProvider
) : VectorBaseFragment<FragmentRoomDirectoryPickerBinding>(),
SpaceDirectoryController.InteractionListener,
@ -93,12 +93,6 @@ class SpaceDirectoryFragment @Inject constructor(
views.spaceCard.matrixToCardMainButton.isVisible = false
views.spaceCard.matrixToCardSecondaryButton.isVisible = false
views.spaceCard.knownMember1.isVisible = false
views.spaceCard.knownMember2.isVisible = false
views.spaceCard.knownMember3.isVisible = false
views.spaceCard.knownMember4.isVisible = false
views.spaceCard.knownMember5.isVisible = false
views.spaceCard.peopleYouMayKnowText.isVisible = false
}
override fun onDestroyView() {
@ -118,12 +112,12 @@ class SpaceDirectoryFragment @Inject constructor(
val title = getString(R.string.space_explore_activity_title)
views.toolbar.title = title
spaceCardHelper.render(state.spaceSummary.invoke(), emptyList(), this, views.spaceCard)
spaceCardRenderer.render(state.spaceSummary.invoke(), emptyList(), this, views.spaceCard)
} else {
val title = currentParent.name ?: currentParent.canonicalAlias ?: getString(R.string.space_explore_activity_title)
views.toolbar.title = title
spaceCardHelper.render(currentParent, emptyList(), this, views.spaceCard)
spaceCardRenderer.render(currentParent, emptyList(), this, views.spaceCard)
}
}

View File

@ -37,7 +37,7 @@ import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment
import im.vector.app.core.utils.toast
import im.vector.app.databinding.BottomSheetInvitedToSpaceBinding
import im.vector.app.features.home.AvatarRenderer
import im.vector.app.features.matrixto.SpaceCardHelper
import im.vector.app.features.matrixto.SpaceCardRenderer
import kotlinx.parcelize.Parcelize
import org.matrix.android.sdk.api.util.toMatrixItem
import javax.inject.Inject
@ -60,7 +60,7 @@ class SpaceInviteBottomSheet : VectorBaseBottomSheetDialogFragment<BottomSheetIn
lateinit var avatarRenderer: AvatarRenderer
@Inject
lateinit var spaceCardHelper: SpaceCardHelper
lateinit var spaceCardRenderer: SpaceCardRenderer
private val viewModel: SpaceInviteBottomSheetViewModel by fragmentViewModel(SpaceInviteBottomSheetViewModel::class)
@ -135,7 +135,7 @@ class SpaceInviteBottomSheet : VectorBaseBottomSheetDialogFragment<BottomSheetIn
views.inviterMxid.isVisible = false
}
spaceCardHelper.render(summary, state.peopleYouKnow.invoke().orEmpty(), null, views.spaceCard)
spaceCardRenderer.render(summary, state.peopleYouKnow.invoke().orEmpty(), null, views.spaceCard)
views.spaceCard.matrixToCardMainButton.button.text = getString(R.string.accept)
views.spaceCard.matrixToCardSecondaryButton.button.text = getString(R.string.decline)