diff --git a/matrix-sdk-android-rx/src/main/java/im/vector/matrix/rx/RxSession.kt b/matrix-sdk-android-rx/src/main/java/im/vector/matrix/rx/RxSession.kt index 1ffb056f55..1572851d3a 100644 --- a/matrix-sdk-android-rx/src/main/java/im/vector/matrix/rx/RxSession.kt +++ b/matrix-sdk-android-rx/src/main/java/im/vector/matrix/rx/RxSession.kt @@ -54,8 +54,8 @@ class RxSession(private val session: Session) { return session.liveUsers().asObservable() } - fun liveIgnoredUserIds(): Observable> { - return session.liveIgnoredUserIds().asObservable() + fun liveIgnoredUsers(): Observable> { + return session.liveIgnoredUsers().asObservable() } fun livePagedUsers(filter: String? = null): Observable> { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/user/UserService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/user/UserService.kt index abc3c9330e..2a93a876f6 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/user/UserService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/user/UserService.kt @@ -66,9 +66,9 @@ interface UserService { fun livePagedUsers(filter: String? = null): LiveData> /** - * Get list of ignored users id + * Get list of ignored users */ - fun liveIgnoredUserIds(): LiveData> + fun liveIgnoredUsers(): LiveData> /** * Ignore users diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/DefaultUserService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/DefaultUserService.kt index 5e21c58e09..d314c8d108 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/DefaultUserService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/DefaultUserService.kt @@ -121,14 +121,14 @@ internal class DefaultUserService @Inject constructor(private val monarchy: Mona .executeBy(taskExecutor) } - override fun liveIgnoredUserIds(): LiveData> { + override fun liveIgnoredUsers(): LiveData> { return monarchy.findAllMappedWithChanges( { realm -> realm.where(IgnoredUserEntity::class.java) .isNotEmpty(IgnoredUserEntityFields.USER_ID) .sort(IgnoredUserEntityFields.USER_ID) }, - { it.userId } + { getUser(it.userId) ?: User(userId = it.userId) } ) } diff --git a/vector/src/main/java/im/vector/riotx/features/settings/ignored/IgnoredUsersController.kt b/vector/src/main/java/im/vector/riotx/features/settings/ignored/IgnoredUsersController.kt index 845f9bfb73..120781874d 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/ignored/IgnoredUsersController.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/ignored/IgnoredUsersController.kt @@ -17,12 +17,15 @@ package im.vector.riotx.features.settings.ignored import com.airbnb.epoxy.EpoxyController +import im.vector.matrix.android.api.session.user.model.User import im.vector.riotx.R import im.vector.riotx.core.epoxy.noResultItem import im.vector.riotx.core.resources.StringProvider +import im.vector.riotx.features.home.AvatarRenderer import javax.inject.Inject -class IgnoredUsersController @Inject constructor(private val stringProvider: StringProvider) : EpoxyController() { +class IgnoredUsersController @Inject constructor(private val stringProvider: StringProvider, + private val avatarRenderer: AvatarRenderer) : EpoxyController() { var callback: Callback? = null private var viewState: IgnoredUsersViewState? = null @@ -38,10 +41,10 @@ class IgnoredUsersController @Inject constructor(private val stringProvider: Str override fun buildModels() { val nonNullViewState = viewState ?: return - buildIgnoredUserModels(nonNullViewState.ignoredUserIds) + buildIgnoredUserModels(nonNullViewState.ignoredUsers) } - private fun buildIgnoredUserModels(userIds: List) { + private fun buildIgnoredUserModels(userIds: List) { if (userIds.isEmpty()) { noResultItem { id("empty") @@ -49,10 +52,11 @@ class IgnoredUsersController @Inject constructor(private val stringProvider: Str } } else { userIds.forEach { userId -> - ignoredUserItem { - id(userId) - userId(userId) - itemClickAction { callback?.onUserIdClicked(userId) } + userItem { + id(userId.userId) + avatarRenderer(avatarRenderer) + user(userId) + itemClickAction { callback?.onUserIdClicked(userId.userId) } } } } diff --git a/vector/src/main/java/im/vector/riotx/features/settings/ignored/IgnoredUsersViewModel.kt b/vector/src/main/java/im/vector/riotx/features/settings/ignored/IgnoredUsersViewModel.kt index ae8060dcd0..a9f142058d 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/ignored/IgnoredUsersViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/ignored/IgnoredUsersViewModel.kt @@ -21,12 +21,13 @@ import com.squareup.inject.assisted.Assisted import com.squareup.inject.assisted.AssistedInject import im.vector.matrix.android.api.MatrixCallback import im.vector.matrix.android.api.session.Session +import im.vector.matrix.android.api.session.user.model.User import im.vector.matrix.rx.rx import im.vector.riotx.core.extensions.postLiveEvent import im.vector.riotx.core.platform.VectorViewModel data class IgnoredUsersViewState( - val ignoredUserIds: List = emptyList(), + val ignoredUsers: List = emptyList(), val unIgnoreRequest: Async = Uninitialized ) : MvRxState @@ -57,10 +58,10 @@ class IgnoredUsersViewModel @AssistedInject constructor(@Assisted initialState: private fun observeIgnoredUsers() { session.rx() - .liveIgnoredUserIds() + .liveIgnoredUsers() .execute { async -> copy( - ignoredUserIds = async.invoke().orEmpty() + ignoredUsers = async.invoke().orEmpty() ) } } diff --git a/vector/src/main/java/im/vector/riotx/features/settings/ignored/IgnoredUserItem.kt b/vector/src/main/java/im/vector/riotx/features/settings/ignored/UserItem.kt similarity index 56% rename from vector/src/main/java/im/vector/riotx/features/settings/ignored/IgnoredUserItem.kt rename to vector/src/main/java/im/vector/riotx/features/settings/ignored/UserItem.kt index 2ce7df1dc4..a9c1b98915 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/ignored/IgnoredUserItem.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/ignored/UserItem.kt @@ -15,33 +15,45 @@ */ package im.vector.riotx.features.settings.ignored +import android.view.View +import android.widget.ImageView import android.widget.TextView import com.airbnb.epoxy.EpoxyAttribute import com.airbnb.epoxy.EpoxyModelClass +import im.vector.matrix.android.api.session.user.model.User 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.home.AvatarRenderer /** - * A list item for ignored user. + * A list item for User. */ -@EpoxyModelClass(layout = R.layout.item_ignored_user) -abstract class IgnoredUserItem : VectorEpoxyModel() { +@EpoxyModelClass(layout = R.layout.item_user) +abstract class UserItem : VectorEpoxyModel() { @EpoxyAttribute - var userId: String? = null + lateinit var avatarRenderer: AvatarRenderer + + @EpoxyAttribute + lateinit var user: User @EpoxyAttribute var itemClickAction: (() -> Unit)? = null override fun bind(holder: Holder) { - holder.userIdText.setTextOrHide(userId) + holder.root.setOnClickListener { itemClickAction?.invoke() } - holder.userIdText.setOnClickListener { itemClickAction?.invoke() } + avatarRenderer.render(user, holder.avatarImage) + holder.userIdText.setTextOrHide(user.userId) + holder.displayNameText.setTextOrHide(user.displayName) } class Holder : VectorEpoxyHolder() { - val userIdText by bind(R.id.itemIgnoredUserId) + val root by bind(R.id.itemUserRoot) + val avatarImage by bind(R.id.itemUserAvatar) + val userIdText by bind(R.id.itemUserId) + val displayNameText by bind(R.id.itemUserName) } } diff --git a/vector/src/main/res/layout/item_ignored_user.xml b/vector/src/main/res/layout/item_ignored_user.xml deleted file mode 100644 index 7003bb30ae..0000000000 --- a/vector/src/main/res/layout/item_ignored_user.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - diff --git a/vector/src/main/res/layout/item_user.xml b/vector/src/main/res/layout/item_user.xml new file mode 100644 index 0000000000..20e339528a --- /dev/null +++ b/vector/src/main/res/layout/item_user.xml @@ -0,0 +1,58 @@ + + + + + + + + + + \ No newline at end of file