Display name and avatar of the user

This commit is contained in:
Benoit Marty 2019-11-05 18:36:40 +01:00
parent a87310ac15
commit b6bb714264
8 changed files with 98 additions and 44 deletions

View file

@ -54,8 +54,8 @@ class RxSession(private val session: Session) {
return session.liveUsers().asObservable()
}
fun liveIgnoredUserIds(): Observable<List<String>> {
return session.liveIgnoredUserIds().asObservable()
fun liveIgnoredUsers(): Observable<List<User>> {
return session.liveIgnoredUsers().asObservable()
}
fun livePagedUsers(filter: String? = null): Observable<PagedList<User>> {

View file

@ -66,9 +66,9 @@ interface UserService {
fun livePagedUsers(filter: String? = null): LiveData<PagedList<User>>
/**
* Get list of ignored users id
* Get list of ignored users
*/
fun liveIgnoredUserIds(): LiveData<List<String>>
fun liveIgnoredUsers(): LiveData<List<User>>
/**
* Ignore users

View file

@ -121,14 +121,14 @@ internal class DefaultUserService @Inject constructor(private val monarchy: Mona
.executeBy(taskExecutor)
}
override fun liveIgnoredUserIds(): LiveData<List<String>> {
override fun liveIgnoredUsers(): LiveData<List<User>> {
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) }
)
}

View file

@ -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<String>) {
private fun buildIgnoredUserModels(userIds: List<User>) {
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) }
}
}
}

View file

@ -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<String> = emptyList(),
val ignoredUsers: List<User> = emptyList(),
val unIgnoreRequest: Async<Unit> = 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()
)
}
}

View file

@ -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<IgnoredUserItem.Holder>() {
@EpoxyModelClass(layout = R.layout.item_user)
abstract class UserItem : VectorEpoxyModel<UserItem.Holder>() {
@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<TextView>(R.id.itemIgnoredUserId)
val root by bind<View>(R.id.itemUserRoot)
val avatarImage by bind<ImageView>(R.id.itemUserAvatar)
val userIdText by bind<TextView>(R.id.itemUserId)
val displayNameText by bind<TextView>(R.id.itemUserName)
}
}

View file

@ -1,21 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/itemIgnoredUserId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?riotx_background"
android:clickable="true"
android:ellipsize="end"
android:focusable="true"
android:foreground="?attr/selectableItemBackground"
android:gravity="center_vertical"
android:lines="2"
android:maxLines="2"
android:minHeight="?listPreferredItemHeight"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:textColor="?riotx_text_primary"
android:textSize="16sp"
tools:text="@sample/matrix.json/data/mxid" />

View file

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/itemUserRoot"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?riotx_background"
android:foreground="?attr/selectableItemBackground"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="8dp">
<ImageView
android:id="@+id/itemUserAvatar"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginStart="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:src="@tools:sample/avatars" />
<TextView
android:id="@+id/itemUserId"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="12dp"
android:ellipsize="end"
android:maxLines="1"
android:textColor="?riotx_text_primary"
android:textSize="15sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/itemUserName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/itemUserAvatar"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed"
tools:text="@sample/matrix.json/data/mxid" />
<TextView
android:id="@+id/itemUserName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:ellipsize="end"
android:maxLines="1"
android:textColor="?riotx_text_secondary"
android:textSize="15sp"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/itemUserAvatar"
app:layout_constraintTop_toBottomOf="@+id/itemUserId"
tools:text="@sample/matrix.json/data/displayName"
tools:visibility="visible" />
</androidx.constraintlayout.widget.ConstraintLayout>