refactor: move message field denial out of message field
Signed-off-by: Infi <infi@infi.sh>
This commit is contained in:
parent
b1fc97714b
commit
92a21296fe
|
|
@ -61,8 +61,6 @@ fun MessageField(
|
||||||
forceSendButton: Boolean = false,
|
forceSendButton: Boolean = false,
|
||||||
disabled: Boolean = false,
|
disabled: Boolean = false,
|
||||||
editMode: Boolean = false,
|
editMode: Boolean = false,
|
||||||
denied: Boolean = false,
|
|
||||||
denyReason: String? = null,
|
|
||||||
cancelEdit: () -> Unit = {},
|
cancelEdit: () -> Unit = {},
|
||||||
onFocusChange: (Boolean) -> Unit = {},
|
onFocusChange: (Boolean) -> Unit = {},
|
||||||
) {
|
) {
|
||||||
|
|
@ -75,7 +73,7 @@ fun MessageField(
|
||||||
ChannelType.SavedMessages -> R.string.message_field_placeholder_notes
|
ChannelType.SavedMessages -> R.string.message_field_placeholder_notes
|
||||||
}
|
}
|
||||||
|
|
||||||
val sendButtonVisible = (messageContent.isNotBlank() || forceSendButton) && !disabled && !denied
|
val sendButtonVisible = (messageContent.isNotBlank() || forceSendButton) && !disabled
|
||||||
|
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
|
|
@ -86,7 +84,7 @@ fun MessageField(
|
||||||
value = messageContent,
|
value = messageContent,
|
||||||
onValueChange = onMessageContentChange,
|
onValueChange = onMessageContentChange,
|
||||||
singleLine = false,
|
singleLine = false,
|
||||||
enabled = !disabled && !denied,
|
enabled = !disabled,
|
||||||
textStyle = LocalTextStyle.current.copy(color = MaterialTheme.colorScheme.onSurface),
|
textStyle = LocalTextStyle.current.copy(color = MaterialTheme.colorScheme.onSurface),
|
||||||
cursorBrush = SolidColor(MaterialTheme.colorScheme.primary),
|
cursorBrush = SolidColor(MaterialTheme.colorScheme.primary),
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
|
|
@ -106,13 +104,6 @@ fun MessageField(
|
||||||
visualTransformation = VisualTransformation.None,
|
visualTransformation = VisualTransformation.None,
|
||||||
interactionSource = remember { MutableInteractionSource() },
|
interactionSource = remember { MutableInteractionSource() },
|
||||||
placeholder = {
|
placeholder = {
|
||||||
if (denied) {
|
|
||||||
Text(
|
|
||||||
text = denyReason
|
|
||||||
?: stringResource(R.string.message_field_denied_generic),
|
|
||||||
overflow = TextOverflow.Ellipsis,
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
Text(
|
Text(
|
||||||
text = stringResource(
|
text = stringResource(
|
||||||
id = placeholderResource,
|
id = placeholderResource,
|
||||||
|
|
@ -121,7 +112,6 @@ fun MessageField(
|
||||||
maxLines = 1,
|
maxLines = 1,
|
||||||
overflow = TextOverflow.Ellipsis,
|
overflow = TextOverflow.Ellipsis,
|
||||||
)
|
)
|
||||||
}
|
|
||||||
},
|
},
|
||||||
colors = TextFieldDefaults.colors(
|
colors = TextFieldDefaults.colors(
|
||||||
focusedIndicatorColor = Color.Transparent,
|
focusedIndicatorColor = Color.Transparent,
|
||||||
|
|
@ -137,7 +127,6 @@ fun MessageField(
|
||||||
),
|
),
|
||||||
contentPadding = PaddingValues(16.dp),
|
contentPadding = PaddingValues(16.dp),
|
||||||
leadingIcon = {
|
leadingIcon = {
|
||||||
if (!denied) {
|
|
||||||
Icon(
|
Icon(
|
||||||
when {
|
when {
|
||||||
editMode -> Icons.Default.Close
|
editMode -> Icons.Default.Close
|
||||||
|
|
@ -160,7 +149,6 @@ fun MessageField(
|
||||||
.padding(4.dp)
|
.padding(4.dp)
|
||||||
.testTag("add_attachment")
|
.testTag("add_attachment")
|
||||||
)
|
)
|
||||||
}
|
|
||||||
},
|
},
|
||||||
trailingIcon = {
|
trailingIcon = {
|
||||||
AnimatedVisibility(sendButtonVisible,
|
AnimatedVisibility(sendButtonVisible,
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import android.widget.Toast
|
||||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.compose.animation.AnimatedVisibility
|
import androidx.compose.animation.AnimatedVisibility
|
||||||
|
import androidx.compose.animation.Crossfade
|
||||||
import androidx.compose.animation.core.animateDpAsState
|
import androidx.compose.animation.core.animateDpAsState
|
||||||
import androidx.compose.animation.fadeIn
|
import androidx.compose.animation.fadeIn
|
||||||
import androidx.compose.animation.fadeOut
|
import androidx.compose.animation.fadeOut
|
||||||
|
|
@ -447,45 +448,61 @@ fun ChannelScreen(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageField(
|
Crossfade(
|
||||||
messageContent = viewModel.pendingMessageContent,
|
viewModel.denyMessageField,
|
||||||
onMessageContentChange = {
|
label = "denyMessageField switch"
|
||||||
viewModel.pendingMessageContent = it
|
) { denyMessageField ->
|
||||||
},
|
if (denyMessageField) {
|
||||||
onSendMessage = viewModel::sendPendingMessage,
|
Text(
|
||||||
onAddAttachment = {
|
text = stringResource(id = viewModel.denyMessageFieldReasonResource),
|
||||||
val isTiramisu = Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU
|
modifier = Modifier
|
||||||
|
.padding(8.dp)
|
||||||
|
.fillMaxWidth(),
|
||||||
|
style = MaterialTheme.typography.labelLarge,
|
||||||
|
textAlign = TextAlign.Center
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
MessageField(
|
||||||
|
messageContent = viewModel.pendingMessageContent,
|
||||||
|
onMessageContentChange = {
|
||||||
|
viewModel.pendingMessageContent = it
|
||||||
|
},
|
||||||
|
onSendMessage = viewModel::sendPendingMessage,
|
||||||
|
onAddAttachment = {
|
||||||
|
val isTiramisu = Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU
|
||||||
|
|
||||||
@FeatureFlag("TiramisuFilePicker")
|
@FeatureFlag("TiramisuFilePicker")
|
||||||
when {
|
when {
|
||||||
FeatureFlags.filePickerType == FilePickerFeatureFlagVariates.TiramisuMediaPermissions
|
FeatureFlags.filePickerType == FilePickerFeatureFlagVariates.TiramisuMediaPermissions
|
||||||
&& isTiramisu -> {
|
&& isTiramisu -> {
|
||||||
focusManager.clearFocus()
|
focusManager.clearFocus()
|
||||||
viewModel.inbuiltFilePickerOpen = !viewModel.inbuiltFilePickerOpen
|
viewModel.inbuiltFilePickerOpen =
|
||||||
}
|
!viewModel.inbuiltFilePickerOpen
|
||||||
|
}
|
||||||
|
|
||||||
FeatureFlags.filePickerType == FilePickerFeatureFlagVariates.DocumentsUI
|
FeatureFlags.filePickerType == FilePickerFeatureFlagVariates.DocumentsUI
|
||||||
|| !isTiramisu -> {
|
|| !isTiramisu -> {
|
||||||
pickFileLauncher.launch(arrayOf("*/*"))
|
pickFileLauncher.launch(arrayOf("*/*"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
channelType = channel.channelType,
|
channelType = channel.channelType,
|
||||||
channelName = channel.name ?: ChannelUtils.resolveDMName(channel) ?: stringResource(
|
channelName = channel.name ?: ChannelUtils.resolveDMName(channel)
|
||||||
R.string.unknown
|
?: stringResource(
|
||||||
),
|
R.string.unknown
|
||||||
forceSendButton = viewModel.pendingAttachments.isNotEmpty(),
|
),
|
||||||
disabled = viewModel.pendingAttachments.isNotEmpty() && viewModel.isSendingMessage,
|
forceSendButton = viewModel.pendingAttachments.isNotEmpty(),
|
||||||
denied = viewModel.denyMessageField,
|
disabled = viewModel.pendingAttachments.isNotEmpty() && viewModel.isSendingMessage,
|
||||||
denyReason = stringResource(id = viewModel.denyMessageFieldReasonResource),
|
editMode = viewModel.editingMessage != null,
|
||||||
editMode = viewModel.editingMessage != null,
|
cancelEdit = viewModel::cancelEditingMessage,
|
||||||
cancelEdit = viewModel::cancelEditingMessage,
|
onFocusChange = { nowFocused ->
|
||||||
onFocusChange = { nowFocused ->
|
if (nowFocused && viewModel.inbuiltFilePickerOpen) {
|
||||||
if (nowFocused && viewModel.inbuiltFilePickerOpen) {
|
viewModel.inbuiltFilePickerOpen = false
|
||||||
viewModel.inbuiltFilePickerOpen = false
|
}
|
||||||
}
|
},
|
||||||
},
|
)
|
||||||
)
|
}
|
||||||
|
}
|
||||||
|
|
||||||
AnimatedVisibility(visible = viewModel.inbuiltFilePickerOpen) {
|
AnimatedVisibility(visible = viewModel.inbuiltFilePickerOpen) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue