Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

ensu android: use Rive animation while generating response

Prateek Sunal64e14739ce10
diff --git a/mobile/native/android/apps/ensu/app-ui/build.gradle.kts b/mobile/native/android/apps/ensu/app-ui/build.gradle.kts
index 5db66167c7..7b6cee2600 100644
--- a/mobile/native/android/apps/ensu/app-ui/build.gradle.kts
+++ b/mobile/native/android/apps/ensu/app-ui/build.gradle.kts
@@ -115,6 +115,9 @@ dependencies {
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.7.0")
implementation("androidx.navigation:navigation-compose:2.7.7")
implementation("com.google.accompanist:accompanist-navigation-animation:0.34.0")
+ implementation("app.rive:rive-android:10.2.1") {
+ exclude(group = "androidx.lifecycle", module = "lifecycle-runtime-ktx")
+ }
implementation(project(":domain"))
implementation(project(":data"))
diff --git a/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/chat/ChatMessages.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/chat/ChatMessages.kt
index 84d582ca63..2c9a87fcb3 100644
--- a/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/chat/ChatMessages.kt
+++ b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/chat/ChatMessages.kt
@@ -53,8 +53,14 @@ import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
+import androidx.compose.ui.viewinterop.AndroidView
import androidx.compose.ui.window.Popup
import androidx.compose.ui.window.PopupProperties
+import app.rive.runtime.kotlin.RiveAnimationView
+import app.rive.runtime.kotlin.core.Alignment as RiveAlignment
+import app.rive.runtime.kotlin.core.Fit
+import app.rive.runtime.kotlin.core.Loop
+import io.ente.ensu.R
import io.ente.ensu.components.BranchSwitcher
import io.ente.ensu.designsystem.EnsuColor
import io.ente.ensu.designsystem.EnsuCornerRadius
@@ -679,9 +685,14 @@ private fun StreamingMessageBubble(text: String) {
)
.padding(horizontal = EnsuSpacing.sm.dp, vertical = EnsuSpacing.md.dp)
) {
- if (text.isBlank()) {
- LoadingDotsText()
- } else {
+ GeneratingAnimation(
+ modifier = Modifier
+ .width(92.dp)
+ .height(42.dp)
+ )
+
+ if (text.isNotBlank()) {
+ Spacer(modifier = Modifier.height(EnsuSpacing.xs.dp))
MarkdownView(markdown = text, enableSelection = false, trailingCursor = showCursor)
}
}
@@ -689,62 +700,23 @@ private fun StreamingMessageBubble(text: String) {
}
@Composable
-private fun LoadingDotsText() {
- var dotCount by remember { mutableStateOf(1) }
- val phrase = remember { randomLoadingPhrase() }
-
- LaunchedEffect(Unit) {
- while (true) {
- delay(450)
- dotCount = if (dotCount == 3) 1 else dotCount + 1
+private fun GeneratingAnimation(modifier: Modifier = Modifier) {
+ AndroidView(
+ modifier = modifier,
+ factory = { context ->
+ RiveAnimationView(context).apply {
+ setRiveResource(
+ resId = R.raw.ensu,
+ autoplay = true,
+ fit = Fit.CONTAIN,
+ alignment = RiveAlignment.CENTER,
+ loop = Loop.LOOP
+ )
+ }
}
- }
-
- Text(
- text = phrase + ".".repeat(dotCount),
- style = EnsuTypography.message,
- color = EnsuColor.textMuted()
)
}
-private fun randomLoadingPhrase(): String {
- val verb = loadingPhraseVerbs.random()
- val target = loadingPhraseTargets.random()
- return "$verb $target"
-}
-
-private val loadingPhraseVerbs = listOf(
- "Generating",
- "Thinking through",
- "Assembling",
- "Drafting",
- "Composing",
- "Crunching",
- "Exploring",
- "Piecing together",
- "Reviewing",
- "Organizing",
- "Synthesizing",
- "Sketching",
- "Refining",
- "Shaping"
-)
-
-private val loadingPhraseTargets = listOf(
- "your reply",
- "an answer",
- "ideas",
- "context",
- "details",
- "the response",
- "the next steps",
- "a solution",
- "the summary",
- "insights",
- "the draft",
- "the explanation"
-)
-
@Composable
private fun TimestampText(timestampMillis: Long) {
Text(
diff --git a/mobile/native/android/apps/ensu/app-ui/src/main/res/raw/ensu.riv b/mobile/native/android/apps/ensu/app-ui/src/main/res/raw/ensu.riv
new file mode 100644
index 0000000000..35f4f64d35
Binary files /dev/null and b/mobile/native/android/apps/ensu/app-ui/src/main/res/raw/ensu.riv differ