This commit is contained in:
ganfra 2022-11-22 17:22:01 +01:00
commit 5e30891765
8 changed files with 59 additions and 7 deletions

View file

@ -102,7 +102,12 @@ fun MessagesScreen(
TimelineItemActionsScreen(
sheetState = actionsSheetState,
actionsSheetState = itemActionsSheetState(),
onActionClicked = viewModel::handleItemAction
onActionClicked = {
viewModel.handleItemAction(it)
coroutineScope.launch {
actionsSheetState.hide()
}
}
)
}

View file

@ -74,15 +74,31 @@ class MessagesViewModel(
viewModelScope.launch(Dispatchers.Default) {
val currentState = awaitState()
Timber.v("Handle $action for ${currentState.itemActionsSheetState}")
val targetEvent =
currentState.itemActionsSheetState.invoke()?.targetItem ?: return@launch
when (action) {
MessagesItemAction.Copy -> Unit // TODO
MessagesItemAction.Forward -> Unit // TODO
MessagesItemAction.Redact -> handleActionRedact(targetEvent)
}
}
}
private fun handleActionRedact(event: MessagesTimelineItemState.MessageEvent) {
viewModelScope.launch {
room.redactEvent(event.id)
}
}
fun computeActionsSheetState(messagesTimelineItemState: MessagesTimelineItemState.MessageEvent) {
suspend {
val actions = listOf(
val actions = mutableListOf(
MessagesItemAction.Forward,
MessagesItemAction.Copy,
)
if (messagesTimelineItemState.isMine) {
actions.add(MessagesItemAction.Redact)
}
MessagesItemActionsSheetState(
targetItem = messagesTimelineItemState,
actions = actions

View file

@ -10,6 +10,7 @@ import androidx.compose.foundation.lazy.items
import androidx.compose.material.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import io.element.android.x.designsystem.components.VectorIcon
import io.element.android.x.features.messages.model.MessagesItemAction
@ -51,8 +52,18 @@ private fun SheetContent(
modifier = Modifier.clickable {
onActionClicked(it)
},
text = { Text(it.title) },
icon = { VectorIcon(it.icon) }
text = {
Text(
text = it.title,
color = if (it.destructive) MaterialTheme.colors.error else Color.Unspecified,
)
},
icon = {
VectorIcon(
resourceId = it.icon,
tint = if (it.destructive) MaterialTheme.colors.error else LocalContentColor.current,
)
}
)
}
}

View file

@ -5,7 +5,12 @@ import androidx.compose.runtime.Stable
import io.element.android.x.designsystem.VectorIcons
@Stable
sealed class MessagesItemAction(val title: String, @DrawableRes val icon: Int) {
sealed class MessagesItemAction(
val title: String,
@DrawableRes val icon: Int,
val destructive: Boolean = false
) {
object Forward : MessagesItemAction("Forward", VectorIcons.ArrowForward)
object Copy : MessagesItemAction("Copy", VectorIcons.Copy)
object Redact : MessagesItemAction("Redact", VectorIcons.Delete, destructive = true)
}