Andee lives on your phone or Mac and uses any app like you do—no integrations, no root, any model; memory and passwords never leave your device | Andee 住进你的手机或 Mac,像你一样操作任何 App——无需集成、无需 Root、支持任意模型,记忆和密码绝不离开设备。
feat(scenes): offer ready-made scenes on a card with no history
booboosuic5785e33244d
diff --git a/CLAUDE.md b/CLAUDE.mdindex ac89e82..934fb6a 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -531,6 +531,8 @@ Where the pieces live, and why there:- **Triage reads the active scene** (`NotificationTriage.decide(…, scene)`), appended to the *system* message and never to the payload: it is the owner's instruction, the notification is a stranger's. That is how a scene saying "reply to my WeChat for me" turns a chat message into `act` — the autonomy is whatever the scene's rules say, by design.- **One listener for every route in or out** — the tool, the 情景 card, the chip's ✕, an app trigger all end in `VoiceConfig.onSceneChanged`, which `ScreenBodyService.onSceneChanged` turns into a scrollback row and the chip. Nothing about entering speaks.+**A card with no history offers scenes instead of sitting empty.** `HistoryListView.refresh` swaps the dead "还没有对话" line for one hint plus a bubble per preset, labelled with the scene's **name** and carrying its **example** — both fields of one `ScenePresets.Text`, so a bubble cannot promise one thing and send another. The hint names speaking and picking in that order (`告诉我,或者选一个`), because what sits underneath is an offer and the ball overhead is the other way in — the same two the `window_tips` line at the foot of the card lists. Copy that reads "选一个" on its own presents the bubbles as the only door, which is a lie the UI can avoid telling. This is the one place the device is proactive, and emptiness is the entire safety story: a conversation starts, the strip is `GONE` for good. Tapping sends `进入「X」情景。<example>` through `submitUserTurn`, and **stops there** — it states the intent, the model decides. Entering the scene is not done from the tap: a scene is rules the model adopts and is offered rather than imposed at every other door into it, and the model reading its own name in a sentence judges that better than a tap does. Nothing folds the card either; the first screen tool goes through `ensureCompact`.+Two guards, both mechanical rather than prompt:- **An `untrusted` (NOTIFY) turn cannot `scene.save`, `scene.enter` or `scene.delete`** (`CommandDispatcher.dispatch`, beside the vault guard). A scene can carry "act for me without asking", so a stranger's message that talked the model into creating or entering one would have bought itself standing permission. `scene.exit` stays allowed — leaving only ever narrows. Silent turns already allow only `note.*`.diff --git a/app/src/main/java/net/kuafuai/andee/ScreenBodyService.kt b/app/src/main/java/net/kuafuai/andee/ScreenBodyService.ktindex 506eacd..37c0ac7 100644--- a/app/src/main/java/net/kuafuai/andee/ScreenBodyService.kt+++ b/app/src/main/java/net/kuafuai/andee/ScreenBodyService.kt@@ -275,6 +275,55 @@ class ScreenBodyService : AccessibilityService() {)openPageFrom(entry, file)}++ /**+ * A suggestion bubble on an empty card — the one turn the device+ * starts on the user's behalf.+ *+ * The user tapped a scene's *name* and gets its *example*: both are+ * fields of one preset, so what the bubble promised and what is sent+ * cannot drift. See [net.kuafuai.andee.config.ScenePresets.Text].+ *+ * **The scene is written down before the sentence is sent.** The+ * turn below names the scene, and the model reads that name against+ * the notebook — [net.kuafuai.andee.config.Notebook.scenesForPrompt]+ * lists what the notebook holds. A bubble that only spoke asked the+ * model about a scene nobody had saved, and it answered, correctly+ * and in front of the user, that it had never seen one. Tapping the+ * bubble *is* the yes that adoption waits for (see+ * [net.kuafuai.andee.config.ScenePresets]), so the write happens here+ * rather than being asked for again in the turn below.+ *+ * [net.kuafuai.andee.config.ScenePresets.adoptIfMissing], not+ * `adopt`: the same bubble can be met in a later session, after the+ * scene has been edited by the user or the model, and `saveScene`+ * replaces the whole row — re-adopting would put the preset's text+ * back over their version.+ *+ * Making the scene *active* is still deliberately **not** done here:+ * a scene is a set of rules the model adopts, it is offered rather+ * than imposed everywhere else (see `scene.*`), and the model reading+ * its own name in a sentence is a better judge of whether this is+ * that scene than a tap is. The device states the intent; the brain+ * decides.+ *+ * Nothing here folds the card either. The first screen tool the+ * brain calls goes through `CommandDispatcher.ensureCompact()`, which+ * folds and waits for the fold — a second one fired from here would+ * be racing it.+ */+ override fun onSuggestionClick(name: String, title: String, example: String) {+ net.kuafuai.andee.config.ScenePresets.adoptIfMissing(+ this@ScreenBodyService,+ name,+ net.kuafuai.andee.config.VoiceConfig.uiLanguage(this@ScreenBodyService) ==+ net.kuafuai.andee.config.VoiceConfig.LANG_EN,+ )+ submitUserTurn(+ AppLocale.str(this@ScreenBodyService, R.string.suggestion_turn, title, example),+ "suggested",+ )+ }})// Before the card is built: FloatingWindowUi.build() reads the log to// lay out its first rows, and registers itself as the listener.diff --git a/app/src/main/java/net/kuafuai/andee/config/ScenePresets.kt b/app/src/main/java/net/kuafuai/andee/config/ScenePresets.ktindex 5a3e51f..e043149 100644--- a/app/src/main/java/net/kuafuai/andee/config/ScenePresets.kt+++ b/app/src/main/java/net/kuafuai/andee/config/ScenePresets.kt@@ -3,14 +3,27 @@ package net.kuafuai.andee.configimport android.content.Context/**- * Ready-made scenes the user can adopt from the 情景 card.+ * Ready-made scenes the user can adopt — from the 情景 card, or from a bubble+ * on a card with no history.*- * **A preset is not a scene until the user taps 采用.** Scenes are learned with- * the person (`LocalPrompt` §11), and nothing here changes that: the card only- * offers, and [adopt] is what writes to the notebook, so the "say yes first"- * rule holds with the tap standing in for the sentence. From then on it is an+ * **A preset is not a scene until the user says yes.** Scenes are learned with+ * the person (`LocalPrompt` §11), and nothing here changes that: both doors only+ * offer, and [adopt] is what writes to the notebook, so the "say yes first"+ * rule holds with a tap standing in for the sentence. From then on it is an* ordinary scene that the user and the model can edit or delete like any other.*+ * The two taps are the same yes. 采用 on the 情景 card says it out loud; a+ * bubble on an empty card *is* the user choosing the scene, so picking it is the+ * answer itself. The bubble goes through [adoptIfMissing] rather than [adopt]+ * only because it can be tapped again in a later session, by which time the+ * scene may have been edited.+ *+ * Neither door *enters* the scene. Writing it down is what makes it findable;+ * whether to step into it stays the model's call, made from the 「进入…情景」 it+ * reads. A bubble that skipped the writing step sent the model looking for a+ * scene nobody had saved, and it answered — correctly, and in front of the+ * user — that it had never seen one.+ ** Plain Kotlin rather than string resources, on purpose. The stored form of a* scene is data in whatever language it was written in, so the language is* picked once, at adoption, from the interface setting. And with no Android@@ -24,12 +37,33 @@ import android.content.Context*/object ScenePresets {- class Text(val title: String, val summary: String, val prompt: String)+ class Text(+ val title: String,+ val summary: String,+ val prompt: String,+ /**+ * One sentence the user could have said, and the only part of a preset+ * that is ever *done* rather than read.+ *+ * It lives here rather than in a table of its own because it is a claim+ * about the scene: the moment the prompt and the example could drift+ * apart, one of them is lying, and nothing would catch it. Same source+ * means editing a scene edits what it offers.+ *+ * The card shows [title] on the bubble and sends this; see+ * [net.kuafuai.andee.ui.HistoryListView] and+ * `ScreenBodyService.onSuggestionClick`.+ */+ val example: String,+ )class Preset(val name: String, private val zh: Text, private val en: Text) {fun text(english: Boolean): Text = if (english) en else zh}+ /** The preset called [name], or null when the table has no such row. */+ fun byName(name: String): Preset? = all.firstOrNull { it.name == name }+/** The presets this notebook does not hold yet, in the order they are offered. */fun notAdopted(context: Context): List<Preset> =all.filter { Notebook.scene(context, it.name) == null }@@ -47,11 +81,32 @@ object ScenePresets {)}+ /**+ * Adopt [name] only if the notebook does not hold it yet. Returns whether it+ * wrote.+ *+ * This is the door the empty card's bubbles use, and the guard is the whole+ * reason it is not plain [adopt]. A bubble is offered for *every* preset,+ * adopted or not (see [net.kuafuai.andee.ui.HistoryListView]), and a user can+ * meet the same bubble in a later session — after the scene has been edited+ * by them or by the model. `saveScene` replaces the whole row including+ * `prompt`, so running [adopt] a second time would put the preset's text+ * back over their version and nothing would say it had happened. Skipping a+ * name that already exists is what makes tapping a bubble safe to do twice.+ */+ fun adoptIfMissing(context: Context, name: String, english: Boolean): Boolean {+ val preset = byName(name) ?: return false+ if (Notebook.scene(context, name) != null) return false+ adopt(context, preset, english)+ return true+ }+private val CHAT_DUTY = Preset(name = "chat_duty",zh = Text(title = "消息值班台",summary = "盯着所有聊天应用的通知,要紧的立刻告诉你,其余保持安静。",+ example = "帮我盯着通知,要紧的马上告诉我,其余的先别烦我",prompt = """当我处于这个场景中时,我就是这个人在设备上所有聊天应用的值班台——不管是哪一个应用,WhatsApp、Telegram、Slack、Signal、Messenger、Instagram、微信,还是别的什么。这个场景之所以存在,正是因为他们的消息分散在好几个应用里,而这些应用彼此并不互通。@@ -81,7 +136,8 @@ object ScenePresets {),en = Text(title = "Message desk",- summary = "Watches the notifications of every chat app, tells you the important ones at once, stays quiet about the rest.",+ summary = "Tells you the important notifications at once, and leaves the rest alone.",+ example = "Watch my notifications and tell me the important ones right away, leave the rest alone",prompt = """While I am in this scene, I am this person's duty desk for every chat app on the device — WhatsApp, Telegram, Slack, Signal, Messenger, Instagram, WeChat, whatever it is. The scene exists because their messages are scattered across several apps that do not talk to each other.@@ -116,6 +172,7 @@ object ScenePresets {zh = Text(title = "订阅清理",summary = "查出你每月在为哪些订阅付费,问你要不要退,退之前不会动手。",+ example = "帮我查一下我每个月都在为哪些订阅付钱",prompt = """当我处于这个场景中时,我的任务是帮这个人看清他在为哪些订阅付费,并且只在他点头之后才帮他退订。@@ -134,7 +191,8 @@ object ScenePresets {),en = Text(title = "Subscription cleanup",- summary = "Finds what you pay for every month and asks which to cancel. Nothing is cancelled without your yes.",+ summary = "Finds what you pay for monthly, and cancels only what you approve.",+ example = "Find out which subscriptions I am paying for every month",prompt = """While I am in this scene, my job is to help this person see which subscriptions they pay for, and to cancel one only after they say yes.@@ -158,6 +216,7 @@ object ScenePresets {zh = Text(title = "开会记录",summary = "开会时录音,结束后整理成纪要页,并把待办挑出来问你要不要记下。",+ example = "等下的会帮我录下来,结束后给我一份纪要",prompt = """当我处于这个场景中时,我的任务是替这个人开会:录下来,会后给他一份能直接用的纪要。@@ -182,7 +241,8 @@ object ScenePresets {),en = Text(title = "Meeting notes",- summary = "Records the meeting, turns it into a minutes page afterwards, and offers to set reminders for your action items.",+ summary = "Records the meeting, writes the minutes, offers to set your reminders.",+ example = "Record the meeting for me and give me the minutes afterwards",prompt = """While I am in this scene, my job is to sit through the meeting for this person: record it, and give them minutes they can use straight away.@@ -212,6 +272,7 @@ object ScenePresets {zh = Text(title = "到点替我上",summary = "抢票、挂号、报名:到点替你进去办,付款和最后确认永远留给你。",+ example = "帮我盯着放号,到点替我抢,最后一步留给我确认",prompt = """当我处于这个场景中时,我的任务是在约定的时间,替这个人去抢一个名额:车票、门诊号、报名。我替他冲到最后一步之前,最后一步永远是他的。@@ -237,7 +298,8 @@ object ScenePresets {),en = Text(title = "Book it for me at the time",- summary = "Tickets, appointments, sign-ups: goes in at the set time and does the legwork. Payment and the final confirmation stay with you.",+ summary = "Goes in when the slot opens and does the legwork. Payment stays with you.",+ example = "Watch for the slot to open and grab it for me, leaving the last step to me",prompt = """While I am in this scene, my job is to go and grab a slot for this person at an agreed time: a ticket, a clinic appointment, a registration. I run up to the last step for them, and the last step is always theirs.diff --git a/app/src/main/java/net/kuafuai/andee/ui/FloatingWindowUi.kt b/app/src/main/java/net/kuafuai/andee/ui/FloatingWindowUi.ktindex 36341e9..137ee39 100644--- a/app/src/main/java/net/kuafuai/andee/ui/FloatingWindowUi.kt+++ b/app/src/main/java/net/kuafuai/andee/ui/FloatingWindowUi.kt@@ -218,6 +218,26 @@ class FloatingWindowUi(* sequencing belongs to whoever owns the dispatcher.*/fun onTextOpen(entry: ChatHistory.Entry)++ /**+ * A suggestion bubble on a card with no history — the user taking the+ * assistant up on one of the things it says it can do.+ *+ * Handed out rather than sent from here: sending is a turn, and a turn+ * has exactly one way in (`ScreenBodyService.submitUserTurn`), which is+ * where the log row, the hub event and the glow all hang off. A list+ * that sent its own would be a second way in, and the hub event is the+ * half that gets forgotten.+ *+ * [name] is the scene's stored key, which is what the service adopts+ * the scene under — a bubble has to leave the scene in the notebook, or+ * the model it names is asked about something that does not exist.+ * [title] is what the user read on the bubble; [example] is the+ * sentence that is actually sent. All three come from one preset — see+ * [net.kuafuai.andee.config.ScenePresets.Text] — so a bubble cannot+ * name one thing and send another.+ */+ fun onSuggestionClick(name: String, title: String, example: String)}private val wm: WindowManager =@@ -2186,6 +2206,9 @@ class FloatingWindowUi(val history = HistoryListView(context).apply {onPageClick = { listeners.onHistoryPageClick(it) }onTextOpen = { listeners.onTextOpen(it) }+ onSuggestionClick = { name, title, example ->+ listeners.onSuggestionClick(name, title, example)+ }}historyView = historyroot.addView(diff --git a/app/src/main/java/net/kuafuai/andee/ui/HistoryListView.kt b/app/src/main/java/net/kuafuai/andee/ui/HistoryListView.ktindex 42e99fc..87e627f 100644--- a/app/src/main/java/net/kuafuai/andee/ui/HistoryListView.kt+++ b/app/src/main/java/net/kuafuai/andee/ui/HistoryListView.kt@@ -15,6 +15,8 @@ import android.widget.LinearLayoutimport android.widget.ScrollViewimport android.widget.TextViewimport net.kuafuai.andee.R+import net.kuafuai.andee.config.ScenePresets+import net.kuafuai.andee.config.VoiceConfigimport net.kuafuai.andee.i18n.AppLocaleimport java.text.SimpleDateFormatimport java.util.Date@@ -63,6 +65,24 @@ class HistoryListView(private val context: Context) : ScrollView(context) {*/var onTextOpen: ((ChatHistory.Entry) -> Unit)? = null+ /**+ * A suggestion bubble was tapped — one of the ready-made scenes, offered by+ * name, that sends its own example when taken up.+ *+ * This is the **only** control in the scrollback that starts something. It+ * is handed out rather than acted on here for the same reason the rows are:+ * starting a turn is the service's business (it writes the log, tells the+ * hub, lights the glow), and a list that could do it would be a second way+ * to start a turn. See `ScreenBodyService.onSuggestionClick`.+ *+ * Three things are passed because they are used in different places: the+ * name is the key the scene is stored under and what adoption needs, the+ * title is what the user read and what the turn names, the example is what+ * actually gets sent. All three come from one preset — see+ * [ScenePresets.Text] — so a bubble cannot name one thing and send another.+ */+ var onSuggestionClick: ((name: String, title: String, example: String) -> Unit)? = null+/*** The rows themselves.*@@ -105,6 +125,15 @@ class HistoryListView(private val context: Context) : ScrollView(context) {/** Laid rows drawn as re-openable pages; one losing its file forces a relayout. */private val laidOpen = HashSet<Long>()+ /**+ * Shown only when there is nothing to suggest either — a conversation that+ * has not started and a build with no presets. The ordinary empty state is+ * [suggest], which invites the user in and then offers something to do.+ *+ * This line only states the absence. It used to open with the same words as+ * [suggest], so the two read as one script with half of it missing; now that+ * the ordinary hint speaks for itself, all this one has to be is true.+ */private val empty = TextView(context).apply {text = lctx.getString(R.string.history_empty)textSize = Glass.Type.CAPTION@@ -113,6 +142,35 @@ class HistoryListView(private val context: Context) : ScrollView(context) {setPadding(0, dp(28), 0, 0)}+ /**+ * The offers, for a conversation that has not started.+ *+ * **The one moment this app can be proactive without being early.** With no+ * history there is nothing to be helpful *about*, and a ball in the corner+ * has taught the user nothing about what it does — so instead of the dead+ * "还没有对话" line, the card names a few things it is good at and sends one+ * when tapped.+ *+ * Only when the log is empty, and that is the whole safety story: the+ * moment there is a conversation, this is `GONE` and stays that way. A+ * suggestion strip parked over a live chat would be the app talking about+ * itself instead of answering.+ *+ * Built once and reused — see [buildSuggestions] — because [refresh] runs on+ * every append and rebuilding four views per message is waste; the language+ * change is the one thing that invalidates it, in [onLocaleChanged].+ *+ * No horizontal padding of its own: the rows are sized to the column's own+ * inset, which is what [column] already reserves, so an offer lines up with+ * the conversation underneath it instead of floating two dp to its right.+ */+ private val suggest = LinearLayout(context).apply {+ orientation = LinearLayout.VERTICAL+ gravity = Gravity.START+ visibility = View.GONE+ setPadding(0, dp(24), 0, 0)+ }+/*** What is happening right now — a partial transcript, the tool being run,* the sentence being read out. Lives as the list's last row rather than in@@ -145,6 +203,7 @@ class HistoryListView(private val context: Context) : ScrollView(context) {LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT),)column.addView(empty)+ column.addView(suggest)column.addView(live)}@@ -202,7 +261,16 @@ class HistoryListView(private val context: Context) : ScrollView(context) {*/fun refresh() {val all = ChatHistory.snapshot()- empty.visibility = if (all.isEmpty()) View.VISIBLE else View.GONE+ // An empty log is the only time the suggestions are shown, so it is+ // also the only time they can be worth building. Built lazily here+ // rather than in `init` so the language is settled first.+ val opens = all.isEmpty()+ if (opens && suggest.childCount == 0) buildSuggestions()+ // Which of the two mutually-exclusive empty states: the suggestions if+ // there are any, the bare line if the table is empty.+ val offering = opens && suggest.childCount > 0+ suggest.visibility = if (offering) View.VISIBLE else View.GONE+ empty.visibility = if (opens && !offering) View.VISIBLE else View.GONEval ids = all.map { it.id }.toSet()val open = all.filter { it.page != null }.map { it.id }.toSet()@@ -215,6 +283,7 @@ class HistoryListView(private val context: Context) : ScrollView(context) {// card scrolling a conversation that no longer existed.column.removeAllViews()column.addView(empty)+ column.addView(suggest)column.addView(live)laid.clear()laidOpen.clear()@@ -248,14 +317,159 @@ class HistoryListView(private val context: Context) : ScrollView(context) {fun onLocaleChanged() {lctx = AppLocale.wrap(context)empty.text = lctx.getString(R.string.history_empty)+ // The bubbles are scene names and that is translated content, so they+ // are rebuilt rather than relabelled — same reason the rows are.+ suggest.removeAllViews()laid.clear()laidOpen.clear()column.removeAllViews()column.addView(empty)+ column.addView(suggest)column.addView(live)refresh()}+ /**+ * The empty state's offer: one line inviting the user in, then a pane per+ * ready-made scene, showing the scene's **title** over what it actually+ * does, and carrying its **example**.+ *+ * Title on the outside, example on the send, and both read from one preset+ * ([ScenePresets.Text.example]) so an offer cannot promise one thing and+ * send another. The title is the label because that is what a person picks+ * between; the example is what they would have had to invent for+ * themselves, which is exactly the part a newcomer cannot do yet. The+ * preset's `name` rides along with the tap and is never shown — see+ * [offer].+ *+ * Every preset, not just the un-adopted ones: the state this appears in is+ * "nothing has happened yet", and what the assistant can do does not depend+ * on which scenes the notebook already holds. See [ScenePresets].+ */+ private fun buildSuggestions() {+ suggest.removeAllViews()+ val english = VoiceConfig.uiLanguage(context) == VoiceConfig.LANG_EN+ suggest.addView(+ TextView(context).apply {+ // Speaking is named before picking, deliberately. "Pick one," on+ // its own read as *this is the only way in*, and the ball+ // overhead is the other door — the same two the tips at the foot+ // of the card list. What sits below is an offer, and an offer+ // that presents itself as the only option is not one.+ text = lctx.getString(R.string.history_suggest_hint)+ textSize = Glass.Type.CAPTION+ // SECONDARY, not MUTED. MUTED is the token for a footnote on a+ // *card*, where it sits on a surface this app controls; this+ // line's background is the user's own app, seen through the+ // backdrop, and on a bright one MUTED measures within a couple+ // of steps of what is behind it. See [offer] for the same+ // argument about the rows.+ setTextColor(Color.parseColor(Glass.SECONDARY))+ // 16 dp, not 4: this caption introduces the rows under it, so its+ // text has to start where their text starts — that is the same+ // inset [offer] puts its title at, and the pane's own edge is+ // outside both. At 4 dp it hung eleven dp to the left of the+ // column it was describing.+ setPadding(dp(16), 0, dp(16), dp(10))+ },+ LinearLayout.LayoutParams(MATCH, WRAP),+ )+ for (p in ScenePresets.all) {+ suggest.addView(+ offer(p, p.text(english)),+ LinearLayout.LayoutParams(MATCH, WRAP).apply { bottomMargin = dp(10) },+ )+ }+ }++ /**+ * One offer, and the whole of it is the button.+ *+ * Takes the whole [ScenePresets.Preset] rather than just its [ScenePresets.Text]+ * because the tap carries `name` too: that is the key the service adopts the+ * scene under, and unlike the title it is not translated, so it cannot be+ * read back off what the bubble happens to be showing.+ *+ * ### Why a well rather than the panel the tidy answer would pick+ *+ * [Glass.panel] — a 6% white film — is the right surface for a group of rows+ * *inside* a card, and it is what `ScenesUi` gives its own preset rows. It is+ * wrong here for a measurable reason: these have no card behind them, only+ * the backdrop, and on the device a 6% film came out **five luminance steps**+ * off the blurred photo underneath — invisible fill, with the one-pixel edge+ * left doing all the work of saying a pane was there. That is the difference+ * [Glass.GLASS] documents, and why the fix is not "a lighter film".+ *+ * So this takes the surface the two other things on this backdrop already+ * use — [Glass.well], the same recessed fill as the control bar and the+ * scene chip. Those two carry the reason in as many words: a pane over a+ * translucent card has to be *darker* than what it sits on, or its text is+ * read against whatever the user's app happens to be. Dark fill, light+ * type, contrast this app owns rather than borrows.+ *+ * ### The two lines+ *+ * Name over summary, which is `ScenesUi.addPresets`' own pairing — at+ * [Glass.Type.BODY]/[Glass.TITLE] and [Glass.Type.CAPTION]/[Glass.SECONDARY],+ * four dp apart. A bare name was the first version and it asked the user to+ * already know what "开会记录" means before tapping it, which is the opposite+ * of helping someone in. The name is still the brightest thing in the row+ * because the name is what they are choosing between; the sentence is what+ * tells them which one they want.+ *+ * Two lines, and the summaries are written to fit inside that. Three was the+ * first version and it does not survive translation: the Chinese summaries+ * run to two lines at this width, the English ones to three, and the extra+ * line per row added up to more than the scrollback has to give — the list+ * then scrolled itself to the bottom on open, which pushed the hint line off+ * the top and left the first offer flush against the edge. Sizing the copy+ * to the layout is the fix rather than letting every row ellipsize: a+ * sentence cut off midway through is worse than a shorter one.+ *+ * ### The press+ *+ * A ripple, held to the rounded corners by the well's own outline — the same+ * treatment [buildRow] gives a page row, because this is the same situation:+ * a whole row that is one control. Not [Glass.pressable] as well, which is+ * the treatment for a small pill; scaling a full-width row under a finger+ * moves its edges while its neighbours stay put, and two press effects on+ * one tap is how a considered surface starts to look assembled.+ */+ private fun offer(p: ScenePresets.Preset, t: ScenePresets.Text): View {+ val row = LinearLayout(context).apply {+ orientation = LinearLayout.VERTICAL+ setPadding(dp(16), dp(12), dp(16), dp(12))+ isClickable = true+ background = RippleDrawable(+ ColorStateList.valueOf(RIPPLE),+ Glass.well(context, dp(18)),+ null,+ )+ setOnClickListener { onSuggestionClick?.invoke(p.name, t.title, t.example) }+ }+ row.addView(+ TextView(context).apply {+ text = t.title+ textSize = Glass.Type.BODY+ setTextColor(Color.parseColor(Glass.TITLE))+ },+ LinearLayout.LayoutParams(MATCH, WRAP),+ )+ row.addView(+ TextView(context).apply {+ text = t.summary+ textSize = Glass.Type.CAPTION+ setTextColor(Color.parseColor(Glass.SECONDARY))+ setLineSpacing(dp(2).toFloat(), 1f)+ setPadding(0, dp(4), 0, 0)+ maxLines = 2+ ellipsize = android.text.TextUtils.TruncateAt.END+ },+ LinearLayout.LayoutParams(MATCH, WRAP),+ )+ return row+ }+private fun buildRow(e: ChatHistory.Entry): View {val mine = e.role == ChatHistory.Role.USERval bad = e.role == ChatHistory.Role.ERROR@@ -427,6 +641,10 @@ class HistoryListView(private val context: Context) : ScrollView(context) {/** How long a [FloatingWindowUi.SubtitleKind.FINAL] live line stays up. */const val FINAL_LINGER_MS = 5_000L+ /** The suggestion column's own layout, kept short for [buildSuggestions]. */+ const val MATCH = LinearLayout.LayoutParams.MATCH_PARENT+ const val WRAP = LinearLayout.LayoutParams.WRAP_CONTENT+/*** A [Glass] token seen through the film: its hue at the film's alpha.* Derived rather than written out so the tinted panes cannot driftdiff --git a/app/src/main/res/values-en/strings.xml b/app/src/main/res/values-en/strings.xmlindex fb07209..52a247f 100644--- a/app/src/main/res/values-en/strings.xml+++ b/app/src/main/res/values-en/strings.xml@@ -264,6 +264,8 @@<string name="dev_perm_say_runtime">A dialog will pop up — just tap Allow.</string><string name="dev_perm_say_notification">I\'ll open Notification access settings — find this app and turn it on.</string><string name="history_empty">No conversation yet</string>+ <string name="history_suggest_hint">Tell me, or pick one</string>+ <string name="suggestion_turn">Enter the \"%1$s\" scene. %2$s</string><string name="history_role_you">You · %1$s</string><string name="history_role_assistant">Andee · %1$s</string><string name="history_role_error">Error · %1$s</string>diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xmlindex 6b85169..3f15eb1 100644--- a/app/src/main/res/values/strings.xml+++ b/app/src/main/res/values/strings.xml@@ -246,6 +246,8 @@<string name="dev_perm_say_runtime">会弹窗,点允许即可。</string><string name="dev_perm_say_notification">会打开通知使用权设置,找到这个应用打开开关。</string><string name="history_empty">还没有对话</string>+ <string name="history_suggest_hint">告诉我,或者选一个</string>+ <string name="suggestion_turn">进入「%1$s」情景。%2$s</string><string name="history_role_you">你 · %1$s</string><string name="history_role_assistant">Andee · %1$s</string><string name="history_role_error">出错 · %1$s</string>diff --git a/app/src/test/java/net/kuafuai/andee/config/ScenePresetsTest.kt b/app/src/test/java/net/kuafuai/andee/config/ScenePresetsTest.ktindex 53f31a2..67b2453 100644--- a/app/src/test/java/net/kuafuai/andee/config/ScenePresetsTest.kt+++ b/app/src/test/java/net/kuafuai/andee/config/ScenePresetsTest.kt@@ -12,6 +12,15 @@ class ScenePresetsTest {private val nameRule = Regex("[a-z0-9_]{1,40}")+ private companion object {+ /**+ * What fits the empty card's two-line summary at the width it is given,+ * with room to spare for a wider glyph set than Latin and for a device+ * with a generous font scale.+ */+ const val SUMMARY_BUDGET = 80+ }+@Testfun `every preset fits the limits saveScene enforces, in both languages`() {for (p in ScenePresets.all) {@@ -23,11 +32,25 @@ class ScenePresetsTest {assertTrue("$tag title over 40", t.title.length <= 40)assertTrue("$tag summary blank", t.summary.isNotBlank())assertTrue("$tag summary over 160", t.summary.length <= 160)+ // The empty card draws this under the preset's name, in a row+ // capped at two lines (`HistoryListView.offer`). Both languages+ // are checked here because the two do not wrap alike: the+ // Chinese summaries came in at two lines and their English+ // twins at three, and one extra line per row was enough to push+ // the offers past the scrollback and scroll the hint off the+ // top. A number to fit, rather than a comment asking nicely.+ assertTrue("$tag summary over $SUMMARY_BUDGET", t.summary.length <= SUMMARY_BUDGET)assertTrue("$tag prompt blank", t.prompt.isNotBlank())assertTrue("$tag prompt is ${t.prompt.length} chars, limit ${Notebook.MAX_SCENE_PROMPT}",t.prompt.length <= Notebook.MAX_SCENE_PROMPT,)+ // The example is not decoration: it is the whole text of the+ // turn a tapped bubble sends (see HistoryListView /+ // onSuggestionClick). A blank one is a bubble that talks to+ // nobody, and it would only be noticed by whoever tapped it.+ assertTrue("$tag example blank", t.example.isNotBlank())+ assertTrue("$tag example over 120", t.example.length <= 120)}}}@@ -37,4 +60,28 @@ class ScenePresetsTest {val names = ScenePresets.all.map { it.name }assertTrue(names.size == names.toSet().size)}++ @Test+ fun `every name the card offers is one the table can look back up`() {+ // `adoptIfMissing` resolves the name the bubble passed with `byName`, and+ // reports a miss by returning false rather than throwing. A name that+ // came out of `all` but did not survive the round trip would put us back+ // where this started — a bubble that names a scene nobody saves — and+ // the only symptom would be the model saying it has never seen one.+ for (p in ScenePresets.all) {+ assertTrue(p.name, ScenePresets.byName(p.name) === p)+ }+ assertTrue(ScenePresets.byName("no_such_scene") == null)+ }++ @Test+ fun `preset names are used verbatim as the scene's stored name`() {+ // The bubble hands the raw preset name to adoption instead of reading it+ // back from the title (which is translated and can change). That only+ // works while every name is already a legal stored key, so the rule is+ // asserted here rather than trusted.+ for (p in ScenePresets.all) {+ assertTrue(p.name, nameRule.matches(p.name))+ }+ }}