Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add avatar #14

Merged
merged 3 commits into from
Mar 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 25 additions & 9 deletions app/src/main/kotlin/ai/elimu/soga/feature/chat/ChatScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import ai.elimu.soga.GenerativeViewModelFactory
import ai.elimu.soga.R
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.ui.draw.clip
import kotlinx.coroutines.launch
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
Comment on lines +43 to +49
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Codebase Verification

The review comment correctly emphasizes the importance of optimizing image resources for different screen densities. However, the verification process revealed that "nya.png" is not optimized for different screen densities, as it exists only in the base drawable folder. This could lead to performance issues or a suboptimal user experience on devices with varying screen densities.

Analysis chain

The addition of image handling capabilities with the Image component and related imports is a positive enhancement for avatar display. Ensure the UI remains responsive and test with various image sizes and screen densities.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that all image resources are optimized for different screen densities
fd "drawable" app/src/main/res/ | xargs -I {} find {} -type f | grep -E "nya.png$"

Length of output: 120


@Composable
internal fun ChatRoute(
Expand Down Expand Up @@ -118,14 +124,24 @@ fun ChatBubbleItem(
Column(
horizontalAlignment = horizontalAlignment,
modifier = Modifier
.padding(horizontal = 8.dp, vertical = 4.dp)
.padding(horizontal = 12.dp, vertical = 10.dp)
.fillMaxWidth()
) {
Text(
text = chatMessage.participant.name,
style = MaterialTheme.typography.bodySmall,
modifier = Modifier.padding(bottom = 4.dp)
)
// Text(
// text = chatMessage.participant.name,
// style = MaterialTheme.typography.bodySmall,
// modifier = Modifier.padding(bottom = 4.dp)
// )
if (isModelMessage) {
Image(
painter = painterResource(id = R.drawable.nya),
contentDescription = stringResource(id = R.string.nya_avatar_descritpion),
contentScale = ContentScale.Crop,
modifier = Modifier
.size(50.dp)
.clip(CircleShape)
)
}
Comment on lines +135 to +144
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The introduction of avatar display for model messages enhances the chat feature. Consider adding alternative avatars for different participants to enrich the user experience further.

Would you like me to suggest code for handling multiple avatars based on participant type?

Row {
if (chatMessage.isPending) {
CircularProgressIndicator(
Expand All @@ -138,11 +154,11 @@ fun ChatBubbleItem(
Card(
colors = CardDefaults.cardColors(containerColor = backgroundColor),
shape = bubbleShape,
modifier = Modifier.widthIn(0.dp, maxWidth * 0.9f)
modifier = Modifier.widthIn(0.dp, maxWidth * 2.9f)
) {
Text(
text = chatMessage.text,
modifier = Modifier.padding(16.dp)
modifier = Modifier.padding(20.dp)
)
}
}
Expand Down Expand Up @@ -192,7 +208,7 @@ fun MessageInput(
.fillMaxWidth()
.weight(0.15f)
) {
Icon(
Icon(
Icons.Default.Send,
contentDescription = stringResource(R.string.action_send),
modifier = Modifier
Expand Down
Binary file added app/src/main/res/drawable/nya.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@
<!-- Chat sample strings -->
<string name="chat_label">Message</string>
<string name="action_send">Send</string>

<!-- Image description -->
<string name="nya_avatar_descritpion">Nya looking at something</string>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<string name="nya_avatar_descritpion">Nya looking at something</string>
<string name="nya_avatar_description">Nya looking at something</string>

</resources>
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ dependencyResolutionManagement {
}
}

rootProject.name = "Soga"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove this line?

Suggested change
rootProject.name = "Soga"

include(":app")
Loading