Creating sealed wrapper class for member items
This commit is contained in:
parent
1d1dc8b1fd
commit
38fdfb27e4
|
@ -27,6 +27,7 @@ import org.matrix.android.sdk.api.session.room.sender.SenderInfo
|
|||
import org.matrix.android.sdk.api.session.user.model.User
|
||||
import java.util.Locale
|
||||
|
||||
// TODO how to represent the notify everyone @room item? EveryoneItem ??
|
||||
sealed class MatrixItem(
|
||||
open val id: String,
|
||||
open val displayName: String?,
|
||||
|
|
|
@ -30,7 +30,7 @@ import im.vector.app.features.displayname.getBestName
|
|||
import im.vector.app.features.home.AvatarRenderer
|
||||
import org.matrix.android.sdk.api.util.MatrixItem
|
||||
|
||||
// TODO create a new item for sections
|
||||
// TODO create a new item for sections: AutocompleteSection
|
||||
@EpoxyModelClass(layout = R.layout.item_autocomplete_matrix_item)
|
||||
abstract class AutocompleteMatrixItem : VectorEpoxyModel<AutocompleteMatrixItem.Holder>() {
|
||||
|
||||
|
|
|
@ -20,28 +20,43 @@ import com.airbnb.epoxy.TypedEpoxyController
|
|||
import im.vector.app.features.autocomplete.AutocompleteClickListener
|
||||
import im.vector.app.features.autocomplete.autocompleteMatrixItem
|
||||
import im.vector.app.features.home.AvatarRenderer
|
||||
import org.matrix.android.sdk.api.session.room.model.RoomMemberSummary
|
||||
import org.matrix.android.sdk.api.util.toMatrixItem
|
||||
import javax.inject.Inject
|
||||
|
||||
class AutocompleteMemberController @Inject constructor() : TypedEpoxyController<List<RoomMemberSummary>>() {
|
||||
class AutocompleteMemberController @Inject constructor() : TypedEpoxyController<List<AutocompleteMemberItem>>() {
|
||||
|
||||
var listener: AutocompleteClickListener<RoomMemberSummary>? = null
|
||||
var listener: AutocompleteClickListener<AutocompleteMemberItem>? = null
|
||||
|
||||
@Inject lateinit var avatarRenderer: AvatarRenderer
|
||||
|
||||
override fun buildModels(data: List<RoomMemberSummary>?) {
|
||||
override fun buildModels(data: List<AutocompleteMemberItem>?) {
|
||||
if (data.isNullOrEmpty()) {
|
||||
return
|
||||
}
|
||||
val host = this
|
||||
data.forEach { user ->
|
||||
autocompleteMatrixItem {
|
||||
id(user.userId)
|
||||
matrixItem(user.toMatrixItem())
|
||||
avatarRenderer(host.avatarRenderer)
|
||||
clickListener { host.listener?.onItemClick(user) }
|
||||
data.forEach { item ->
|
||||
when (item) {
|
||||
is AutocompleteMemberItem.RoomMember -> buildRoomMemberItem(item)
|
||||
is AutocompleteMemberItem.Everyone -> buildEveryoneItem(item)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// HELPER METHODS
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private fun buildRoomMemberItem(roomMember: AutocompleteMemberItem.RoomMember) {
|
||||
autocompleteMatrixItem {
|
||||
roomMember.roomMemberSummary.let { user ->
|
||||
id(user.userId)
|
||||
matrixItem(user.toMatrixItem())
|
||||
avatarRenderer(this@AutocompleteMemberController.avatarRenderer)
|
||||
clickListener { this@AutocompleteMemberController.listener?.onItemClick(roomMember) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun buildEveryoneItem(everyone: AutocompleteMemberItem.Everyone) {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* Copyright (c) 2022 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.app.features.autocomplete.member
|
||||
|
||||
import org.matrix.android.sdk.api.session.room.model.RoomMemberSummary
|
||||
import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
||||
|
||||
sealed class AutocompleteMemberItem {
|
||||
// TODO add section class
|
||||
data class RoomMember(val roomMemberSummary: RoomMemberSummary) : AutocompleteMemberItem()
|
||||
data class Everyone(val roomSummary: RoomSummary) : AutocompleteMemberItem()
|
||||
}
|
|
@ -33,7 +33,7 @@ class AutocompleteMemberPresenter @AssistedInject constructor(context: Context,
|
|||
@Assisted val roomId: String,
|
||||
session: Session,
|
||||
private val controller: AutocompleteMemberController
|
||||
) : RecyclerViewPresenter<RoomMemberSummary>(context), AutocompleteClickListener<RoomMemberSummary> {
|
||||
) : RecyclerViewPresenter<AutocompleteMemberItem>(context), AutocompleteClickListener<AutocompleteMemberItem> {
|
||||
|
||||
private val room by lazy { session.getRoom(roomId)!! }
|
||||
|
||||
|
@ -54,7 +54,7 @@ class AutocompleteMemberPresenter @AssistedInject constructor(context: Context,
|
|||
return controller.adapter
|
||||
}
|
||||
|
||||
override fun onItemClick(t: RoomMemberSummary) {
|
||||
override fun onItemClick(t: AutocompleteMemberItem) {
|
||||
dispatchClick(t)
|
||||
}
|
||||
|
||||
|
@ -72,10 +72,10 @@ class AutocompleteMemberPresenter @AssistedInject constructor(context: Context,
|
|||
.asSequence()
|
||||
.sortedBy { it.displayName }
|
||||
.disambiguate()
|
||||
// TODO check if user can notify everyone => compare user role to room permission setting
|
||||
// TODO if user can notify everyone, add entry "@room"
|
||||
// TODO check if user can notify everyone => compare user role to room permission setting: PowerLevelsContent
|
||||
// TODO if user can notify everyone, add entry AutocompleteMemberItem.Everyone
|
||||
// TODO add header sections to separate members and notification
|
||||
controller.setData(members.toList())
|
||||
controller.setData(members.map { AutocompleteMemberItem.RoomMember(it) }.toList())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ import im.vector.app.features.autocomplete.command.AutocompleteCommandPresenter
|
|||
import im.vector.app.features.autocomplete.command.CommandAutocompletePolicy
|
||||
import im.vector.app.features.autocomplete.emoji.AutocompleteEmojiPresenter
|
||||
import im.vector.app.features.autocomplete.group.AutocompleteGroupPresenter
|
||||
import im.vector.app.features.autocomplete.member.AutocompleteMemberItem
|
||||
import im.vector.app.features.autocomplete.member.AutocompleteMemberPresenter
|
||||
import im.vector.app.features.autocomplete.room.AutocompleteRoomPresenter
|
||||
import im.vector.app.features.command.Command
|
||||
|
@ -41,7 +42,6 @@ import im.vector.app.features.home.AvatarRenderer
|
|||
import im.vector.app.features.html.PillImageSpan
|
||||
import im.vector.app.features.themes.ThemeUtils
|
||||
import org.matrix.android.sdk.api.session.group.model.GroupSummary
|
||||
import org.matrix.android.sdk.api.session.room.model.RoomMemberSummary
|
||||
import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
||||
import org.matrix.android.sdk.api.util.MatrixItem
|
||||
import org.matrix.android.sdk.api.util.toMatrixItem
|
||||
|
@ -125,14 +125,18 @@ class AutoCompleter @AssistedInject constructor(
|
|||
|
||||
private fun setupMembers(backgroundDrawable: ColorDrawable, editText: EditText) {
|
||||
autocompleteMemberPresenter = autocompleteMemberPresenterFactory.create(roomId)
|
||||
Autocomplete.on<RoomMemberSummary>(editText)
|
||||
Autocomplete.on<AutocompleteMemberItem>(editText)
|
||||
.with(CharPolicy('@', true))
|
||||
.with(autocompleteMemberPresenter)
|
||||
.with(ELEVATION)
|
||||
.with(backgroundDrawable)
|
||||
.with(object : AutocompleteCallback<RoomMemberSummary> {
|
||||
override fun onPopupItemClicked(editable: Editable, item: RoomMemberSummary): Boolean {
|
||||
insertMatrixItem(editText, editable, "@", item.toMatrixItem())
|
||||
.with(object : AutocompleteCallback<AutocompleteMemberItem> {
|
||||
override fun onPopupItemClicked(editable: Editable, item: AutocompleteMemberItem): Boolean {
|
||||
when (item) {
|
||||
is AutocompleteMemberItem.RoomMember ->
|
||||
insertMatrixItem(editText, editable, "@", item.roomMemberSummary.toMatrixItem())
|
||||
is AutocompleteMemberItem.Everyone -> Unit // TODO
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
|
@ -59,6 +59,7 @@ class PillsPostProcessor @AssistedInject constructor(@Assisted private val roomI
|
|||
}
|
||||
|
||||
private fun LinkSpan.createPillSpan(roomId: String?): PillImageSpan? {
|
||||
// TODO handle @room text to create associated chip
|
||||
val permalinkData = PermalinkParser.parse(url)
|
||||
val matrixItem = when (permalinkData) {
|
||||
is PermalinkData.UserLink -> {
|
||||
|
|
Loading…
Reference in New Issue