/ UIKit / Android View
UIKit
Chat UIKit Android View v3
Chat UIKit Android View
Chat UIKit
Android View
Version 3

Customize data sources for users

Copy link

You can display a user list that is managed independently from the user list provided by the UIKit's default data source.


UserInfo class

Copy link

When creating a custom user model, you must inherit from the UserInfo interface. The following table lists the properties of UserInfo.

PropertiesTypeDescription

userId

String

The unique ID of the user.

nickname

String?

The user's nickname. (Default: null)

profileUrl

String?

The URL of the user's profile image. (Default: null)


Globally change the user data source

Copy link

To use a custom user model, extend the UserInfo interface as shown in the code below.

class CustomUserInfo(
    private val userId: String,
    private val nickname: String? = null,
    private val profileUrl: String? = null,
    private val age: Int
): UserInfo {
    override fun getUserId(): String {
        return userId
    }

    override fun getNickname(): String? {
        return nickname
    }

    override fun getProfileUrl(): String {
        return profileUrl
    }
}

Then, set up a custom UserListQueryHandler in the Application's onCreate() method.

fun setCustomUserListQueryHandler() {
    val customUserList: List<CustomUserInfo> = emptyList()
    var loadIndex = 0
    val loadSize = 10

    SendbirdUIKit.setCustomUserListQueryHandler(
        object : CustomUserListQueryHandler {
            override fun loadInitial(handler: OnListResultHandler<UserInfo>) {
                val endIndex = min(loadSize, customUserList.size)

                handler.onResult(customUserList.subList(0, endIndex), null)
                loadIndex = endIndex
            }

            override fun loadMore(handler: OnListResultHandler<UserInfo>) {
                val endIndex = min(loadIndex + loadSize, customUserList.size)

                handler.onResult(customUserList.subList(loadIndex, endIndex), null)
                loadIndex = endIndex
            }

            override fun hasMore(): Boolean {
                return loadIndex < customUserList.count()
            }
        }
    )
}

For an in-depth practical demonstration, see our sample code.