make message sending work

pull/8/head
geeksville 2020-02-17 11:46:54 -08:00
rodzic 56bf4523cb
commit c2ab35ff9b
2 zmienionych plików z 20 dodań i 4 usunięć

Wyświetl plik

@ -1,9 +1,10 @@
# High priority
MVP features required for first public alpha
* show real ID of me when I sent texts
* keep text entry box at bottom of screen
* show user icons in chat
* show sent messages in chat
* make chat pretty and functional
* when I enter texts, send them to the device
* let user set name and shortname
* take video

Wyświetl plik

@ -7,11 +7,13 @@ import androidx.ui.core.Modifier
import androidx.ui.core.Text
import androidx.ui.core.TextField
import androidx.ui.foundation.shape.corner.RoundedCornerShape
import androidx.ui.graphics.Color
import androidx.ui.input.ImeAction
import androidx.ui.layout.Column
import androidx.ui.layout.LayoutPadding
import androidx.ui.layout.LayoutSize
import androidx.ui.layout.Row
import androidx.ui.material.Emphasis
import androidx.ui.material.MaterialTheme
import androidx.ui.material.ProvideEmphasis
import androidx.ui.material.surface.Surface
@ -39,11 +41,23 @@ object MessagesState : Logging {
// If the following (unused otherwise) line is commented out, the IDE preview window works.
// if left in the preview always renders as empty.
val messages = mutableStateOf(MessagesState.testTexts)
val messages = mutableStateOf(MessagesState.testTexts, { a, b ->
a.size == b.size // If the # of messages changes, consider it important for rerender
})
fun addMessage(m: TextMessage) {
val l = messages.value.toMutableList()
l.add(m)
messages.value = l
}
}
private val dateFormat = SimpleDateFormat("h:mm a")
val TimestampEmphasis = object : Emphasis {
override fun emphasize(color: Color) = color.copy(alpha = 0.12f)
}
/**
* A pretty version the text, with user icon to the left, name and time of arrival (copy slack look and feel)
*/
@ -63,7 +77,7 @@ fun MessageCard(msg: TextMessage, modifier: Modifier = Modifier.None) {
val user = node?.user
val senderName = user?.longName ?: msg.from
Text(text = senderName)
ProvideEmphasis(emphasis = MaterialTheme.emphasisLevels().disabled) {
ProvideEmphasis(emphasis = TimestampEmphasis) {
Text(
text = dateFormat.format(msg.date),
modifier = LayoutPadding(left = 8.dp),
@ -115,6 +129,7 @@ fun MessagesContent() {
imeAction = ImeAction.Send,
onImeActionPerformed = {
MessagesState.info("did IME action")
MessagesState.addMessage(TextMessage("fixme", message.value))
},
modifier = LayoutPadding(4.dp)
)