Add scroll list with sample dialogs

This commit is contained in:
Lonami Exo 2022-10-11 17:52:25 +02:00
parent f8fcf8b642
commit 97269ddb3f
4 changed files with 67 additions and 0 deletions

View File

@ -3,7 +3,9 @@ package dev.lonami.talaria
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.*
@ -11,6 +13,7 @@ import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.ImeAction
@ -18,6 +21,8 @@ import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import dev.lonami.talaria.data.Datasource
import dev.lonami.talaria.model.Dialog
import dev.lonami.talaria.ui.theme.TalariaTheme
class MainActivity : ComponentActivity() {
@ -101,6 +106,34 @@ fun OtpInput(otp: String, onOtpChanged: (String) -> Unit, onConfirmOtp: () -> Un
}
}
@Composable
fun DialogCard(dialog: Dialog) {
Card(
modifier = Modifier
.fillMaxWidth()
.padding(8.dp, 16.dp)
) {
Row {
Image(
painter = painterResource(R.drawable.ic_launcher_foreground),
contentDescription = stringResource(R.string.profile_photo),
)
Column(modifier = Modifier.weight(1.0f)) {
Text(dialog.title, fontWeight = FontWeight.Bold)
Text(dialog.lastMessage)
}
Switch(dialog.pinned, enabled = false, onCheckedChange = null)
}
}
}
@Composable
fun DialogList(dialogs: List<Dialog>) {
LazyColumn {
items(dialogs.size) { DialogCard(dialogs[it]) }
}
}
@Composable
fun Login() {
var stage by remember { mutableStateOf(LoginStage.ASK_PHONE) }
@ -141,3 +174,13 @@ fun LoginPreview() {
Login()
}
}
@Preview
@Composable
fun DialogPreview() {
TalariaTheme {
DialogList(
Datasource.loadAffirmations()
)
}
}

View File

@ -0,0 +1,20 @@
package dev.lonami.talaria.data
import dev.lonami.talaria.model.Dialog
object Datasource {
fun loadAffirmations(): List<Dialog> {
return listOf(
Dialog("Saved Messages", "Secret launch-code: banana", pinned = true),
Dialog("First Sample Dialog", "Photo", pinned = false),
Dialog("Second Sample Dialog", "Video", pinned = false),
Dialog("Third Sample Dialog", "Audio", pinned = false),
Dialog("Fourth Sample Dialog", "Sticker (just kidding who uses that)", pinned = false),
Dialog("Fifth Sample Dialog", "Photo", pinned = false),
Dialog("Sixth Sample Dialog", "Video", pinned = false),
Dialog("Seventh Sample Dialog", "Audio", pinned = false),
Dialog("Eighth Sample Dialog", "Sticker (just kidding who uses that)", pinned = false),
Dialog("Ninth Sample Dialog", "Hello, scroll!", pinned = false),
)
}
}

View File

@ -0,0 +1,3 @@
package dev.lonami.talaria.model
data class Dialog(val title: String, val lastMessage: String, val pinned: Boolean)

View File

@ -9,4 +9,5 @@
<string name="otp">Code</string>
<string name="otp_example">12345</string>
<string name="do_login">Login</string>
<string name="profile_photo">Profile Picture</string>
</resources>