From 98016791a6b65dd1ae358d3cbc891911f711baf2 Mon Sep 17 00:00:00 2001 From: Han Yin Date: Sat, 30 Aug 2025 21:44:32 -0700 Subject: [PATCH] UI: fix the breaking build --- .../bottombar/ConversationBottomBar.kt | 8 +-- .../llama/ui/screens/BenchmarkScreen.kt | 2 +- .../llama/ui/screens/ConversationScreen.kt | 54 ++++++++++++------- .../llama/ui/screens/ModelLoadingScreen.kt | 2 +- .../llama/viewmodel/ConversationViewModel.kt | 7 ++- 5 files changed, 40 insertions(+), 33 deletions(-) diff --git a/examples/llama.android/app/src/main/java/com/example/llama/ui/scaffold/bottombar/ConversationBottomBar.kt b/examples/llama.android/app/src/main/java/com/example/llama/ui/scaffold/bottombar/ConversationBottomBar.kt index 0e44f365c0..060b83037d 100644 --- a/examples/llama.android/app/src/main/java/com/example/llama/ui/scaffold/bottombar/ConversationBottomBar.kt +++ b/examples/llama.android/app/src/main/java/com/example/llama/ui/scaffold/bottombar/ConversationBottomBar.kt @@ -122,12 +122,7 @@ fun ConversationBottomBar( }, floatingActionButton = { FloatingActionButton( - onClick = { - if (isReady) { - onSendClick() - } - }, - containerColor = MaterialTheme.colorScheme.primary + onClick = { if (isReady) { onSendClick() } }, ) { if (isReady) { Icon( @@ -138,7 +133,6 @@ fun ConversationBottomBar( CircularProgressIndicator( modifier = Modifier.size(24.dp), strokeCap = StrokeCap.Round, - color = MaterialTheme.colorScheme.onPrimary, ) } } diff --git a/examples/llama.android/app/src/main/java/com/example/llama/ui/screens/BenchmarkScreen.kt b/examples/llama.android/app/src/main/java/com/example/llama/ui/screens/BenchmarkScreen.kt index b14bc92208..5457d688e3 100644 --- a/examples/llama.android/app/src/main/java/com/example/llama/ui/screens/BenchmarkScreen.kt +++ b/examples/llama.android/app/src/main/java/com/example/llama/ui/screens/BenchmarkScreen.kt @@ -84,7 +84,7 @@ fun BenchmarkScreen( val benchmarkResults by viewModel.benchmarkResults.collectAsState() // UI states - var isModelCardExpanded by remember { mutableStateOf(false) } + var isModelCardExpanded by remember { mutableStateOf(true) } var isInitialBenchmarkRun by rememberSaveable { mutableStateOf(false) } // Run benchmark when entering the screen diff --git a/examples/llama.android/app/src/main/java/com/example/llama/ui/screens/ConversationScreen.kt b/examples/llama.android/app/src/main/java/com/example/llama/ui/screens/ConversationScreen.kt index 5b85aa5ee4..3fb58cf4cb 100644 --- a/examples/llama.android/app/src/main/java/com/example/llama/ui/screens/ConversationScreen.kt +++ b/examples/llama.android/app/src/main/java/com/example/llama/ui/screens/ConversationScreen.kt @@ -32,15 +32,21 @@ import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.icons.Icons import androidx.compose.material.icons.automirrored.outlined.HelpOutline import androidx.compose.material.icons.filled.Timer +import androidx.compose.material3.AssistChip +import androidx.compose.material3.Button +import androidx.compose.material3.ButtonColors +import androidx.compose.material3.ButtonDefaults import androidx.compose.material3.Card import androidx.compose.material3.CardDefaults -import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi +import androidx.compose.material3.FilledTonalButton +import androidx.compose.material3.FilledTonalIconToggleButton +import androidx.compose.material3.FilterChip import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.Icon import androidx.compose.material3.IconButton +import androidx.compose.material3.IconButtonDefaults import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text -import androidx.compose.material3.TonalToggleButton import androidx.compose.runtime.Composable import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.LaunchedEffect @@ -72,6 +78,7 @@ import com.example.llama.ui.components.ModelCardContentContextRow import com.example.llama.ui.components.ModelCardContentField import com.example.llama.ui.components.ModelCardCoreExpandable import com.example.llama.ui.components.ModelUnloadDialogHandler +import com.example.llama.ui.theme.ButtonShape import com.example.llama.util.formatMilliSeconds import com.example.llama.util.formatMilliSecondstructured import com.example.llama.util.toEnglishName @@ -204,7 +211,10 @@ fun ConversationScreen( if (showModelCard) { selectedModel?.let { Box( - modifier = Modifier.fillMaxWidth().padding(16.dp).align(Alignment.TopCenter) + modifier = Modifier + .fillMaxWidth() + .padding(16.dp) + .align(Alignment.TopCenter) ) { ModelCardWithSystemPrompt( model = it, @@ -338,7 +348,9 @@ private fun ConversationMessageList( @Composable private fun UserMessageBubble(content: String, formattedTime: String) { Column( - modifier = Modifier.fillMaxWidth().padding(vertical = 8.dp), + modifier = Modifier + .fillMaxWidth() + .padding(vertical = 8.dp), horizontalAlignment = Alignment.End ) { // Timestamp above bubble @@ -494,7 +506,6 @@ private fun PulsatingDots(small: Boolean = false) { } } -@OptIn(ExperimentalMaterial3ExpressiveApi::class) @Composable private fun ExpandableTokenMetricsBubble( metrics: TokenMetrics, @@ -503,21 +514,24 @@ private fun ExpandableTokenMetricsBubble( var showMetrics by remember { mutableStateOf(false) } Column(Modifier.fillMaxWidth(0.9f)) { - TonalToggleButton( - checked = showMetrics, - onCheckedChange = { showMetrics = !showMetrics } - ) { - Icon( - modifier = Modifier.size(16.dp), - imageVector = Icons.Default.Timer, - contentDescription = "${if (showMetrics) "Hide" else "Show"} token metrics of this assistant message" - ) - Text( - text = "${if (showMetrics) "Hide" else "Show"} stats", - modifier = Modifier.padding(start = 8.dp), - style = MaterialTheme.typography.labelMedium, - ) - } + FilterChip( + selected = showMetrics, + onClick = { showMetrics = !showMetrics }, + label = { + Text( + text = "${if (showMetrics) "Hide" else "Show"} stats", + modifier = Modifier.padding(start = 8.dp), + style = MaterialTheme.typography.labelMedium, + ) + }, + leadingIcon = { + Icon( + modifier = Modifier.size(16.dp), + imageVector = Icons.Default.Timer, + contentDescription = "${if (showMetrics) "Hide" else "Show"} token metrics of this assistant message" + ) + }, + ) if (showMetrics) { Card( diff --git a/examples/llama.android/app/src/main/java/com/example/llama/ui/screens/ModelLoadingScreen.kt b/examples/llama.android/app/src/main/java/com/example/llama/ui/screens/ModelLoadingScreen.kt index 1ec0f9066c..ba14fdee71 100644 --- a/examples/llama.android/app/src/main/java/com/example/llama/ui/screens/ModelLoadingScreen.kt +++ b/examples/llama.android/app/src/main/java/com/example/llama/ui/screens/ModelLoadingScreen.kt @@ -518,7 +518,7 @@ private fun PromptList( Column( modifier = Modifier .fillMaxWidth() - .animateItemPlacement() + .animateItem() .selectable( selected = isSelected, onClick = { diff --git a/examples/llama.android/app/src/main/java/com/example/llama/viewmodel/ConversationViewModel.kt b/examples/llama.android/app/src/main/java/com/example/llama/viewmodel/ConversationViewModel.kt index c11eecf129..2d29b3ab94 100644 --- a/examples/llama.android/app/src/main/java/com/example/llama/viewmodel/ConversationViewModel.kt +++ b/examples/llama.android/app/src/main/java/com/example/llama/viewmodel/ConversationViewModel.kt @@ -14,7 +14,6 @@ import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.onCompletion import kotlinx.coroutines.launch -import okhttp3.internal.toImmutableList import java.text.SimpleDateFormat import java.util.Date import java.util.Locale @@ -108,7 +107,7 @@ class ConversationViewModel @Inject constructor( _messages.value.toMutableList().apply { (removeLastOrNull() as? Message.Assistant.Stopped)?.let { add(it.copy(content = it.content + SUFFIX_GENERATION_STOPPED)) - _messages.value = toImmutableList() + _messages.value = toList() } } @@ -119,7 +118,7 @@ class ConversationViewModel @Inject constructor( _messages.value.toMutableList().apply { (removeLastOrNull() as? Message.Assistant.Stopped)?.let { add(it.copy(content = it.content + SUFFIX_GENERATION_ERROR.format(e.message))) - _messages.value = toImmutableList() + _messages.value = this.toList() } } @@ -143,7 +142,7 @@ class ConversationViewModel @Inject constructor( timestamp = it.timestamp )) } - _messages.value = toImmutableList() + _messages.value = toList() } }