fix token badge, hide pills on keyboard, reset tokens on nav

Three fixes:
1. Token badge only shown when usedTokens > 0 (not in old chats
   where we have no streaming data). Pushed to far right with
   Spacer weight. Reset to 0 on new chat and conversation switch.
2. Mode pills hidden when keyboard is open (WindowInsets.isImeVisible)
   — prevents the bottom dock from pushing too far up and overlapping
   chat content. Input field stays compact at the bottom.
3. ModelPill no longer constrained with weight(fill=false) which
   was causing layout issues.
This commit is contained in:
Bruno Deanoz 2026-06-22 01:01:53 +02:00
parent e87220afb5
commit f62cc4b7ac

View file

@ -13,7 +13,10 @@ import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.imePadding
import androidx.compose.foundation.layout.isImeVisible
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
@ -219,6 +222,7 @@ fun ChatScreen(
messages.clear()
conversationId = null
viewingLockedChat = false
usedTokens = 0
}
fun openConversation(summary: ConversationSummary) {
@ -269,6 +273,7 @@ fun ChatScreen(
return
}
viewingLockedChat = false
usedTokens = 0
scope.launch {
messages.clear()
val cachedList = chat.messageRepo.getCached(summary.id)
@ -655,11 +660,10 @@ fun ChatScreen(
ModelPill(
label = modelDisplayName(session.config?.model ?: "", models),
onClick = { haptics.tick(); showModelSheet = true },
modifier = Modifier.weight(1f, fill = false),
)
if (usedTokens > 0 || messages.isNotEmpty()) {
Spacer(Modifier.weight(1f))
if (usedTokens > 0) {
val ctxLen = models.find { it.id == session.config?.model }?.context_length ?: 1_000_000
Spacer(Modifier.width(8.dp))
TokenBadge(used = usedTokens, contextLength = ctxLen)
}
}
@ -704,18 +708,22 @@ fun ChatScreen(
.imePadding()
.then(if (isTablet) Modifier.widthIn(max = 720.dp) else Modifier)
) {
Spacer(Modifier.height(24.dp))
ModePillsRow(
activeMode = activeMode,
onToggle = { mode ->
activeMode = if (activeMode == mode) null else mode
haptics.tick()
},
reasoningPreset = reasoningPreset,
onReasoningChange = { reasoningPreset = it; haptics.tick() },
samplingPrefs = samplingPrefs,
onSamplingChange = { samplingPrefs = it },
)
@OptIn(ExperimentalLayoutApi::class)
val imeVisible = WindowInsets.isImeVisible
if (!imeVisible) {
Spacer(Modifier.height(24.dp))
ModePillsRow(
activeMode = activeMode,
onToggle = { mode ->
activeMode = if (activeMode == mode) null else mode
haptics.tick()
},
reasoningPreset = reasoningPreset,
onReasoningChange = { reasoningPreset = it; haptics.tick() },
samplingPrefs = samplingPrefs,
onSamplingChange = { samplingPrefs = it },
)
}
Spacer(Modifier.height(10.dp))
ChatInput(
value = input,