diff --git a/app/src/main/java/eu/llembas/android/assist/AssistSheet.kt b/app/src/main/java/eu/llembas/android/assist/AssistSheet.kt index 1c0e74d..c351f01 100644 --- a/app/src/main/java/eu/llembas/android/assist/AssistSheet.kt +++ b/app/src/main/java/eu/llembas/android/assist/AssistSheet.kt @@ -88,6 +88,7 @@ import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import eu.llembas.android.R import eu.llembas.android.ui.ModelAvatar +import eu.llembas.android.ui.ProgressStatus import eu.llembas.android.ui.chat.Steps import eu.llembas.android.ui.progressLineOf import eu.llembas.android.ui.theme.LocalPalette @@ -471,11 +472,11 @@ private fun Turn(turn: AssistTurn, last: Boolean, state: AssistUiState, actions: } if (turn.steps.isNotEmpty()) Steps(turn.steps) val reply = turn.reply - val statusLine = progressLineOf(reply?.progress) ?: reply?.status.orEmpty() + val drawsProgress = reply != null && (progressLineOf(reply.progress) != null || reply.status.isNotBlank()) when { reply != null && reply.cards.isNotEmpty() -> TextButton(onClick = onOpenApp) { Text(stringResource(R.string.assist_answer_in_app)) } - turn.writing && statusLine.isNotBlank() -> Text(statusLine, style = MaterialTheme.typography.labelSmall, color = palette.inkFaint) + turn.writing && drawsProgress -> ProgressStatus(reply?.progress, reply?.status.orEmpty(), MaterialTheme.typography.labelSmall, palette.inkFaint) last && !turn.writing && turn.steps.isNotEmpty() -> Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) { if (state.canSpeak) { diff --git a/app/src/main/java/eu/llembas/android/ui/ProgressWords.kt b/app/src/main/java/eu/llembas/android/ui/ProgressWords.kt index 8904b8f..e98a513 100644 --- a/app/src/main/java/eu/llembas/android/ui/ProgressWords.kt +++ b/app/src/main/java/eu/llembas/android/ui/ProgressWords.kt @@ -1,18 +1,26 @@ package eu.llembas.android.ui import android.content.res.Resources +import androidx.compose.foundation.layout.Row +import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableLongStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalInspectionMode +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.style.TextOverflow import eu.llembas.android.R import eu.llembas.android.api.Progress import eu.llembas.android.api.ProgressWords +import eu.llembas.android.api.elapsed import eu.llembas.android.api.progressLine import eu.llembas.android.api.progressText import kotlinx.coroutines.delay @@ -87,3 +95,27 @@ fun progressLineOf(progress: Progress?, withElapsed: Boolean = true): String? { val now = if (LocalInspectionMode.current) progress.since + STILL_ELAPSED else rememberTick() return if (withElapsed) progressLine(progress, words, now, locale) else progressText(progress, words, now, locale) } + +/** + * What a reply is doing, one line: the progress text, then `· elapsed` (`progress.line`) kept + * whole at the end while the text gives way (two lines, then an ellipsis) -- on a phone a long + * reason must not push the clock off. [status], the free text, when there is no progress this + * app can draw. Nothing at all when neither says anything. + */ +@Composable +fun ProgressStatus(progress: Progress?, status: String, style: TextStyle, color: Color, modifier: Modifier = Modifier) { + val text = progressLineOf(progress, withElapsed = false) + if (text == null) { + if (status.isNotBlank()) Text(status, style = style, color = color, maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = modifier) + return + } + val clock = progress?.takeUnless { it.phase in Progress.NO_ELAPSED }?.let { p -> + val now = if (LocalInspectionMode.current) p.since + STILL_ELAPSED else rememberTick() + elapsed(now - p.since) + } + Row(modifier, verticalAlignment = Alignment.Top) { + Text(text, style = style, color = color, maxLines = 2, overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f, fill = false)) + // The spec's separator, `progress.line`'s " · ", before the clock. + if (clock != null) Text(" · $clock", style = style, color = color, maxLines = 1, softWrap = false) + } +} diff --git a/app/src/main/java/eu/llembas/android/ui/chat/ChatScreen.kt b/app/src/main/java/eu/llembas/android/ui/chat/ChatScreen.kt index 2ecd338..0e1468c 100644 --- a/app/src/main/java/eu/llembas/android/ui/chat/ChatScreen.kt +++ b/app/src/main/java/eu/llembas/android/ui/chat/ChatScreen.kt @@ -92,7 +92,7 @@ import eu.llembas.android.R import eu.llembas.android.api.Message import eu.llembas.android.api.ShowCard import eu.llembas.android.ui.ModelAvatar -import eu.llembas.android.ui.progressLineOf +import eu.llembas.android.ui.ProgressStatus import eu.llembas.android.ui.theme.LocalPalette import eu.llembas.android.ui.viewer.FileViewer import kotlinx.coroutines.launch @@ -288,15 +288,12 @@ fun ChatContent( } } // The 3.4.0 progress line, ticking; the free status text from an older server. - val progressLine = progressLineOf(live?.progress) - val statusLine = progressLine ?: live?.status.orEmpty() - if (live != null && statusLine.isNotBlank()) { - Text( - statusLine, + if (live != null) { + ProgressStatus( + live.progress, + live.status, style = MaterialTheme.typography.labelSmall, color = palette.inkFaint, - maxLines = 1, - overflow = TextOverflow.Ellipsis, modifier = Modifier.padding(horizontal = 8.dp, vertical = 2.dp), ) }