Handle search result click
This commit is contained in:
parent
509e658dbf
commit
f93bdc189b
3 changed files with 22 additions and 4 deletions
|
|
@ -16,8 +16,11 @@
|
|||
|
||||
package io.element.android.features.createroom.impl.root
|
||||
|
||||
import io.element.android.libraries.matrix.ui.model.MatrixUser
|
||||
|
||||
sealed interface CreateRoomRootEvents {
|
||||
data class UpdateSearchQuery(val query: String): CreateRoomRootEvents
|
||||
data class UpdateSearchQuery(val query: String) : CreateRoomRootEvents
|
||||
data class StartDM(val matrixUser: MatrixUser) : CreateRoomRootEvents
|
||||
object CreateRoom : CreateRoomRootEvents
|
||||
object InvitePeople : CreateRoomRootEvents
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import io.element.android.libraries.matrix.ui.model.MatrixUser
|
|||
import kotlinx.collections.immutable.ImmutableList
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
import kotlinx.collections.immutable.toImmutableList
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
class CreateRoomRootPresenter @Inject constructor() : Presenter<CreateRoomRootState> {
|
||||
|
|
@ -44,9 +45,10 @@ class CreateRoomRootPresenter @Inject constructor() : Presenter<CreateRoomRootSt
|
|||
|
||||
fun handleEvents(event: CreateRoomRootEvents) {
|
||||
when (event) {
|
||||
is CreateRoomRootEvents.UpdateSearchQuery -> searchQuery = event.query
|
||||
is CreateRoomRootEvents.StartDM -> handleStartDM(event.matrixUser)
|
||||
CreateRoomRootEvents.CreateRoom -> Unit // Todo Handle create room action
|
||||
CreateRoomRootEvents.InvitePeople -> Unit // Todo Handle invite people action
|
||||
is CreateRoomRootEvents.UpdateSearchQuery -> searchQuery = event.query
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -72,10 +74,14 @@ class CreateRoomRootPresenter @Inject constructor() : Presenter<CreateRoomRootSt
|
|||
val isMatrixId = MatrixPatterns.isUserId(query)
|
||||
val results = mutableListOf<MatrixUser>()// TODO trigger /search request
|
||||
if (isMatrixId && results.none { it.id.value == query }) {
|
||||
val getProfileResult: MatrixUser? = null // TODO trigger /profile quest
|
||||
val getProfileResult: MatrixUser? = null // TODO trigger /profile request
|
||||
val profile = getProfileResult ?: MatrixUser(UserId(query))
|
||||
results.add(0, profile)
|
||||
}
|
||||
return results.toImmutableList()
|
||||
}
|
||||
|
||||
private fun handleStartDM(matrixUser: MatrixUser) {
|
||||
Timber.d("handleStartDM: $matrixUser") // Todo handle start DM action
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,6 +89,7 @@ fun CreateRoomRootView(
|
|||
active = isSearchActive,
|
||||
onActiveChanged = { isSearchActive = it },
|
||||
onTextChanged = { state.eventSink(CreateRoomRootEvents.UpdateSearchQuery(it)) },
|
||||
onResultSelected = { state.eventSink(CreateRoomRootEvents.StartDM(it)) }
|
||||
)
|
||||
|
||||
if (!isSearchActive) {
|
||||
|
|
@ -134,6 +135,7 @@ fun CreateRoomSearchBar(
|
|||
modifier: Modifier = Modifier,
|
||||
onActiveChanged: (Boolean) -> Unit = {},
|
||||
onTextChanged: (String) -> Unit = {},
|
||||
onResultSelected: (MatrixUser) -> Unit = {},
|
||||
) {
|
||||
val focusManager = LocalFocusManager.current
|
||||
|
||||
|
|
@ -181,7 +183,12 @@ fun CreateRoomSearchBar(
|
|||
shape = if (!active) SearchBarDefaults.dockedShape else SearchBarDefaults.fullScreenShape,
|
||||
colors = if (!active) SearchBarDefaults.colors() else SearchBarDefaults.colors(containerColor = Color.Transparent),
|
||||
content = {
|
||||
results.forEach { CreateRoomSearchResultItem(matrixUser = it) }
|
||||
results.forEach {
|
||||
CreateRoomSearchResultItem(
|
||||
matrixUser = it,
|
||||
onClick = { onResultSelected(it) }
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
@ -210,11 +217,13 @@ fun CreateRoomActionButtonsList(
|
|||
fun CreateRoomSearchResultItem(
|
||||
matrixUser: MatrixUser,
|
||||
modifier: Modifier = Modifier,
|
||||
onClick: () -> Unit = {},
|
||||
) {
|
||||
MatrixUserRow(
|
||||
modifier = modifier.heightIn(min = 56.dp),
|
||||
matrixUser = matrixUser,
|
||||
avatarSize = AvatarSize.SMALL,
|
||||
onClick = onClick,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue