Merge branch 'develop' of https://github.com/vector-im/element-x-android-poc into develop
This commit is contained in:
commit
07363dbe63
8 changed files with 59 additions and 7 deletions
|
|
@ -13,10 +13,13 @@
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/Theme.ElementX"
|
android:theme="@style/Theme.ElementX"
|
||||||
tools:targetApi="33">
|
tools:targetApi="33">
|
||||||
|
<!-- Note: temporary block orientation to sensorPortrait because the RichTextEditor library is crashing on configuration change -->
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:windowSoftInputMode="adjustResize">
|
android:screenOrientation="sensorPortrait"
|
||||||
|
android:windowSoftInputMode="adjustResize"
|
||||||
|
tools:ignore="LockedOrientationActivity">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -102,7 +102,12 @@ fun MessagesScreen(
|
||||||
TimelineItemActionsScreen(
|
TimelineItemActionsScreen(
|
||||||
sheetState = actionsSheetState,
|
sheetState = actionsSheetState,
|
||||||
actionsSheetState = itemActionsSheetState(),
|
actionsSheetState = itemActionsSheetState(),
|
||||||
onActionClicked = viewModel::handleItemAction
|
onActionClicked = {
|
||||||
|
viewModel.handleItemAction(it)
|
||||||
|
coroutineScope.launch {
|
||||||
|
actionsSheetState.hide()
|
||||||
|
}
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -74,15 +74,31 @@ class MessagesViewModel(
|
||||||
viewModelScope.launch(Dispatchers.Default) {
|
viewModelScope.launch(Dispatchers.Default) {
|
||||||
val currentState = awaitState()
|
val currentState = awaitState()
|
||||||
Timber.v("Handle $action for ${currentState.itemActionsSheetState}")
|
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) {
|
fun computeActionsSheetState(messagesTimelineItemState: MessagesTimelineItemState.MessageEvent) {
|
||||||
suspend {
|
suspend {
|
||||||
val actions = listOf(
|
val actions = mutableListOf(
|
||||||
MessagesItemAction.Forward,
|
MessagesItemAction.Forward,
|
||||||
MessagesItemAction.Copy,
|
MessagesItemAction.Copy,
|
||||||
)
|
)
|
||||||
|
if (messagesTimelineItemState.isMine) {
|
||||||
|
actions.add(MessagesItemAction.Redact)
|
||||||
|
}
|
||||||
MessagesItemActionsSheetState(
|
MessagesItemActionsSheetState(
|
||||||
targetItem = messagesTimelineItemState,
|
targetItem = messagesTimelineItemState,
|
||||||
actions = actions
|
actions = actions
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import androidx.compose.foundation.lazy.items
|
||||||
import androidx.compose.material.*
|
import androidx.compose.material.*
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import io.element.android.x.designsystem.components.VectorIcon
|
import io.element.android.x.designsystem.components.VectorIcon
|
||||||
import io.element.android.x.features.messages.model.MessagesItemAction
|
import io.element.android.x.features.messages.model.MessagesItemAction
|
||||||
|
|
@ -51,8 +52,18 @@ private fun SheetContent(
|
||||||
modifier = Modifier.clickable {
|
modifier = Modifier.clickable {
|
||||||
onActionClicked(it)
|
onActionClicked(it)
|
||||||
},
|
},
|
||||||
text = { Text(it.title) },
|
text = {
|
||||||
icon = { VectorIcon(it.icon) }
|
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,
|
||||||
|
)
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,12 @@ import androidx.compose.runtime.Stable
|
||||||
import io.element.android.x.designsystem.VectorIcons
|
import io.element.android.x.designsystem.VectorIcons
|
||||||
|
|
||||||
@Stable
|
@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 Forward : MessagesItemAction("Forward", VectorIcons.ArrowForward)
|
||||||
object Copy : MessagesItemAction("Copy", VectorIcons.Copy)
|
object Copy : MessagesItemAction("Copy", VectorIcons.Copy)
|
||||||
|
object Redact : MessagesItemAction("Redact", VectorIcons.Delete, destructive = true)
|
||||||
}
|
}
|
||||||
|
|
@ -5,4 +5,5 @@ import io.element.android.x.libraries.designsystem.R
|
||||||
object VectorIcons {
|
object VectorIcons {
|
||||||
val Copy = R.drawable.ic_content_copy
|
val Copy = R.drawable.ic_content_copy
|
||||||
val ArrowForward = R.drawable.ic_content_arrow_forward
|
val ArrowForward = R.drawable.ic_content_arrow_forward
|
||||||
|
val Delete = R.drawable.ic_baseline_delete_outline_24
|
||||||
}
|
}
|
||||||
|
|
@ -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>
|
||||||
|
|
@ -2,7 +2,6 @@ package io.element.android.x.matrix.room
|
||||||
|
|
||||||
import io.element.android.x.core.coroutine.CoroutineDispatchers
|
import io.element.android.x.core.coroutine.CoroutineDispatchers
|
||||||
import io.element.android.x.matrix.core.RoomId
|
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 io.element.android.x.matrix.timeline.MatrixTimeline
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
@ -76,4 +75,11 @@ class MatrixRoom(
|
||||||
room.send(content, transactionId)
|
room.send(content, transactionId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun redactEvent(eventId: String, reason: String? = null, ) = withContext(coroutineDispatchers.io) {
|
||||||
|
val transactionId = genTransactionId()
|
||||||
|
runCatching {
|
||||||
|
room.redact(eventId, reason, transactionId)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue