diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/RoomSummary.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/RoomSummary.kt index 447ba563de..53268e5805 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/RoomSummary.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/RoomSummary.kt @@ -30,6 +30,8 @@ data class RoomSummary( val topic: String = "", val avatarUrl: String = "", val isDirect: Boolean = false, + val joinedMembersCount: Int? = 0, + val invitedMembersCount: Int? = 0, val latestPreviewableEvent: TimelineEvent? = null, val otherMemberIds: List = emptyList(), val notificationCount: Int = 0, diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/mapper/RoomSummaryMapper.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/mapper/RoomSummaryMapper.kt index 2577bec581..80056c2b2f 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/mapper/RoomSummaryMapper.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/mapper/RoomSummaryMapper.kt @@ -60,6 +60,8 @@ internal class RoomSummaryMapper @Inject constructor( avatarUrl = roomSummaryEntity.avatarUrl ?: "", isDirect = roomSummaryEntity.isDirect, latestPreviewableEvent = latestEvent, + joinedMembersCount = roomSummaryEntity.joinedMembersCount, + invitedMembersCount = roomSummaryEntity.invitedMembersCount, otherMemberIds = roomSummaryEntity.otherMemberIds.toList(), highlightCount = roomSummaryEntity.highlightCount, notificationCount = roomSummaryEntity.notificationCount, diff --git a/vector/src/main/java/im/vector/riotx/core/epoxy/profiles/ProfileItemAction.kt b/vector/src/main/java/im/vector/riotx/core/epoxy/profiles/ProfileItemAction.kt index eb34834f27..5de1958783 100644 --- a/vector/src/main/java/im/vector/riotx/core/epoxy/profiles/ProfileItemAction.kt +++ b/vector/src/main/java/im/vector/riotx/core/epoxy/profiles/ProfileItemAction.kt @@ -16,16 +16,20 @@ package im.vector.riotx.core.epoxy.profiles +import android.content.res.ColorStateList import android.view.View import android.widget.ImageView import android.widget.TextView +import androidx.core.content.ContextCompat import androidx.core.view.isVisible +import androidx.core.widget.ImageViewCompat import com.airbnb.epoxy.EpoxyAttribute import com.airbnb.epoxy.EpoxyModelClass import im.vector.riotx.R import im.vector.riotx.core.epoxy.VectorEpoxyHolder import im.vector.riotx.core.epoxy.VectorEpoxyModel import im.vector.riotx.core.extensions.setTextOrHide +import im.vector.riotx.features.themes.ThemeUtils @EpoxyModelClass(layout = R.layout.item_profile_action) abstract class ProfileItemAction : VectorEpoxyModel() { @@ -39,6 +43,8 @@ abstract class ProfileItemAction : VectorEpoxyModel() @EpoxyAttribute var editable: Boolean = true @EpoxyAttribute + var destructive: Boolean = false + @EpoxyAttribute lateinit var listener: View.OnClickListener override fun bind(holder: Holder) { @@ -46,6 +52,12 @@ abstract class ProfileItemAction : VectorEpoxyModel() holder.view.setOnClickListener(listener) holder.editable.isVisible = editable holder.title.text = title + val tintColor = if (destructive) { + ContextCompat.getColor(holder.view.context, R.color.riotx_notice) + } else { + ThemeUtils.getColor(holder.view.context, R.attr.riotx_text_primary) + } + holder.title.setTextColor(tintColor) holder.subtitle.setTextOrHide(subtitle) if (iconRes != 0) { holder.icon.setImageResource(iconRes) diff --git a/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileController.kt b/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileController.kt index f321d54274..390686567b 100644 --- a/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileController.kt +++ b/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileController.kt @@ -17,8 +17,11 @@ package im.vector.riotx.features.roomprofile +import androidx.annotation.DrawableRes +import androidx.annotation.StringRes import com.airbnb.epoxy.TypedEpoxyController import im.vector.riotx.R +import im.vector.riotx.core.epoxy.DividerItem_ import im.vector.riotx.core.epoxy.dividerItem import im.vector.riotx.core.epoxy.profiles.profileItemAction import im.vector.riotx.core.epoxy.profiles.profileItemSection @@ -33,7 +36,10 @@ class RoomProfileController @Inject constructor(private val stringProvider: Stri interface Callback { fun onLearnMoreClicked() fun onMemberListClicked() + fun onNotificationsClicked() + fun onUploadsClicked() fun onSettingsClicked() + fun onLeaveRoomClicked() } override fun buildModels(data: RoomProfileViewState?) { @@ -43,60 +49,88 @@ class RoomProfileController @Inject constructor(private val stringProvider: Stri val roomSummary = data.roomSummary() - profileItemSection { - id("section_security") - title("Security") - } - - + // Security + buildSection(stringProvider.getString(R.string.room_profile_section_security)) val learnMoreSubtitle = if (data.isEncrypted) { R.string.room_profile_encrypted_subtitle } else { R.string.room_profile_not_encrypted_subtitle } - profileItemAction { - id("action_learn_more") - title("Learn more") - editable(true) - subtitle(stringProvider.getString(learnMoreSubtitle)) - listener { _ -> - callback?.onLearnMoreClicked() - } - } - - dividerItem { - id("action_learn_more_divider") - } - - profileItemSection { - id("section_options") - title("Options") - } - - val numberOfMembers = (roomSummary?.otherMemberIds?.size ?: 0) + 1 - profileItemAction { - iconRes(R.drawable.ic_person_outline_black) - id("action_member_list") - title(stringProvider.getString(R.string.room_profile_member_list_title, numberOfMembers)) - editable(true) - listener { _ -> - callback?.onMemberListClicked() - } - } - - dividerItem { - id("action_member_list_divider") - } - - profileItemAction { - iconRes(R.drawable.ic_room_actions_settings) - id("action_settings") - title("Room settings") - editable(true) - listener { _ -> - callback?.onSettingsClicked() - } - } + buildAction( + id = "learn_more", + title = stringProvider.getString(R.string.room_profile_section_security_learn_more), + subtitle = stringProvider.getString(learnMoreSubtitle), + action = { callback?.onLearnMoreClicked() } + ) + // More + buildSection(stringProvider.getString(R.string.room_profile_section_more)) + buildAction( + id = "settings", + title = stringProvider.getString(R.string.room_profile_section_more_settings), + icon = R.drawable.ic_room_profile_settings, + action = { callback?.onSettingsClicked() } + ) + buildAction( + id = "notifications", + title = stringProvider.getString(R.string.room_profile_section_more_notifications), + icon = R.drawable.ic_room_profile_notification, + action = { callback?.onNotificationsClicked() } + ) + val numberOfMembers = roomSummary?.joinedMembersCount?.toString() ?: "-" + buildAction( + id = "member_list", + title = stringProvider.getString(R.string.room_profile_section_more_member_list, numberOfMembers), + icon = R.drawable.ic_room_profile_member_list, + action = { callback?.onMemberListClicked() } + ) + buildAction( + id = "uploads", + title = stringProvider.getString(R.string.room_profile_section_more_uploads), + icon = R.drawable.ic_room_profile_uploads, + action = { callback?.onUploadsClicked() } + ) + buildAction( + id = "leave", + title = stringProvider.getString(R.string.room_profile_section_more_leave), + divider = false, + destructive = true, + action = { callback?.onLeaveRoomClicked() } + ) } + + private fun buildSection(title: String) { + profileItemSection { + id("section_$title") + title(title) + } + } + + private fun buildAction( + id: String, + title: String, + subtitle: String? = null, + @DrawableRes icon: Int = 0, + destructive: Boolean = false, + divider: Boolean = true, + action: () -> Unit + ) { + + profileItemAction { + iconRes(icon) + id("action_$id") + subtitle(subtitle) + destructive(destructive) + title(title) + listener { _ -> + action() + } + } + + DividerItem_() + .id("divider_$title") + .addIf(divider, this) + } + + } diff --git a/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileFragment.kt b/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileFragment.kt index 2523f8f6ff..a659ba4c00 100644 --- a/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileFragment.kt @@ -61,7 +61,6 @@ class RoomProfileFragment @Inject constructor( roomProfileRecyclerView.setHasFixedSize(true) roomProfileRecyclerView.layoutManager = LinearLayoutManager(requireContext(), RecyclerView.VERTICAL, false) roomProfileRecyclerView.adapter = roomProfileController.adapter - } override fun onDestroyView() { @@ -77,7 +76,8 @@ class RoomProfileFragment @Inject constructor( } else { roomProfileNameView.text = it.displayName roomProfileNameView2.text = it.displayName - roomProfileIdView.text = it.roomId + // Use canonical alias when PR with alias management will be merged + roomProfileAliasView.text = it.roomId roomProfileTopicView.setTextOrHide(it.topic) avatarRenderer.render(it, roomProfileAvatarView) } @@ -92,12 +92,23 @@ class RoomProfileFragment @Inject constructor( } override fun onMemberListClicked() { - vectorBaseActivity.notImplemented("Room member list") + vectorBaseActivity.notImplemented("See room member list") } override fun onSettingsClicked() { - vectorBaseActivity.notImplemented("Room settings") + vectorBaseActivity.notImplemented("See Room settings") } + override fun onNotificationsClicked() { + vectorBaseActivity.notImplemented("See notifications") + } + + override fun onUploadsClicked() { + vectorBaseActivity.notImplemented("See uploads") + } + + override fun onLeaveRoomClicked() { + vectorBaseActivity.notImplemented("Leave room") + } } diff --git a/vector/src/main/res/drawable/ic_room_profile_member_list.xml b/vector/src/main/res/drawable/ic_room_profile_member_list.xml new file mode 100644 index 0000000000..a80a0d4811 --- /dev/null +++ b/vector/src/main/res/drawable/ic_room_profile_member_list.xml @@ -0,0 +1,51 @@ + + + + + + + + diff --git a/vector/src/main/res/drawable/ic_room_profile_notification.xml b/vector/src/main/res/drawable/ic_room_profile_notification.xml new file mode 100644 index 0000000000..f2b500815d --- /dev/null +++ b/vector/src/main/res/drawable/ic_room_profile_notification.xml @@ -0,0 +1,25 @@ + + + + + diff --git a/vector/src/main/res/drawable/ic_room_profile_settings.xml b/vector/src/main/res/drawable/ic_room_profile_settings.xml new file mode 100644 index 0000000000..494ba69f14 --- /dev/null +++ b/vector/src/main/res/drawable/ic_room_profile_settings.xml @@ -0,0 +1,30 @@ + + + + + diff --git a/vector/src/main/res/drawable/ic_room_profile_uploads.xml b/vector/src/main/res/drawable/ic_room_profile_uploads.xml new file mode 100644 index 0000000000..914a70f7fb --- /dev/null +++ b/vector/src/main/res/drawable/ic_room_profile_uploads.xml @@ -0,0 +1,37 @@ + + + + + + diff --git a/vector/src/main/res/layout/fragment_room_profile.xml b/vector/src/main/res/layout/fragment_room_profile.xml index d7e3ca2555..8b3ac8f608 100644 --- a/vector/src/main/res/layout/fragment_room_profile.xml +++ b/vector/src/main/res/layout/fragment_room_profile.xml @@ -44,7 +44,7 @@ tools:text="Random" /> + app:layout_constraintTop_toTopOf="parent" + tools:src="@drawable/ic_room_profile_notification" /> @@ -72,8 +74,8 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_arrow_right" - android:visibility="gone" android:tint="?riotx_text_secondary" + android:visibility="gone" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent" diff --git a/vector/src/main/res/values/strings_riotX.xml b/vector/src/main/res/values/strings_riotX.xml index 1cd27b39b4..feaa9f5db5 100644 --- a/vector/src/main/res/values/strings_riotX.xml +++ b/vector/src/main/res/values/strings_riotX.xml @@ -21,6 +21,13 @@ Messages in this room are not end-to-end encrypted. Messages in this room are end-to-end encrypted. - "%1$d people" + Security + Learn more + More + Room settings + Notifications + "%1$s people" + Uploads + Leave Room