android image without text, remove preview

This commit is contained in:
JRoberts
2022-04-16 20:57:05 +04:00
parent c738e7a9ba
commit 932ebb739a
5 changed files with 20 additions and 9 deletions
@@ -37,17 +37,19 @@ fun TerminalView(chatModel: ChatModel, close: () -> Unit) {
@Composable
fun TerminalLayout(terminalItems: List<TerminalItem>, close: () -> Unit, sendCommand: (String) -> Unit) {
var msg = remember { mutableStateOf("") }
ProvideWindowInsets(windowInsetsAnimationsEnabled = true) {
Scaffold(
topBar = { CloseSheetBar(close) },
bottomBar = {
Box(Modifier.padding(horizontal = 8.dp)) {
SendMsgView(
msg = remember { mutableStateOf("") },
msg = msg,
linkPreview = remember { mutableStateOf(null) },
cancelledLinks = remember { mutableSetOf() },
parseMarkdown = { null },
sendMessage = sendCommand
sendMessage = sendCommand,
sendEnabled = msg.value.isNotEmpty()
)
}
},
@@ -124,6 +124,8 @@ fun ChatView(chatModel: ChatModel) {
editingItem.value = null
quotedItem.value = null
linkPreview.value = null
chosenImage.value = null
imagePreview.value = null
}
},
resetMessage = { msg.value = "" },
@@ -80,7 +80,8 @@ fun ComposeView(
}
}
)
SendMsgView(msg, linkPreview, cancelledLinks, parseMarkdown, sendMessage, editing = editingItem.value != null)
SendMsgView(msg, linkPreview, cancelledLinks, parseMarkdown, sendMessage,
editing = editingItem.value != null, sendEnabled = msg.value.isNotEmpty() || imagePreview.value != null)
}
}
}
@@ -35,7 +35,8 @@ fun SendMsgView(
cancelledLinks: MutableSet<String>,
parseMarkdown: (String) -> List<FormattedText>?,
sendMessage: (String) -> Unit,
editing: Boolean = false
editing: Boolean = false,
sendEnabled: Boolean = false
) {
val smallFont = MaterialTheme.typography.body1.copy(color = MaterialTheme.colors.onBackground)
var textStyle by remember { mutableStateOf(smallFont) }
@@ -124,7 +125,7 @@ fun SendMsgView(
) {
innerTextField()
}
val color = if (msg.value.isNotEmpty()) MaterialTheme.colors.primary else Color.Gray
val color = if (sendEnabled) MaterialTheme.colors.primary else Color.Gray
Icon(
if (editing) Icons.Filled.Check else Icons.Outlined.ArrowUpward,
generalGetString(R.string.icon_descr_send_message),
@@ -135,7 +136,7 @@ fun SendMsgView(
.clip(CircleShape)
.background(color)
.clickable {
if (msg.value.isNotEmpty()) {
if (sendEnabled) {
sendMessage(msg.value)
msg.value = ""
textStyle = smallFont
@@ -162,7 +163,8 @@ fun PreviewSendMsgView() {
linkPreview = remember {mutableStateOf<LinkPreview?>(null) },
cancelledLinks = mutableSetOf(),
parseMarkdown = { null },
sendMessage = { msg -> println(msg) }
sendMessage = { msg -> println(msg) },
sendEnabled = true
)
}
}
@@ -182,7 +184,8 @@ fun PreviewSendMsgViewEditing() {
cancelledLinks = mutableSetOf(),
sendMessage = { msg -> println(msg) },
parseMarkdown = { null },
editing = true
editing = true,
sendEnabled = true
)
}
}
+4 -1
View File
@@ -18,7 +18,7 @@ struct TerminalView: View {
@State var message: String = ""
@FocusState private var keyboardVisible: Bool
@State var editing: Bool = false
@State var sendEnabled: Bool = true
@State var sendEnabled: Bool = false
var body: some View {
VStack {
@@ -76,6 +76,9 @@ struct TerminalView: View {
}
.navigationViewStyle(.stack)
.navigationTitle("Chat console")
.onChange(of: message) { _ in
sendEnabled = !message.isEmpty
}
}
func scrollToBottom(_ proxy: ScrollViewProxy, animation: Animation = .default) {