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