Quick snackbar for unimplemented actions
This commit is contained in:
parent
68e7c019c7
commit
666571119e
3 changed files with 31 additions and 6 deletions
|
|
@ -69,9 +69,11 @@ fun MessagesScreen(
|
||||||
val roomAvatar by viewModel.collectAsState(MessagesViewState::roomAvatar)
|
val roomAvatar by viewModel.collectAsState(MessagesViewState::roomAvatar)
|
||||||
val timelineItems by viewModel.collectAsState(MessagesViewState::timelineItems)
|
val timelineItems by viewModel.collectAsState(MessagesViewState::timelineItems)
|
||||||
val hasMoreToLoad by viewModel.collectAsState(MessagesViewState::hasMoreToLoad)
|
val hasMoreToLoad by viewModel.collectAsState(MessagesViewState::hasMoreToLoad)
|
||||||
|
val snackBarContent by viewModel.collectAsState(MessagesViewState::snackbarContent)
|
||||||
val composerFullScreen by composerViewModel.collectAsState(MessageComposerViewState::isFullScreen)
|
val composerFullScreen by composerViewModel.collectAsState(MessageComposerViewState::isFullScreen)
|
||||||
val composerCanSendMessage by composerViewModel.collectAsState(MessageComposerViewState::isSendButtonVisible)
|
val composerCanSendMessage by composerViewModel.collectAsState(MessageComposerViewState::isSendButtonVisible)
|
||||||
val composerText by composerViewModel.collectAsState(MessageComposerViewState::text)
|
val composerText by composerViewModel.collectAsState(MessageComposerViewState::text)
|
||||||
|
val snackbarHostState = remember { SnackbarHostState() }
|
||||||
MessagesContent(
|
MessagesContent(
|
||||||
roomTitle = roomTitle,
|
roomTitle = roomTitle,
|
||||||
roomAvatar = roomAvatar,
|
roomAvatar = roomAvatar,
|
||||||
|
|
@ -96,7 +98,8 @@ fun MessagesScreen(
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
actionsSheetState.show()
|
actionsSheetState.show()
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
snackbarHostState = snackbarHostState,
|
||||||
)
|
)
|
||||||
val itemActionsSheetState by viewModel.collectAsState(prop1 = MessagesViewState::itemActionsSheetState)
|
val itemActionsSheetState by viewModel.collectAsState(prop1 = MessagesViewState::itemActionsSheetState)
|
||||||
TimelineItemActionsScreen(
|
TimelineItemActionsScreen(
|
||||||
|
|
@ -109,6 +112,12 @@ fun MessagesScreen(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
snackBarContent?.let {
|
||||||
|
coroutineScope.launch {
|
||||||
|
snackbarHostState.showSnackbar(it)
|
||||||
|
}
|
||||||
|
viewModel.onSnackbarShown()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
|
@ -121,15 +130,17 @@ fun MessagesContent(
|
||||||
onBackPressed: () -> Unit,
|
onBackPressed: () -> Unit,
|
||||||
onSendMessage: (String) -> Unit,
|
onSendMessage: (String) -> Unit,
|
||||||
onClick: (MessagesTimelineItemState.MessageEvent) -> Unit,
|
onClick: (MessagesTimelineItemState.MessageEvent) -> Unit,
|
||||||
onLongClick: ((MessagesTimelineItemState.MessageEvent)) -> Unit,
|
onLongClick: (MessagesTimelineItemState.MessageEvent) -> Unit,
|
||||||
composerFullScreen: Boolean,
|
composerFullScreen: Boolean,
|
||||||
onComposerFullScreenChange: () -> Unit,
|
onComposerFullScreenChange: () -> Unit,
|
||||||
onComposerTextChange: (CharSequence) -> Unit,
|
onComposerTextChange: (CharSequence) -> Unit,
|
||||||
composerCanSendMessage: Boolean,
|
composerCanSendMessage: Boolean,
|
||||||
composerText: StableCharSequence?,
|
composerText: StableCharSequence?,
|
||||||
|
snackbarHostState: SnackbarHostState,
|
||||||
) {
|
) {
|
||||||
LogCompositions(tag = "MessagesScreen", msg = "Content")
|
LogCompositions(tag = "MessagesScreen", msg = "Content")
|
||||||
val lazyListState = rememberLazyListState()
|
val lazyListState = rememberLazyListState()
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
topBar = {
|
topBar = {
|
||||||
TopAppBar(
|
TopAppBar(
|
||||||
|
|
@ -194,7 +205,8 @@ fun MessagesContent(
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
snackbarHost = { SnackbarHost(snackbarHostState) },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -77,13 +77,25 @@ class MessagesViewModel(
|
||||||
val targetEvent =
|
val targetEvent =
|
||||||
currentState.itemActionsSheetState.invoke()?.targetItem ?: return@launch
|
currentState.itemActionsSheetState.invoke()?.targetItem ?: return@launch
|
||||||
when (action) {
|
when (action) {
|
||||||
MessagesItemAction.Copy -> Unit // TODO
|
MessagesItemAction.Copy -> notImplementedYet()
|
||||||
MessagesItemAction.Forward -> Unit // TODO
|
MessagesItemAction.Forward -> notImplementedYet()
|
||||||
MessagesItemAction.Redact -> handleActionRedact(targetEvent)
|
MessagesItemAction.Redact -> handleActionRedact(targetEvent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun notImplementedYet() {
|
||||||
|
setSnackbarContent("Not implemented yet!")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onSnackbarShown() {
|
||||||
|
setSnackbarContent(null)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setSnackbarContent(message: String?) {
|
||||||
|
setState { copy(snackbarContent = message) }
|
||||||
|
}
|
||||||
|
|
||||||
private fun handleActionRedact(event: MessagesTimelineItemState.MessageEvent) {
|
private fun handleActionRedact(event: MessagesTimelineItemState.MessageEvent) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
room.redactEvent(event.id)
|
room.redactEvent(event.id)
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,8 @@ data class MessagesViewState(
|
||||||
val roomAvatar: AvatarData? = null,
|
val roomAvatar: AvatarData? = null,
|
||||||
val timelineItems: Async<List<MessagesTimelineItemState>> = Uninitialized,
|
val timelineItems: Async<List<MessagesTimelineItemState>> = Uninitialized,
|
||||||
val hasMoreToLoad: Boolean = true,
|
val hasMoreToLoad: Boolean = true,
|
||||||
val itemActionsSheetState: Async<MessagesItemActionsSheetState> = Uninitialized
|
val itemActionsSheetState: Async<MessagesItemActionsSheetState> = Uninitialized,
|
||||||
|
val snackbarContent: String? = null,
|
||||||
) : MavericksState {
|
) : MavericksState {
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue