|
@@ -6,7 +6,6 @@ import androidx.compose.foundation.layout.Row
|
|
|
import androidx.compose.foundation.layout.fillMaxWidth
|
|
|
import androidx.compose.foundation.layout.height
|
|
|
import androidx.compose.foundation.layout.padding
|
|
|
-import androidx.compose.foundation.shape.CircleShape
|
|
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
|
import androidx.compose.foundation.text.KeyboardOptions
|
|
|
import androidx.compose.material.icons.Icons
|
|
@@ -64,37 +63,6 @@ fun InputChat(
|
|
|
var openAlertDialog by remember { mutableStateOf(false) }
|
|
|
val attachmentState = remember { mutableStateListOf<Uri>() }
|
|
|
attachmentState.addAll(attachments)
|
|
|
- val leadingIcon: (@Composable () -> Unit)? = if (enableAttachment) {
|
|
|
- {
|
|
|
- Attachments(
|
|
|
- modifier = Modifier
|
|
|
- .height(300.dp)
|
|
|
- .fillMaxWidth()
|
|
|
- .padding(start = 16.dp, end = 16.dp, bottom = 8.dp)
|
|
|
- .graphicsLayer {
|
|
|
- shape = RoundedCornerShape(16.dp)
|
|
|
- clip = true
|
|
|
- }
|
|
|
- .background(MaterialTheme.colorScheme.surfaceContainerLowest),
|
|
|
- onAttachment = { list ->
|
|
|
- attachmentState.addAll(list)
|
|
|
- val items = list.map {
|
|
|
- context.toAttachmentItem(it)
|
|
|
- }
|
|
|
- if (items.size == 1) {
|
|
|
- val params = AttachmentItemList(items)
|
|
|
- val data = Uri.encode(Json.encodeToString(params))
|
|
|
- navController.navigate(Screen.AttachmentCaption.route + "?data=${data}&pin=${pin}") {
|
|
|
- launchSingleTop = true
|
|
|
- restoreState = true
|
|
|
- }
|
|
|
- } else if (items.size > 1) {
|
|
|
- openAlertDialog = true
|
|
|
- }
|
|
|
- }
|
|
|
- )
|
|
|
- }
|
|
|
- } else null
|
|
|
TextField(
|
|
|
modifier = Modifier
|
|
|
.fillMaxWidth()
|
|
@@ -109,7 +77,22 @@ fun InputChat(
|
|
|
placeholder = {
|
|
|
Text(text = placeHolderText, color = MaterialTheme.colorScheme.onSurface)
|
|
|
},
|
|
|
- leadingIcon = leadingIcon,
|
|
|
+ leadingIcon = addAttachment(enableAttachment = enableAttachment) { list ->
|
|
|
+ attachmentState.addAll(list)
|
|
|
+ val items = list.map {
|
|
|
+ context.toAttachmentItem(it)
|
|
|
+ }
|
|
|
+ if (items.size == 1) {
|
|
|
+ val params = AttachmentItemList(items)
|
|
|
+ val data = Uri.encode(Json.encodeToString(params))
|
|
|
+ navController.navigate(Screen.AttachmentCaption.route + "?data=${data}&pin=${pin}") {
|
|
|
+ launchSingleTop = true
|
|
|
+ restoreState = true
|
|
|
+ }
|
|
|
+ } else if (items.size > 1) {
|
|
|
+ openAlertDialog = true
|
|
|
+ }
|
|
|
+ },
|
|
|
trailingIcon = {
|
|
|
Row {
|
|
|
IconButton(onClick = {
|
|
@@ -215,4 +198,27 @@ fun InputChat(
|
|
|
)
|
|
|
}
|
|
|
}
|
|
|
+}
|
|
|
+
|
|
|
+private fun addAttachment(
|
|
|
+ enableAttachment: Boolean = true,
|
|
|
+ onAttachment: (List<Uri>) -> Unit
|
|
|
+): (@Composable () -> Unit)? {
|
|
|
+ val leadingIcon: (@Composable () -> Unit)? = if (enableAttachment) {
|
|
|
+ {
|
|
|
+ Attachments(
|
|
|
+ modifier = Modifier
|
|
|
+ .height(300.dp)
|
|
|
+ .fillMaxWidth()
|
|
|
+ .padding(start = 16.dp, end = 16.dp, bottom = 8.dp)
|
|
|
+ .graphicsLayer {
|
|
|
+ shape = RoundedCornerShape(16.dp)
|
|
|
+ clip = true
|
|
|
+ }
|
|
|
+ .background(MaterialTheme.colorScheme.surfaceContainerLowest),
|
|
|
+ onAttachment = onAttachment
|
|
|
+ )
|
|
|
+ }
|
|
|
+ } else null
|
|
|
+ return leadingIcon
|
|
|
}
|