Added option to send multiples message as one (as jarvis in the chat) with reduced padding and no profile icon.

This commit is contained in:
Mathieu 2022-01-03 22:18:43 +01:00
parent 7996a94ad3
commit 8349e7739d

View File

@ -18,18 +18,29 @@ import ch.mathieubroillet.jarvis.android.ui.theme.productSansFont
@Composable @Composable
fun MessageFromJarvis(text: String) { fun MessageFromJarvis(
text: String,
anotherMessageFollows: Boolean = false,
showProfileIcon: Boolean = true
) {
//We create a row to contain the message and the robot image (to look like an sms) //We create a row to contain the message and the robot image (to look like an sms)
Row(Modifier.padding(bottom = 25.dp)) { Row(
Modifier.padding(
bottom = if (anotherMessageFollows) 5.dp else 20.dp,
start = if (!showProfileIcon) 50.dp else 0.dp
)
) {
// Adding the robot image as the sender // Adding the robot image as the sender
Image( if (showProfileIcon) {
painter = painterResource(id = R.drawable.robot256), Image(
contentDescription = "robot", painter = painterResource(id = R.drawable.robot256),
Modifier contentDescription = "robot",
.size(50.dp) Modifier
.padding(end = 10.dp) .size(50.dp)
) .padding(end = 10.dp)
)
}
// Adding the message box with the text given in the params // Adding the message box with the text given in the params
Box( Box(
@ -37,13 +48,39 @@ fun MessageFromJarvis(text: String) {
.fillMaxWidth(fraction = 0.9F) .fillMaxWidth(fraction = 0.9F)
.clip(RoundedCornerShape(15.dp)) .clip(RoundedCornerShape(15.dp))
.background(color = MaterialTheme.colors.secondaryVariant) .background(color = MaterialTheme.colors.secondaryVariant)
.padding(horizontal = 10.dp, vertical = 5.dp) .padding(horizontal = 10.dp, vertical = 10.dp)
) { ) {
Text(text = text, fontFamily = productSansFont) Text(text = text, fontFamily = productSansFont)
} }
} }
} }
@Composable
fun MessageFromJarvis(texts: List<String>) {
//Automated function to send multiples messages at the same time but only showing the profile pic in the first one and reducing the padding between them.
var i = texts.size
for (text in texts) {
when (i) {
texts.size -> MessageFromJarvis(
text = text,
anotherMessageFollows = true,
showProfileIcon = true
)
1 -> MessageFromJarvis(
text = text,
anotherMessageFollows = false,
showProfileIcon = false
)
else -> MessageFromJarvis(
text = text,
anotherMessageFollows = true,
showProfileIcon = false
)
}
i--
}
}
@Composable @Composable
fun MessageFromUser(text: String) { fun MessageFromUser(text: String) {
//We create a row to contain the user message and we align the row to the right side (to look like a conversation between two people) //We create a row to contain the user message and we align the row to the right side (to look like a conversation between two people)