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