From 8349e7739de2c57cf88feca00252164a2e87a9e0 Mon Sep 17 00:00:00 2001 From: Mathieu Date: Mon, 3 Jan 2022 22:18:43 +0100 Subject: [PATCH] Added option to send multiples message as one (as jarvis in the chat) with reduced padding and no profile icon. --- .../jarvis/android/utils/Messages.kt | 57 +++++++++++++++---- 1 file changed, 47 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/ch/mathieubroillet/jarvis/android/utils/Messages.kt b/app/src/main/java/ch/mathieubroillet/jarvis/android/utils/Messages.kt index 036bddf..c7e9b50 100644 --- a/app/src/main/java/ch/mathieubroillet/jarvis/android/utils/Messages.kt +++ b/app/src/main/java/ch/mathieubroillet/jarvis/android/utils/Messages.kt @@ -18,18 +18,29 @@ import ch.mathieubroillet.jarvis.android.ui.theme.productSansFont @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) - 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 - Image( - painter = painterResource(id = R.drawable.robot256), - contentDescription = "robot", - Modifier - .size(50.dp) - .padding(end = 10.dp) - ) + if (showProfileIcon) { + Image( + painter = painterResource(id = R.drawable.robot256), + contentDescription = "robot", + Modifier + .size(50.dp) + .padding(end = 10.dp) + ) + } // Adding the message box with the text given in the params Box( @@ -37,13 +48,39 @@ fun MessageFromJarvis(text: String) { .fillMaxWidth(fraction = 0.9F) .clip(RoundedCornerShape(15.dp)) .background(color = MaterialTheme.colors.secondaryVariant) - .padding(horizontal = 10.dp, vertical = 5.dp) + .padding(horizontal = 10.dp, vertical = 10.dp) ) { Text(text = text, fontFamily = productSansFont) } } } +@Composable +fun MessageFromJarvis(texts: List) { + //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 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)