forked from Lonami/Talaria
Add scroll list with sample messages
This commit is contained in:
parent
97269ddb3f
commit
ec3ca82d59
|
@ -21,8 +21,10 @@ import androidx.compose.ui.text.input.KeyboardType
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import dev.lonami.talaria.data.Datasource
|
import dev.lonami.talaria.data.DialogSource
|
||||||
|
import dev.lonami.talaria.data.MessageSource
|
||||||
import dev.lonami.talaria.model.Dialog
|
import dev.lonami.talaria.model.Dialog
|
||||||
|
import dev.lonami.talaria.model.Message
|
||||||
import dev.lonami.talaria.ui.theme.TalariaTheme
|
import dev.lonami.talaria.ui.theme.TalariaTheme
|
||||||
|
|
||||||
class MainActivity : ComponentActivity() {
|
class MainActivity : ComponentActivity() {
|
||||||
|
@ -134,6 +136,30 @@ fun DialogList(dialogs: List<Dialog>) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun MessageCard(message: Message) {
|
||||||
|
Card(
|
||||||
|
elevation = 4.dp,
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(8.dp)
|
||||||
|
) {
|
||||||
|
Column(modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(8.dp)) {
|
||||||
|
Text(message.sender, fontWeight = FontWeight.Bold)
|
||||||
|
Text(message.text)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun MessageList(messages: List<Message>) {
|
||||||
|
LazyColumn {
|
||||||
|
items(messages.size) { MessageCard(messages[it]) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun Login() {
|
fun Login() {
|
||||||
var stage by remember { mutableStateOf(LoginStage.ASK_PHONE) }
|
var stage by remember { mutableStateOf(LoginStage.ASK_PHONE) }
|
||||||
|
@ -180,7 +206,17 @@ fun LoginPreview() {
|
||||||
fun DialogPreview() {
|
fun DialogPreview() {
|
||||||
TalariaTheme {
|
TalariaTheme {
|
||||||
DialogList(
|
DialogList(
|
||||||
Datasource.loadAffirmations()
|
DialogSource.loadDialogs()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Preview
|
||||||
|
@Composable
|
||||||
|
fun ChatPreview() {
|
||||||
|
TalariaTheme {
|
||||||
|
MessageList(
|
||||||
|
MessageSource.loadMessages()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,8 @@ package dev.lonami.talaria.data
|
||||||
|
|
||||||
import dev.lonami.talaria.model.Dialog
|
import dev.lonami.talaria.model.Dialog
|
||||||
|
|
||||||
object Datasource {
|
object DialogSource {
|
||||||
fun loadAffirmations(): List<Dialog> {
|
fun loadDialogs(): List<Dialog> {
|
||||||
return listOf(
|
return listOf(
|
||||||
Dialog("Saved Messages", "Secret launch-code: banana", pinned = true),
|
Dialog("Saved Messages", "Secret launch-code: banana", pinned = true),
|
||||||
Dialog("First Sample Dialog", "Photo", pinned = false),
|
Dialog("First Sample Dialog", "Photo", pinned = false),
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
package dev.lonami.talaria.data
|
||||||
|
|
||||||
|
import dev.lonami.talaria.model.Message
|
||||||
|
|
||||||
|
object MessageSource {
|
||||||
|
fun loadMessages(): List<Message> {
|
||||||
|
return generateSequence {
|
||||||
|
Message("Alice", "Testing")
|
||||||
|
}.take(50).toList()
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
package dev.lonami.talaria.model
|
||||||
|
|
||||||
|
data class Message(val sender: String, val text: String)
|
Loading…
Reference in New Issue