feat(updates): lead with the installed build, one-row channel picker, clearer offer; agent images in chat (#3643)

This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-12-03 15:53:59 -05:00
1 parent 59eaa0eb06
commit 3988f52480
7 files changed
+395 -114

No files matched your search

@@ -75,7 +75,9 @@ object AgentHost {
"Never kill by a command-line pattern (pkill -f, pgrep -f piped to kill): your own command line holds the user's message, so the pattern matches you. " +
"Files the user attaches are listed at the end of their message, under /root/.cache/droiddeck/attachments. " +
"To have the user pick between options, end your reply with a fenced code block whose language is choices, one short option per line, " +
"and end your turn: DroidDeck shows them as buttons and sends the one picked as the next message."
"and end your turn: DroidDeck shows them as buttons and sends the one picked as the next message. " +
"To show the user an image (a screenshot, a mockup, a chart), put ![what it shows](/absolute/path.png) on a line of its own: " +
"DroidDeck draws the file in the chat."
val entries = mutableStateListOf<Entry>()
val queue = mutableStateListOf<Queued>()
@@ -78,7 +78,7 @@ internal fun AgentEntry(
is Entry.Said -> {
val reply = remember(entry.text) { choices(entry.text) }
Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
if (reply.text.isNotBlank()) SelectionContainer { AgentMarkdown(reply.text, Modifier.widthIn(max = 760.dp).padding(horizontal = 4.dp)) }
if (reply.text.isNotBlank()) SelectionContainer { AgentReply(reply.text, Modifier.widthIn(max = 760.dp).padding(horizontal = 4.dp)) }
if (reply.options.isNotEmpty()) AgentChoices(reply.options, answerable, onSent)
}
}
@@ -37,6 +37,106 @@ import org.commonmark.ext.gfm.tables.TableRow
import org.commonmark.node.AbstractVisitor
import org.commonmark.node.CustomNode
import org.commonmark.node.Node
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.widthIn
import androidx.compose.material3.Text
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.compose.ui.draw.clip
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage
import com.droiddeck.launcher.runtime.LinuxRuntime
import java.io.File
/** Part of an agent's reply: Markdown text, or an image the agent named on a line of its own. */
internal sealed interface ReplyPart {
data class Prose(val text: String) : ReplyPart
data class Picture(val alt: String, val path: String) : ReplyPart
}
private val PICTURE_LINE = Regex("""^\s*!\[([^\]]*)]\(\s*(?:<(?:file://)?(/[^>]*)>|(?:file://)?(/[^)<>]*?))\s*\)\s*$""")
private val FENCE = Regex("""^ {0,3}(`{3,}|~{3,})(.*)$""")
/** Splits [text] at lines that hold only an image of a local absolute path, outside code fences. */
internal fun replyParts(text: String): List<ReplyPart> {
val parts = mutableListOf<ReplyPart>()
val prose = StringBuilder()
fun flush() {
if (prose.isNotBlank()) parts += ReplyPart.Prose(prose.toString().trimEnd('\n'))
prose.clear()
}
var fence: String? = null
for (line in text.lines()) {
val marker = FENCE.matchEntire(line)
val picture = if (fence == null) PICTURE_LINE.matchEntire(line) else null
val open = fence
when {
picture != null -> {
flush()
val path = picture.groupValues[2].ifEmpty { picture.groupValues[3] }
parts += ReplyPart.Picture(picture.groupValues[1].trim(), path.trim())
continue
}
marker == null -> Unit
open == null -> fence = marker.groupValues[1]
marker.groupValues[1].let { it[0] == open[0] && it.length >= open.length } && marker.groupValues[2].isBlank() -> fence = null
}
prose.append(line).append('\n')
}
flush()
return parts
}
/**
* Where the app reads a file the agent named by its guest path: the app's own folders and shared
* storage are bound at the same paths in the guest, everything else lives in the rootfs.
*/
internal fun agentHostFile(context: Context, guestPath: String): File {
val app = context.applicationContext
val same = listOfNotNull(app.filesDir.path, app.cacheDir.path, LinuxRuntime.sharedStorage(app)?.path)
return if (same.any { guestPath == it || guestPath.startsWith("$it/") }) File(guestPath)
else File(LinuxRuntime.rootDir(app), guestPath.removePrefix("/"))
}
/** An agent's reply, with the images it names shown in place. */
@Composable
internal fun AgentReply(text: String, modifier: Modifier) {
val parts = remember(text) { replyParts(text) }
if (parts.size == 1 && parts[0] is ReplyPart.Prose) {
AgentMarkdown(text, modifier)
return
}
Column(modifier, verticalArrangement = Arrangement.spacedBy(8.dp)) {
parts.forEach { part ->
when (part) {
is ReplyPart.Prose -> AgentMarkdown(part.text, Modifier)
is ReplyPart.Picture -> AgentPicture(part)
}
}
}
}
@Composable
private fun AgentPicture(picture: ReplyPart.Picture) {
val context = LocalContext.current
val file = remember(picture.path) { agentHostFile(context, picture.path) }
var full by remember(picture.path) { mutableStateOf(false) }
if (!file.isFile) {
Text(stringResource(R.string.agent_image_missing, picture.alt.ifBlank { picture.path }), color = MaterialTheme.colorScheme.onSurfaceVariant)
return
}
AsyncImage(
model = file, contentDescription = picture.alt.ifBlank { file.name }, contentScale = ContentScale.Fit,
modifier = Modifier.widthIn(max = 560.dp).then(if (full) Modifier else Modifier.heightIn(max = 420.dp))
.clip(Shape12).clickable { full = !full },
)
}
@Composable
internal fun AgentMarkdown(text: String, modifier: Modifier) {
@@ -532,7 +532,7 @@ private fun AgentLive() {
val pal = LocalPalette.current
Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
if (AgentHost.liveThinking.isNotBlank()) AgentThought(AgentHost.liveThinking, live = true)
if (AgentHost.live.isNotBlank()) AgentMarkdown(AgentHost.live, Modifier.widthIn(max = 760.dp).padding(horizontal = 4.dp))
if (AgentHost.live.isNotBlank()) AgentReply(AgentHost.live, Modifier.widthIn(max = 760.dp).padding(horizontal = 4.dp))
val running = AgentHost.running()
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp), modifier = Modifier.padding(4.dp)) {
CircularProgressIndicator(Modifier.size(14.dp), strokeWidth = 2.dp, color = pal.primary)
@@ -9,7 +9,6 @@ import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.shrinkVertically
import androidx.compose.foundation.background
import androidx.compose.foundation.basicMarquee
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.hoverable
@@ -25,6 +24,9 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.selection.selectable
import androidx.compose.foundation.selection.selectableGroup
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
@@ -44,6 +46,7 @@ import androidx.compose.material.icons.outlined.Science
import androidx.compose.material.icons.outlined.SwapHoriz
import androidx.compose.material.icons.outlined.Sync
import androidx.compose.material.icons.outlined.Verified
import androidx.compose.material.icons.outlined.WarningAmber
import androidx.compose.material3.Icon
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.graphics.vector.ImageVector
@@ -109,50 +112,37 @@ internal fun UpdatesPage(s: FrontEndState, a: FrontEndActions, modifier: Modifie
val me = remember { AppUpdates.installed() }
val colors = MaterialTheme.colorScheme
Column(modifier = modifier) {
Row(
verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(12.dp),
modifier = Modifier.fillMaxWidth().padding(bottom = 10.dp),
) {
Text(
stringResource(R.string.upd_build, me.version, s.buildLabel), fontSize = 12.5.sp, color = colors.onSurfaceVariant,
maxLines = 1, modifier = Modifier.weight(1f)
.basicMarquee(iterations = Int.MAX_VALUE, initialDelayMillis = 700, velocity = 40.dp),
)
val checked = u.catalog?.checkedAt?.takeIf { it > 0 }
if (!LocalNarrowPane.current) Text(
if (u.checking) stringResource(R.string.common_checking) else if (checked != null) stringResource(R.string.upd_checked, ago(checked).replaceFirstChar { it.lowercase() }) else stringResource(R.string.upd_not_checked),
fontSize = 13.sp, color = colors.onSurfaceVariant,
)
val clipboard = LocalClipboardManager.current
val context = LocalContext.current
val details = buildDetails(me, s.buildLabel)
ToolIcon(Icons.Outlined.ContentCopy, stringResource(R.string.upd_copy_build)) {
clipboard.setText(AnnotatedString(details))
android.widget.Toast.makeText(context, context.getString(R.string.upd_copied), android.widget.Toast.LENGTH_SHORT).show()
}
ToolIcon(Icons.Outlined.Refresh, stringResource(R.string.store_check_updates), busy = u.checking, enabled = !u.checking && u.stage == null, onClick = ua.onCheck)
}
BoxWithConstraints(Modifier.weight(1f).fillMaxWidth()) {
val stacked = LocalNarrowPane.current || maxWidth < 600.dp
Column(modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState()).padding(bottom = 16.dp)) {
SectionLabel(stringResource(R.string.upd_installed_label))
InstalledCard(s, u, me)
CheckRow(u, ua)
SectionLabel(stringResource(R.string.upd_channel))
if (stacked) {
ChannelPicker(u, ua)
Box(Modifier.height(14.dp))
StatusPanel(s, u, ua, me)
Box(Modifier.height(18.dp))
ChannelLabel()
ChannelPicker(u, ua, s.sessionRunning)
} else {
ChannelLabel()
Row(horizontalArrangement = Arrangement.spacedBy(18.dp)) {
Box(Modifier.weight(1f)) { ChannelPicker(u, ua, s.sessionRunning) }
Box(Modifier.weight(1f)) { ChannelPicker(u, ua) }
Box(Modifier.weight(1.15f)) { StatusPanel(s, u, ua, me) }
}
}
Box(Modifier.padding(top = 18.dp)) {
ToggleRow(
host, "build-watermark", stringResource(R.string.setup_build_watermark),
stringResource(R.string.setup_build_watermark_hint), s.buildWatermark,
) { a.onBuildWatermark() }
}
SectionLabel(stringResource(R.string.upd_testers), top = 22.dp)
ToggleRow(
host, "build-watermark", stringResource(R.string.setup_build_watermark),
stringResource(R.string.setup_build_watermark_hint), s.buildWatermark,
) { a.onBuildWatermark() }
val context = LocalContext.current
val agentReady = com.droiddeck.launcher.agent.AgentHost.installed &&
(com.droiddeck.launcher.agent.AgentSetup.ready || com.droiddeck.launcher.agent.AgentSetup.completed(context))
LabBuilds(s.sessionRunning, onRebuild = if (agentReady) { info ->
com.droiddeck.launcher.agent.AgentHost.send(context, context.getString(R.string.agent_rebuild_lab, info.label))
context.startActivity(android.content.Intent(context, com.droiddeck.launcher.FrontEndActivity::class.java)
.putExtra(com.droiddeck.launcher.stores.download.StoreDownloadService.EXTRA_NAV, "agent")
.addFlags(android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP or android.content.Intent.FLAG_ACTIVITY_REORDER_TO_FRONT))
} else null)
}
}
}
@@ -169,6 +159,112 @@ internal fun UpdatesPage(s: FrontEndState, a: FrontEndActions, modifier: Modifie
)
}
private val TEST_TINT = Color(0xFF9B6CFF)
@Composable
private fun SectionLabel(text: String, top: androidx.compose.ui.unit.Dp = 4.dp) {
Text(
text, fontSize = 12.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 1.5.sp,
color = MaterialTheme.colorScheme.onSurfaceVariant, modifier = Modifier.padding(start = 2.dp, top = top, bottom = 10.dp),
)
}
/** What is installed: which kind of build, its version and versionCode, and its commit, as the first thing on the page. */
@Composable
private fun InstalledCard(s: FrontEndState, u: UpdatesState, me: AppUpdates.Installed) {
val colors = MaterialTheme.colorScheme
val pal = LocalPalette.current
val catalog = u.catalog
val lab = com.droiddeck.launcher.lab.LabOverlay.active
val basePr = if (me.pr > 0) me.pr else Regex("""\bpr(\d+)\b""").find(s.buildLabel)?.groupValues?.get(1)?.toIntOrNull() ?: 0
val kind = when {
lab != null -> stringResource(R.string.upd_kind_lab)
me.pr > 0 -> stringResource(R.string.upd_kind_test)
catalog?.stable?.let { AppUpdates.isRunning(it, me) } == true -> stringResource(R.string.upd_stable)
catalog?.preview?.let { AppUpdates.isRunning(it, me) } == true -> stringResource(R.string.upd_preview)
else -> null
}
val tint = if (lab != null || me.pr > 0) TEST_TINT else pal.signal
val title = when {
lab != null -> lab.label
me.pr > 0 -> stringResource(R.string.upd_pr, me.pr)
else -> stringResource(R.string.upd_droiddeck_version, me.version)
}
val subtitle = when {
lab != null && basePr > 0 -> stringResource(R.string.upd_lab_on_pr, basePr)
lab != null -> stringResource(R.string.upd_lab_on_version, me.version)
me.pr > 0 -> catalog?.tests?.firstOrNull { it.pr == me.pr }?.title?.takeIf { it.isNotBlank() }?.let(::changeTitle)
else -> null
}
val built = lab?.built?.takeIf { it > 0 } ?: me.committedAt
val meta = listOfNotNull(
me.version.takeIf { lab != null || me.pr > 0 },
stringResource(R.string.upd_version_code, me.versionCode),
me.commit.take(7).takeIf { it.length == 7 },
built.takeIf { it > 0 }?.let { stringResource(R.string.upd_built_ago, ago(it).replaceFirstChar { c -> c.lowercase() }) },
).joinToString(" · ")
val clipboard = LocalClipboardManager.current
val context = LocalContext.current
val details = buildDetails(me, s.buildLabel)
Row(
verticalAlignment = Alignment.Top, horizontalArrangement = Arrangement.spacedBy(12.dp),
modifier = Modifier.fillMaxWidth().clip(Shape16).background(colors.surface).border(1.dp, pal.line, Shape16).padding(start = 18.dp, end = 12.dp, top = 14.dp, bottom = 16.dp),
) {
Column(Modifier.weight(1f).padding(top = 2.dp)) {
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp)) {
if (kind != null) Text(
kind.uppercase(), fontSize = 10.5.sp, fontWeight = FontWeight.Bold, letterSpacing = 0.6.sp, color = tint, maxLines = 1,
modifier = Modifier.clip(CircleShape).background(tint.copy(alpha = 0.16f)).padding(horizontal = 8.dp, vertical = 3.dp),
)
Text(title, fontSize = 20.sp, fontWeight = FontWeight.Bold, color = colors.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis)
}
if (subtitle != null) Text(subtitle, fontSize = 14.sp, fontWeight = FontWeight.Medium, color = colors.onBackground, maxLines = 2,
overflow = TextOverflow.Ellipsis, modifier = Modifier.padding(top = 6.dp))
Text(meta, fontSize = 12.5.sp, color = colors.onSurfaceVariant, modifier = Modifier.padding(top = 4.dp))
}
ToolIcon(Icons.Outlined.ContentCopy, stringResource(R.string.upd_copy_build)) {
clipboard.setText(AnnotatedString(details))
android.widget.Toast.makeText(context, context.getString(R.string.upd_copied), android.widget.Toast.LENGTH_SHORT).show()
}
}
}
@Composable
private fun CheckRow(u: UpdatesState, ua: UpdatesActions) {
val colors = MaterialTheme.colorScheme
val pal = LocalPalette.current
val src = remember { MutableInteractionSource() }
val hot = rememberHot(src)
val enabled = !u.checking && u.stage == null
val checked = u.catalog?.checkedAt?.takeIf { it > 0 }
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth().padding(top = 6.dp, bottom = 14.dp),
) {
Row(
verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(6.dp),
modifier = Modifier.offset(x = (-6).dp).paneItem("updates:check").heightIn(min = 40.dp).clip(Shape12)
.background(if (hot) pal.signal.copy(alpha = 0.14f) else Color.Transparent)
.glideBorder(hot, Shape12, pal.signal)
.hoverable(src).clickable(interactionSource = src, indication = null, enabled = enabled, role = Role.Button, onClick = ua.onCheck)
.controllerConfirm(enabled = enabled, onClick = ua.onCheck)
.padding(horizontal = 6.dp),
) {
if (u.checking) androidx.compose.material3.CircularProgressIndicator(Modifier.size(16.dp), color = pal.signal, strokeWidth = 2.dp)
else Icon(Icons.Outlined.Refresh, contentDescription = null, tint = pal.signal.copy(alpha = if (enabled) 1f else 0.5f), modifier = Modifier.size(18.dp))
Text(
if (u.checking) stringResource(R.string.common_checking) else stringResource(R.string.upd_check_now),
fontSize = 14.sp, fontWeight = FontWeight.SemiBold, color = pal.signal.copy(alpha = if (enabled || u.checking) 1f else 0.5f),
)
}
Box(Modifier.weight(1f))
Text(
if (checked != null) stringResource(R.string.upd_checked, ago(checked).replaceFirstChar { it.lowercase() }) else stringResource(R.string.upd_not_checked),
fontSize = 12.5.sp, color = colors.onSurfaceVariant, maxLines = 1,
)
}
}
@Composable
private fun StatusPanel(s: FrontEndState, u: UpdatesState, ua: UpdatesActions, me: AppUpdates.Installed) {
val colors = MaterialTheme.colorScheme
@@ -201,12 +297,18 @@ private fun StatusPanel(s: FrontEndState, u: UpdatesState, ua: UpdatesActions, m
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(7.dp)) {
Box(Modifier.size(7.dp).clip(CircleShape).background(look.tint))
Text(look.status, fontSize = 13.sp, fontWeight = FontWeight.SemiBold, color = look.tint)
if (offered) Text(stringResource(R.string.upd_dot_ago, ago(release!!.publishedAt)), fontSize = 13.sp, color = colors.onSurfaceVariant)
}
Text(look.headline, fontSize = 22.sp, fontWeight = FontWeight.Bold, color = colors.onBackground, modifier = Modifier.padding(top = 4.dp))
if (offered) {
ReleaseNotes(changeTitle(release!!.title.ifBlank { release.tag }), release.summary, release.tag)
ReleaseFacts(release)
val size = release!!.apk?.size?.takeIf { it > 0 }?.let { megabytes(it) }
Text(
listOfNotNull(stringResource(R.string.upd_released_ago, ago(release.publishedAt)), size).joinToString(" · "),
fontSize = 12.5.sp, color = colors.onSurfaceVariant, modifier = Modifier.padding(top = 2.dp),
)
val older = (release.committedAt.takeIf { it > 0 } ?: release.publishedAt).let { it > 0 && me.committedAt > 0 && it < me.committedAt }
if (offer == Offer.SWITCH && older) OlderNote(me.committedAt)
val title = changeTitle(release.title.ifBlank { release.tag })
ReleaseNotes(title.takeUnless { it == look.headline || (release.version != null && it.endsWith(release.version)) }, release.summary, release.tag)
}
if (release != null && u.follow.channel == Channel.TEST && catalog != null) {
androidx.compose.runtime.LaunchedEffect(release.tag, release.commit, release.apk?.sha256) { ua.onSeen(release) }
@@ -228,8 +330,10 @@ private fun StatusPanel(s: FrontEndState, u: UpdatesState, ua: UpdatesActions, m
else LinearProgressIndicator(modifier = Modifier.fillMaxWidth().height(6.dp).clip(CircleShape))
}
offered && installBlock != null -> Unit
offer == Offer.UPDATE -> PrimaryButton(stringResource(R.string.upd_update_button, button), enabled = installable, main = true) { ua.onInstall(release!!) }
offer == Offer.SWITCH -> PrimaryButton(stringResource(R.string.upd_install_button, button), enabled = installable, main = true) { ua.onInstall(release!!) }
offer == Offer.UPDATE -> PrimaryButton(stringResource(R.string.upd_update_button, button), enabled = installable, main = true, fill = true,
modifier = Modifier.fillMaxWidth()) { ua.onInstall(release!!) }
offer == Offer.SWITCH -> PrimaryButton(stringResource(R.string.upd_switch_to_button, channelTitle(u.follow), button), enabled = installable, main = true,
fill = true, modifier = Modifier.fillMaxWidth()) { ua.onInstall(release!!) }
offer == Offer.AHEAD && u.follow.channel == Channel.STABLE && installBlock == null ->
SecondaryButton(stringResource(R.string.upd_install_anyway, release?.version.orEmpty()), enabled = installable) { ua.onInstall(release!!) }
offer == Offer.GONE -> PrimaryButton(stringResource(R.string.upd_follow_preview), main = true) { ua.onFollow(Follow(Channel.NIGHTLY)) }
@@ -238,25 +342,53 @@ private fun StatusPanel(s: FrontEndState, u: UpdatesState, ua: UpdatesActions, m
if (s.sessionRunning && (offered || offer == Offer.AHEAD)) {
Text(stringResource(R.string.upd_stop_session), fontSize = 12.5.sp, color = colors.onSurfaceVariant, modifier = Modifier.padding(top = 8.dp))
}
if (offered) ReleaseFacts(release!!)
if (u.follow.channel == Channel.NIGHTLY) {
PreviewHistory(catalog, me, s, u, ua)
}
}
}
/** A switch that installs a build made before the installed one; Android keeps the app's data across it. */
@Composable
private fun ReleaseNotes(title: String, notes: String, key: String) {
private fun OlderNote(installedAt: Long) {
val context = LocalContext.current
val date = android.text.format.DateUtils.formatDateTime(context, installedAt,
android.text.format.DateUtils.FORMAT_SHOW_DATE or android.text.format.DateUtils.FORMAT_ABBREV_MONTH)
Row(
verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp),
modifier = Modifier.padding(top = 12.dp).fillMaxWidth().clip(Shape12).background(AttentionAmber.copy(alpha = 0.12f))
.padding(horizontal = 12.dp, vertical = 10.dp),
) {
Icon(Icons.Outlined.WarningAmber, contentDescription = null, tint = AttentionAmber, modifier = Modifier.size(20.dp))
Column {
Text(stringResource(R.string.upd_older_than_installed, date), fontSize = 13.sp, fontWeight = FontWeight.SemiBold, color = AttentionAmber)
Text(stringResource(R.string.upd_data_stays), fontSize = 12.5.sp, color = MaterialTheme.colorScheme.onSurfaceVariant)
}
}
}
@Composable
private fun channelTitle(f: Follow) = when (f.channel) {
Channel.STABLE -> stringResource(R.string.upd_stable)
Channel.NIGHTLY -> stringResource(R.string.upd_preview)
Channel.TEST -> stringResource(R.string.upd_pr, f.pr)
}
@Composable
private fun ReleaseNotes(title: String?, notes: String, key: String) {
val colors = MaterialTheme.colorScheme
val pal = LocalPalette.current
var open by rememberSaveable(key) { mutableStateOf(false) }
var cut by remember(key) { mutableStateOf(false) }
Text(
if (title != null) Text(
title, fontSize = 15.sp, color = colors.onBackground, maxLines = if (open) Int.MAX_VALUE else 2, overflow = TextOverflow.Ellipsis,
onTextLayout = { if (it.hasVisualOverflow) cut = true }, modifier = Modifier.padding(top = 10.dp),
)
if (notes.isNotBlank()) Text(
notes, fontSize = 13.5.sp, color = colors.onSurfaceVariant, maxLines = if (open) Int.MAX_VALUE else 1, overflow = TextOverflow.Ellipsis,
onTextLayout = { if (it.hasVisualOverflow) cut = true }, modifier = Modifier.padding(top = 4.dp),
notes, fontSize = 13.5.sp, color = colors.onSurfaceVariant, maxLines = if (open) Int.MAX_VALUE else if (title == null) 3 else 1,
overflow = TextOverflow.Ellipsis, onTextLayout = { if (it.hasVisualOverflow) cut = true },
modifier = Modifier.padding(top = if (title == null) 10.dp else 4.dp),
)
if (cut || open) {
val src = remember { MutableInteractionSource() }
@@ -287,47 +419,76 @@ private fun changeTitle(t: String): String =
private fun megabytes(bytes: Long) = stringResource(R.string.upd_mb, ((bytes + 524_288) / 1_048_576).toInt())
@Composable
private fun ChannelLabel() {
Text(
stringResource(R.string.upd_channel), fontSize = 12.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 1.5.sp,
color = MaterialTheme.colorScheme.onSurfaceVariant, modifier = Modifier.padding(start = 2.dp, top = 2.dp, bottom = 10.dp),
)
}
@Composable
private fun ChannelPicker(u: UpdatesState, ua: UpdatesActions, sessionRunning: Boolean) {
private fun ChannelPicker(u: UpdatesState, ua: UpdatesActions) {
val colors = MaterialTheme.colorScheme
val pal = LocalPalette.current
val catalog = u.catalog
val tests = catalog?.tests.orEmpty()
val me = remember { AppUpdates.installed() }
val ready = tests.count { AppUpdates.installable(it, me) }
var showTests by rememberSaveable { mutableStateOf(false) }
val listing = (showTests || u.follow.channel == Channel.TEST) && tests.isNotEmpty()
val shown = if (listing || showTests) Channel.TEST else u.follow.channel
Column(verticalArrangement = Arrangement.spacedBy(10.dp)) {
ChannelCard(
Icons.Outlined.Verified, stringResource(R.string.upd_stable), stringResource(R.string.upd_stable_hint),
catalog?.stable?.let { stringResource(R.string.upd_version_ago, it.version ?: it.tag, ago(it.publishedAt)) }, u.follow.channel == Channel.STABLE,
) { ua.onFollow(Follow(Channel.STABLE)) }
ChannelCard(
Icons.Outlined.Bolt, stringResource(R.string.upd_preview), stringResource(R.string.upd_preview_hint),
catalog?.preview?.let { ago(it.publishedAt) }, u.follow.channel == Channel.NIGHTLY,
) { ua.onFollow(Follow(Channel.NIGHTLY)) }
ChannelCard(
Icons.Outlined.Science, stringResource(R.string.upd_tests), stringResource(R.string.upd_tests_hint),
if (tests.isEmpty()) stringResource(R.string.upd_tests_none) else pluralStringResource(R.plurals.upd_tests_count, ready, ready),
u.follow.channel == Channel.TEST, enabled = tests.isNotEmpty() || u.follow.channel == Channel.TEST,
) { showTests = !showTests }
AnimatedVisibility((showTests || u.follow.channel == Channel.TEST) && tests.isNotEmpty(), enter = expandVertically(Motion.sp(1f)) + fadeIn(Motion.sp(1f)), exit = shrinkVertically(Motion.sp(1f)) + fadeOut(Motion.sp(1f))) {
Row(
horizontalArrangement = Arrangement.spacedBy(4.dp),
modifier = Modifier.fillMaxWidth().clip(CircleShape).background(colors.surface).border(1.dp, pal.line, CircleShape)
.padding(4.dp).selectableGroup(),
) {
ChannelSegment(Icons.Outlined.Verified, stringResource(R.string.upd_stable), null, shown == Channel.STABLE) {
showTests = false; ua.onFollow(Follow(Channel.STABLE))
}
ChannelSegment(Icons.Outlined.Bolt, stringResource(R.string.upd_preview), null, shown == Channel.NIGHTLY) {
showTests = false; ua.onFollow(Follow(Channel.NIGHTLY))
}
ChannelSegment(
Icons.Outlined.Science, stringResource(R.string.upd_tests_short), ready.takeIf { it > 0 }?.toString(),
shown == Channel.TEST, enabled = tests.isNotEmpty() || u.follow.channel == Channel.TEST,
) { showTests = !showTests }
}
val hint = when {
listing || u.follow.channel == Channel.TEST -> stringResource(R.string.upd_tests_hint)
u.follow.channel == Channel.NIGHTLY -> stringResource(R.string.upd_preview_hint) +
(catalog?.preview?.let { " · " + stringResource(R.string.upd_latest_ago, ago(it.publishedAt)) } ?: "")
else -> stringResource(R.string.upd_stable_hint) +
(catalog?.stable?.let { " · " + stringResource(R.string.upd_version_ago, it.version ?: it.tag, ago(it.publishedAt)) } ?: "")
}
Text(hint, fontSize = 12.5.sp, color = colors.onSurfaceVariant, modifier = Modifier.padding(horizontal = 4.dp))
if (tests.isEmpty() && catalog != null && showTests) Text(stringResource(R.string.upd_tests_none), fontSize = 12.5.sp, color = colors.onSurfaceVariant)
AnimatedVisibility(listing, enter = expandVertically(Motion.sp(1f)) + fadeIn(Motion.sp(1f)), exit = shrinkVertically(Motion.sp(1f)) + fadeOut(Motion.sp(1f))) {
TestList(tests, me, u, ua)
}
val context = androidx.compose.ui.platform.LocalContext.current
val agentReady = com.droiddeck.launcher.agent.AgentHost.installed &&
(com.droiddeck.launcher.agent.AgentSetup.ready || com.droiddeck.launcher.agent.AgentSetup.completed(context))
LabBuilds(sessionRunning, onRebuild = if (agentReady) { info ->
com.droiddeck.launcher.agent.AgentHost.send(context, context.getString(R.string.agent_rebuild_lab, info.label))
context.startActivity(android.content.Intent(context, com.droiddeck.launcher.FrontEndActivity::class.java)
.putExtra(com.droiddeck.launcher.stores.download.StoreDownloadService.EXTRA_NAV, "agent")
.addFlags(android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP or android.content.Intent.FLAG_ACTIVITY_REORDER_TO_FRONT))
} else null)
}
}
@Composable
private fun RowScope.ChannelSegment(
icon: ImageVector, title: String, badge: String?, selected: Boolean,
enabled: Boolean = true, onClick: () -> Unit,
) {
val colors = MaterialTheme.colorScheme
val pal = LocalPalette.current
val src = remember { MutableInteractionSource() }
val hot = rememberHot(src)
Row(
verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(6.dp, Alignment.CenterHorizontally),
modifier = Modifier.weight(1f).heightIn(min = 44.dp).paneItem("channel:$title")
.clip(CircleShape)
.background(if (selected) pal.signal.copy(alpha = 0.16f) else if (hot) pal.signal.copy(alpha = 0.10f) else Color.Transparent)
.glideBorder(hot, CircleShape, pal.signal, if (selected) pal.signal else Color.Transparent)
.alpha(if (enabled) 1f else 0.5f)
.hoverable(src)
.selectable(selected = selected, interactionSource = src, indication = null, enabled = enabled, role = Role.RadioButton, onClick = onClick)
.controllerConfirm(enabled = enabled, onClick = onClick)
.padding(horizontal = 6.dp),
) {
Icon(icon, contentDescription = null, tint = if (selected) pal.signal else colors.onSurfaceVariant, modifier = Modifier.size(18.dp))
Text(title, fontSize = 14.sp, fontWeight = FontWeight.SemiBold, color = if (selected) colors.onBackground else colors.onSurfaceVariant,
maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f, fill = false))
if (badge != null) Text(
badge, fontSize = 11.sp, fontWeight = FontWeight.Bold, color = colors.onSurfaceVariant,
modifier = Modifier.clip(CircleShape).background(colors.surfaceVariant).padding(horizontal = 6.dp, vertical = 1.dp),
)
}
}
@@ -542,41 +703,6 @@ private fun TestList(tests: List<Release>, me: AppUpdates.Installed, u: UpdatesS
}
}
@Composable
private fun ChannelCard(
icon: ImageVector, title: String, hint: String, latest: String?, selected: Boolean,
enabled: Boolean = true, onClick: () -> Unit,
) {
val colors = MaterialTheme.colorScheme
val pal = LocalPalette.current
val src = remember { MutableInteractionSource() }
val hot = rememberHot(src)
val fill = if (hot) pal.signal.copy(alpha = 0.14f) else Color.Transparent
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(14.dp),
modifier = Modifier.fillMaxWidth().paneItem("channel:$title")
.clip(Shape14).background(colors.surface).background(fill).glideBorder(hot, Shape14, pal.signal, pal.line)
.alpha(if (enabled) 1f else 0.55f)
.hoverable(src)
.clickable(interactionSource = src, indication = null, enabled = enabled, role = Role.RadioButton, onClick = onClick)
.controllerConfirm(enabled = enabled, onClick = onClick)
.padding(horizontal = 14.dp, vertical = 10.dp),
) {
Box(contentAlignment = Alignment.Center, modifier = Modifier.size(38.dp).clip(Shape12).background(if (selected) pal.signal.copy(alpha = 0.18f) else colors.surfaceVariant)) {
Icon(icon, contentDescription = null, tint = if (selected) pal.signal else colors.onSurfaceVariant, modifier = Modifier.size(22.dp))
}
Column(modifier = Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(2.dp)) {
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) {
Text(title, fontSize = 16.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground)
if (latest != null) Text(latest, fontSize = 12.sp, fontWeight = FontWeight.Medium, color = if (selected) pal.signal else colors.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis)
}
Text(hint, fontSize = 12.5.sp, color = colors.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis)
}
RadioDot(selected)
}
}
@Composable
private fun RadioDot(selected: Boolean, size: androidx.compose.ui.unit.Dp = 22.dp) {
val pal = LocalPalette.current