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

View File

@@ -13,10 +13,13 @@
android:supportsRtl="true"
android:theme="@style/Theme.ElementX"
tools:targetApi="33">
<!-- Note: temporary block orientation to sensorPortrait because the RichTextEditor library is crashing on configuration change -->
<activity
android:name=".MainActivity"
android:exported="true"
android:windowSoftInputMode="adjustResize">
android:screenOrientation="sensorPortrait"
android:windowSoftInputMode="adjustResize"
tools:ignore="LockedOrientationActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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)
}

View File

@@ -5,4 +5,5 @@ import io.element.android.x.libraries.designsystem.R
object VectorIcons {
val Copy = R.drawable.ic_content_copy
val ArrowForward = R.drawable.ic_content_arrow_forward
val Delete = R.drawable.ic_baseline_delete_outline_24
}

View File

@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M6,19c0,1.1 0.9,2 2,2h8c1.1,0 2,-0.9 2,-2L18,7L6,7v12zM8,9h8v10L8,19L8,9zM15.5,4l-1,-1h-5l-1,1L5,4v2h14L19,4z"/>
</vector>

View File

@@ -2,7 +2,6 @@ package io.element.android.x.matrix.room
import io.element.android.x.core.coroutine.CoroutineDispatchers
import io.element.android.x.matrix.core.RoomId
import io.element.android.x.matrix.core.UserId
import io.element.android.x.matrix.timeline.MatrixTimeline
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
@@ -76,4 +75,11 @@ class MatrixRoom(
room.send(content, transactionId)
}
}
suspend fun redactEvent(eventId: String, reason: String? = null, ) = withContext(coroutineDispatchers.io) {
val transactionId = genTransactionId()
runCatching {
room.redact(eventId, reason, transactionId)
}
}
}