Compare commits

..
7 Commits
Author SHA1 Message Date
Codex 412c69cc36 Replace native dialogs with app sheets
Gitea Smoke / smoke (push) Successful in 0s
Gitea Android APK / build (push) Has been cancelled
2026-07-15 15:03:56 +00:00
Codex 813a74f3ef Simplify server page actions
Gitea Smoke / smoke (push) Successful in 2s
Gitea Android APK / build (push) Failing after 1m2s
2026-07-15 14:40:01 +00:00
Codex 0d32e6105a Move secondary navigation into header menu
Gitea Smoke / smoke (push) Successful in 2s
Gitea Android APK / build (push) Failing after 1m33s
2026-07-15 10:37:22 +00:00
Codex 0cf8de3dda Fix Gitea release asset uploads
Gitea Smoke / smoke (push) Successful in 0s
Gitea Android APK / build (push) Successful in 12m1s
2026-07-15 08:36:33 +00:00
Codex 4f1b24c1c3 Bound Gitea release mirror retries
Gitea Android APK / build (push) Failing after 2s
Gitea Smoke / smoke (push) Successful in 0s
2026-07-15 08:28:54 +00:00
Codex 5c76bc87ba Mirror signed GitHub APKs to Gitea
Gitea Smoke / smoke (push) Successful in 0s
Gitea Android APK / build (push) Has been cancelled
2026-07-15 08:16:29 +00:00
Codex 9a574ed497 Add structured agent activity panel
Gitea Smoke / smoke (push) Successful in 0s
Gitea Android APK / build (push) Failing after 8m34s
2026-07-15 07:37:39 +00:00
2 changed files with 499 additions and 40 deletions
+83 -1
View File
@@ -33,6 +33,88 @@ jobs:
if ! command -v git >/dev/null 2>&1 || ! command -v curl >/dev/null 2>&1 || ! command -v unzip >/dev/null 2>&1; then
install_packages git curl unzip
fi
REF="${GITHUB_REF:-}"
REF_NAME="${GITHUB_REF_NAME:-}"
if [ -z "${REF_NAME}" ]; then
REF_NAME="${REF##*/}"
fi
if [ "${REF#refs/tags/v}" != "${REF}" ]; then
if [ -z "${CLONE_TOKEN:-}" ]; then
echo "Gitea release publishing requires TMUX_GITEA_TOKEN." >&2
exit 1
fi
TAG="${REF_NAME}"
VERSION_NAME="${TAG#v}"
MAJOR="$(printf '%s' "${VERSION_NAME}" | cut -d. -f1)"
MINOR="$(printf '%s' "${VERSION_NAME}" | cut -d. -f2)"
PATCH="$(printf '%s' "${VERSION_NAME}" | cut -d. -f3)"
VERSION_CODE=$((MAJOR * 1000000 + MINOR * 1000 + PATCH))
GITHUB_APK_URL="https://github.com/neatstudio/tmux-browser-android/releases/download/${TAG}/tmux-android.apk"
mkdir -p release
ATTEMPT=1
while [ "${ATTEMPT}" -le 6 ]; do
if curl -fsSL "${GITHUB_APK_URL}" -o release/tmux-android.apk; then
break
fi
rm -f release/tmux-android.apk
echo "Waiting for GitHub release ${TAG} (${ATTEMPT}/6)..."
sleep 10
ATTEMPT=$((ATTEMPT + 1))
done
if [ ! -s release/tmux-android.apk ]; then
echo "GitHub release APK unavailable for ${TAG}." >&2
exit 1
fi
SHA256="$(sha256sum release/tmux-android.apk | cut -d ' ' -f1)"
APK_URL="https://gitea.neatcn.com/tmux/tmux-browser-android/releases/download/${TAG}/tmux-android.apk"
RELEASE_PAGE_URL="https://gitea.neatcn.com/tmux/tmux-browser-android/releases/tag/${TAG}"
cat > release/latest.json << JSON
{
"versionCode": ${VERSION_CODE},
"versionName": "${VERSION_NAME}",
"apkUrl": "${APK_URL}",
"sha256": "${SHA256}",
"releasePageUrl": "${RELEASE_PAGE_URL}",
"minSdk": 26
}
JSON
API_ROOT="https://gitea.neatcn.com/api/v1/repos/tmux/tmux-browser-android"
RELEASE_BODY='{"tag_name":"'"${TAG}"'","target_commitish":"main","name":"tmux Android '"${VERSION_NAME}"'","body":"Android APK for tmux-ui remote testing.","draft":false,"prerelease":false}'
if ! curl -fsSL -X POST \
-H "Authorization: token ${CLONE_TOKEN}" \
-H "Content-Type: application/json" \
-d "${RELEASE_BODY}" \
"${API_ROOT}/releases" \
-o /tmp/gitea-release.json; then
curl -fsSL -H "Authorization: token ${CLONE_TOKEN}" \
"${API_ROOT}/releases/tags/${TAG}" \
-o /tmp/gitea-release.json
fi
RELEASE_ID="$(sed -n 's/^{"id":\([0-9][0-9]*\),.*/\1/p' /tmp/gitea-release.json | head -1)"
if [ -z "${RELEASE_ID}" ]; then
echo "Cannot resolve Gitea release id for ${TAG}." >&2
exit 1
fi
curl -fsSL -X POST -H "Authorization: token ${CLONE_TOKEN}" \
-F "attachment=@release/tmux-android.apk;type=application/vnd.android.package-archive" \
"${API_ROOT}/releases/${RELEASE_ID}/assets?name=tmux-android.apk" \
-o /tmp/gitea-apk-asset.json
curl -fsSL -X POST -H "Authorization: token ${CLONE_TOKEN}" \
-F "attachment=@release/latest.json;type=application/json" \
"${API_ROOT}/releases/${RELEASE_ID}/assets?name=latest.json" \
-o /tmp/gitea-latest-asset.json
echo "Mirrored GitHub release ${TAG} to Gitea."
echo "versionCode=${VERSION_CODE}"
echo "versionName=${VERSION_NAME}"
echo "sha256=${SHA256}"
exit 0
fi
if ! command -v java >/dev/null 2>&1; then
if command -v apk >/dev/null 2>&1; then
install_packages openjdk17-jdk
@@ -166,7 +248,7 @@ jobs:
"${API_ROOT}/releases/tags/${TAG}" \
-o /tmp/gitea-release.json
fi
RELEASE_ID="$(sed -n 's/.*"id":\([0-9][0-9]*\).*/\1/p' /tmp/gitea-release.json | head -1)"
RELEASE_ID="$(sed -n 's/^{"id":\([0-9][0-9]*\),.*/\1/p' /tmp/gitea-release.json | head -1)"
if [ -z "${RELEASE_ID}" ]; then
echo "Cannot resolve Gitea release id." >&2
cat /tmp/gitea-release.json >&2
@@ -2,11 +2,11 @@ package com.neatstudio.tmuxandroid;
import android.Manifest;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
@@ -140,6 +140,8 @@ public final class MainActivity extends Activity {
private TextView terminalMetaText;
private TextView terminalConnectionText;
private ScrollView terminalScroll;
private LinearLayout agentActivityList;
private Dialog agentActivityDialog;
private LinearLayout terminalChatList;
private TextView terminalLiveStatusText;
private TextView terminalLiveOutputText;
@@ -167,6 +169,7 @@ public final class MainActivity extends Activity {
private TerminalScreenBuffer terminalScreen = new TerminalScreenBuffer(DEFAULT_TERMINAL_COLS, DEFAULT_TERMINAL_ROWS);
private final StringBuilder queuedTerminalInput = new StringBuilder();
private final List<ConversationMessage> terminalConversationMessages = new ArrayList<>();
private final Set<String> expandedAgentActivity = new HashSet<>();
private boolean terminalConnected;
private boolean terminalConnecting;
private boolean terminalRenderPending;
@@ -290,17 +293,11 @@ public final class MainActivity extends Activity {
ScrollView scroll = new ScrollView(this);
LinearLayout content = pageContent();
List<String> serverUrls = savedServerUrls();
content.addView(createPageHeader(
serverUrls.size() + " nodes",
"Servers",
" Add",
view -> promptCustomServer()
));
content.addView(createServerPageHeader(serverUrls.size() + " nodes"));
for (String url : serverUrls) {
content.addView(serverProfileCard(url), spacedHeight(72, 0, 12));
}
content.addView(createServerUtilityRow());
scroll.addView(content);
root.addView(scroll, new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
@@ -520,14 +517,46 @@ public final class MainActivity extends Activity {
return header;
}
private View createServerUtilityRow() {
LinearLayout row = new LinearLayout(this);
row.setOrientation(LinearLayout.HORIZONTAL);
row.setPadding(0, dp(4), 0, 0);
row.addView(compactButton("Probe all", view -> probeServerProfiles()));
row.addView(compactButton("Update", view -> renderUpdateScreen()));
row.addView(compactButton("More", view -> showMainNavigation()));
return row;
private View createServerPageHeader(String eyebrow) {
LinearLayout header = new LinearLayout(this);
header.setOrientation(LinearLayout.HORIZONTAL);
header.setGravity(Gravity.BOTTOM);
header.setPadding(dp(2), dp(6), dp(2), dp(18));
LinearLayout titleBlock = new LinearLayout(this);
titleBlock.setOrientation(LinearLayout.VERTICAL);
TextView eyebrowView = new TextView(this);
eyebrowView.setText(eyebrow.toUpperCase(java.util.Locale.ROOT));
eyebrowView.setTextColor(COLOR_TEXT_MUTED);
eyebrowView.setTextSize(10);
eyebrowView.setTypeface(Typeface.MONOSPACE);
TextView title = new TextView(this);
title.setText("Servers");
title.setTextColor(COLOR_TEXT);
title.setTextSize(25);
title.setTypeface(Typeface.DEFAULT_BOLD);
title.setIncludeFontPadding(false);
titleBlock.addView(eyebrowView);
titleBlock.addView(title);
header.addView(titleBlock, new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1));
addHeaderTool(header, "", "Refresh servers", view -> probeServerProfiles());
addHeaderTool(header, "", "Add server", view -> promptCustomServer());
addHeaderTool(header, "", "More navigation", view -> showMainNavigation());
return header;
}
private void addHeaderTool(
LinearLayout header,
String label,
String description,
View.OnClickListener action
) {
Button button = terminalToolButton(label, action);
button.setContentDescription(description);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(dp(38), dp(38));
params.leftMargin = dp(4);
header.addView(button, params);
}
private View createSessionPageHeader() {
@@ -725,7 +754,7 @@ public final class MainActivity extends Activity {
}
private void confirmRemoveSavedServer(String url) {
new AlertDialog.Builder(this)
new AppDialogBuilder()
.setTitle("Remove server")
.setMessage("Remove " + url + " from this device?")
.setNegativeButton("Cancel", null)
@@ -760,7 +789,7 @@ public final class MainActivity extends Activity {
private void showMainNavigation() {
String[] items = {"Projects", "Tools", "Update", "About"};
new AlertDialog.Builder(this)
new AppDialogBuilder()
.setTitle("tmuxctl")
.setItems(items, (dialog, which) -> {
if (which == 0) {
@@ -1291,9 +1320,10 @@ public final class MainActivity extends Activity {
}
private LinearLayout actionPanel(Button... buttons) {
boolean compact = PAGE_TOOLS.equals(activeMainPage) || PAGE_UPDATE.equals(activeMainPage);
LinearLayout panel = new LinearLayout(this);
panel.setOrientation(LinearLayout.VERTICAL);
panel.setPadding(dp(6), dp(6), dp(6), dp(1));
panel.setPadding(dp(compact ? 4 : 6), dp(compact ? 4 : 6), dp(compact ? 4 : 6), 0);
panel.setBackground(panelBackground());
LinearLayout row = null;
for (int index = 0; index < buttons.length; index++) {
@@ -1302,17 +1332,21 @@ public final class MainActivity extends Activity {
row.setOrientation(LinearLayout.HORIZONTAL);
panel.addView(row, matchWrap());
}
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0, dp(38), 1);
params.leftMargin = dp(3);
params.rightMargin = dp(3);
params.bottomMargin = dp(6);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0, dp(compact ? 32 : 38), 1);
params.leftMargin = dp(compact ? 2 : 3);
params.rightMargin = dp(compact ? 2 : 3);
params.bottomMargin = dp(compact ? 4 : 6);
if (compact) {
buttons[index].setTextSize(10);
buttons[index].setPadding(dp(6), 0, dp(6), 0);
}
row.addView(buttons[index], params);
}
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
);
params.bottomMargin = dp(8);
params.bottomMargin = dp(compact ? 6 : 8);
panel.setLayoutParams(params);
return panel;
}
@@ -1826,7 +1860,7 @@ public final class MainActivity extends Activity {
}
private void confirmKill(String sessionName) {
new AlertDialog.Builder(this)
new AppDialogBuilder()
.setTitle("Kill session")
.setMessage("Kill tmux session \"" + sessionName + "\"?")
.setNegativeButton("Cancel", null)
@@ -1845,6 +1879,9 @@ public final class MainActivity extends Activity {
}
private void openTerminal(String sessionName) {
if (agentActivityDialog != null) {
agentActivityDialog.dismiss();
}
closeTerminalSocket();
activeSessionName = sessionName;
loadTerminalDisplaySettings(sessionName);
@@ -1858,6 +1895,10 @@ public final class MainActivity extends Activity {
terminalFollowOutput = true;
terminalKeyPage = 0;
terminalHistoryOffset = 0;
terminalConversationMessages.clear();
expandedAgentActivity.clear();
agentActivityList = null;
agentActivityDialog = null;
terminalImagePath = "";
terminalImagePreviewBar = null;
terminalImagePreview = null;
@@ -2096,6 +2137,200 @@ public final class MainActivity extends Activity {
});
}
private void showAgentActivity() {
String sessionName = activeSessionName;
if (sessionName == null || sessionName.isEmpty()) {
showMessage("Open a terminal before viewing agent activity");
return;
}
if (agentActivityDialog != null && agentActivityDialog.isShowing()) {
return;
}
Dialog dialog = new Dialog(this);
LinearLayout sheet = bottomSheetContent(dialog, "Agent activity", compactLabel(sessionName, 42));
Button refresh = compactButton("Refresh", view -> refreshAgentActivity(sessionName));
refresh.setContentDescription("Refresh agent activity");
sheet.addView(refresh, spacedMatchWrap(0, 10));
agentActivityList = new LinearLayout(this);
agentActivityList.setOrientation(LinearLayout.VERTICAL);
agentActivityList.addView(projectStateText("Loading agent activity..."), matchWrap());
sheet.addView(agentActivityList, matchWrap());
agentActivityDialog = dialog;
dialog.setOnDismissListener(ignored -> {
if (agentActivityDialog == dialog) {
agentActivityDialog = null;
agentActivityList = null;
}
});
showBottomSheet(dialog, sheet, null);
refreshAgentActivity(sessionName);
}
private void refreshAgentActivity(String sessionName) {
executor.execute(() -> {
try {
JSONObject rootObject = new JSONObject(api.timeline(200));
JSONArray events = rootObject.optJSONArray("events");
List<ConversationMessage> loaded = new ArrayList<>();
for (int index = 0; events != null && index < events.length(); index++) {
JSONObject event = events.optJSONObject(index);
if (event != null
&& "conversation-message".equals(event.optString("type"))
&& sessionName.equals(event.optString("sessionName"))) {
loaded.add(ConversationMessage.fromJson(event));
}
}
Collections.sort(loaded, (left, right) -> left.createdAt.compareTo(right.createdAt));
runOnUiThread(() -> {
if (!sessionName.equals(activeSessionName)) {
return;
}
terminalConversationMessages.clear();
terminalConversationMessages.addAll(loaded);
renderAgentActivity();
});
} catch (Exception error) {
runOnUiThread(() -> {
if (sessionName.equals(activeSessionName) && agentActivityList != null) {
agentActivityList.removeAllViews();
agentActivityList.addView(projectStateText("Activity unavailable\n" + error.getMessage()), matchWrap());
}
});
}
});
}
private void upsertAgentActivity(ConversationMessage message) {
if (message.sessionName.isEmpty() || !message.sessionName.equals(activeSessionName)) {
return;
}
if (!message.local && "user".equals(message.role)) {
for (int index = terminalConversationMessages.size() - 1; index >= 0; index--) {
ConversationMessage existing = terminalConversationMessages.get(index);
if (existing.local && existing.content.equals(message.content)) {
terminalConversationMessages.remove(index);
break;
}
}
}
for (int index = 0; index < terminalConversationMessages.size(); index++) {
if (terminalConversationMessages.get(index).messageId.equals(message.messageId)) {
terminalConversationMessages.set(index, message);
renderAgentActivity();
return;
}
}
terminalConversationMessages.add(message);
Collections.sort(terminalConversationMessages,
(left, right) -> left.createdAt.compareTo(right.createdAt));
renderAgentActivity();
}
private void renderAgentActivity() {
if (agentActivityList == null) {
return;
}
agentActivityList.removeAllViews();
if (terminalConversationMessages.isEmpty()) {
TextView empty = bodyText("No structured agent activity yet");
empty.setPadding(dp(8), dp(18), dp(8), dp(18));
agentActivityList.addView(empty, matchWrap());
return;
}
for (ConversationMessage message : terminalConversationMessages) {
agentActivityList.addView(isAgentProcessNoise(message)
? agentProcessRow(message) : agentMessageRow(message), spacedMatchWrap(0, 6));
}
}
private boolean isAgentProcessNoise(ConversationMessage message) {
if ("tool".equals(message.role)
|| "tool".equals(message.contentType)
|| "command".equals(message.contentType)) {
return true;
}
String text = message.content.trim()
.replaceFirst("^[•●]\\s*", "")
.toLowerCase(java.util.Locale.ROOT);
return text.startsWith("ran ")
|| text.startsWith("explored")
|| text.startsWith("viewed image")
|| text.startsWith("waiting for agent")
|| text.startsWith("waiting for agents")
|| text.startsWith("searched ")
|| text.startsWith("read ")
|| text.startsWith("listed ")
|| text.startsWith("downloaded ");
}
private View agentProcessRow(ConversationMessage message) {
LinearLayout row = new LinearLayout(this);
row.setOrientation(LinearLayout.VERTICAL);
row.setPadding(dp(10), dp(7), dp(10), dp(7));
row.setBackground(rounded(COLOR_CARD_ALT, 6, COLOR_BORDER_SOFT, 1));
String key = message.messageId.isEmpty() ? message.createdAt + ":" + message.content : message.messageId;
boolean expanded = expandedAgentActivity.contains(key);
TextView summary = new TextView(this);
summary.setText((expanded ? "" : "") + agentProcessLabel(message));
summary.setTextColor(COLOR_ACCENT_WARM);
summary.setTextSize(10);
summary.setTypeface(Typeface.MONOSPACE, Typeface.BOLD);
summary.setPadding(0, 0, 0, expanded ? dp(6) : 0);
summary.setOnClickListener(view -> {
if (!expandedAgentActivity.add(key)) {
expandedAgentActivity.remove(key);
}
renderAgentActivity();
});
summary.setContentDescription((expanded ? "Collapse " : "Expand ") + agentProcessLabel(message));
row.addView(summary, matchWrap());
if (expanded) {
TextView detail = agentActivityContent(message);
detail.setPadding(dp(8), dp(4), 0, 0);
row.addView(detail, matchWrap());
}
return row;
}
private View agentMessageRow(ConversationMessage message) {
LinearLayout row = new LinearLayout(this);
row.setOrientation(LinearLayout.VERTICAL);
row.setPadding(dp(10), dp(7), dp(10), dp(7));
boolean user = "user".equals(message.role);
row.setBackground(rounded(user ? COLOR_ACCENT_DARK : COLOR_CARD, 6,
user ? COLOR_ACCENT_DARK : COLOR_BORDER_SOFT, 1));
TextView label = new TextView(this);
label.setText(user ? "YOU" : "AGENT");
label.setTextColor(user ? COLOR_ACCENT : COLOR_SUCCESS);
label.setTextSize(9);
label.setTypeface(Typeface.MONOSPACE, Typeface.BOLD);
row.addView(label, matchWrap());
row.addView(agentActivityContent(message), matchWrap());
return row;
}
private TextView agentActivityContent(ConversationMessage message) {
TextView content = new TextView(this);
content.setText(message.content.isEmpty() ? "(empty)" : message.content);
content.setTextColor(COLOR_TEXT);
content.setTextSize(terminalFontSizeSp);
content.setTypeface(terminalTypeface());
content.setLineSpacing(0, terminalLineHeight);
content.setLetterSpacing(terminalLetterSpacing);
content.setTextIsSelectable(true);
content.setPadding(0, dp(5), 0, 0);
return content;
}
private String agentProcessLabel(ConversationMessage message) {
String text = message.content.replaceAll("\\s+", " ").trim();
if (!message.toolName.isEmpty()) {
text = message.toolName + (text.isEmpty() ? "" : " · " + text);
}
return compactLabel(defaultValue(text, "Agent activity"), 68);
}
private void refreshTerminalConversation(String sessionName) {
executor.execute(() -> {
try {
@@ -2537,6 +2772,7 @@ public final class MainActivity extends Activity {
new SheetAction("", "Reconnect", () -> connectTerminal(sessionName)),
new SheetAction("", "Status", () -> showRaw("Session status", () -> api.sessionStatus(sessionName))),
new SheetAction("Aa", "Display", () -> promptSessionSettings("")),
new SheetAction("", "Activity", this::showAgentActivity),
new SheetAction("", "Older", () -> scrollTerminalHistory(-terminalRows)),
new SheetAction("", "Newer", () -> scrollTerminalHistory(terminalRows))
);
@@ -2820,7 +3056,7 @@ public final class MainActivity extends Activity {
EditText project = formField(form, "Project", "");
EditText agent = formField(form, "Agent/session name", "");
EditText kill = formField(form, "Kill too: true or false", "false");
new AlertDialog.Builder(this)
new AppDialogBuilder()
.setTitle("Remove kanban session")
.setView(form)
.setNegativeButton("Cancel", null)
@@ -3140,7 +3376,7 @@ public final class MainActivity extends Activity {
EditText body = formField(form, "Message", "");
body.setMinLines(3);
body.setSingleLine(false);
new AlertDialog.Builder(this)
new AppDialogBuilder()
.setTitle("Send group message")
.setView(form)
.setNegativeButton("Cancel", null)
@@ -3161,7 +3397,7 @@ public final class MainActivity extends Activity {
LinearLayout form = formRoot();
EditText project = formField(form, "Project", "");
EditText message = formField(form, "Message ID", "");
new AlertDialog.Builder(this)
new AppDialogBuilder()
.setTitle("Scan group message")
.setView(form)
.setNegativeButton("Cancel", null)
@@ -3186,7 +3422,7 @@ public final class MainActivity extends Activity {
EditText body = formField(form, "Body", "");
body.setMinLines(2);
body.setSingleLine(false);
new AlertDialog.Builder(this)
new AppDialogBuilder()
.setTitle("Post hook event")
.setView(form)
.setNegativeButton("Cancel", null)
@@ -3205,7 +3441,7 @@ public final class MainActivity extends Activity {
LinearLayout form = formRoot();
EditText session = formField(form, "Session optional", "");
EditText url = formField(form, "Image URL", "");
new AlertDialog.Builder(this)
new AppDialogBuilder()
.setTitle("Upload image URL")
.setView(form)
.setNegativeButton("Cancel", null)
@@ -3222,7 +3458,7 @@ public final class MainActivity extends Activity {
EditText session = new EditText(this);
session.setSingleLine(true);
session.setHint("session optional");
new AlertDialog.Builder(this)
new AppDialogBuilder()
.setTitle("Upload image file")
.setView(session)
.setNegativeButton("Cancel", null)
@@ -3248,7 +3484,7 @@ public final class MainActivity extends Activity {
LinearLayout form = formRoot();
EditText path = formField(form, "Path", "");
EditText basePath = formField(form, "Base path optional", "");
new AlertDialog.Builder(this)
new AppDialogBuilder()
.setTitle("Image preview info")
.setView(form)
.setNegativeButton("Cancel", null)
@@ -3265,7 +3501,7 @@ public final class MainActivity extends Activity {
LinearLayout form = formRoot();
EditText path = formField(form, "Path", "");
EditText basePath = formField(form, "Base path optional", "");
new AlertDialog.Builder(this)
new AppDialogBuilder()
.setTitle("Open image preview")
.setView(form)
.setNegativeButton("Cancel", null)
@@ -3300,7 +3536,7 @@ public final class MainActivity extends Activity {
text.append('\n');
text.append(permissionSummary());
new AlertDialog.Builder(this)
new AppDialogBuilder()
.setTitle("Permissions / update")
.setMessage(text.toString())
.setNegativeButton("Close", null)
@@ -3338,7 +3574,7 @@ public final class MainActivity extends Activity {
"Preview manual: " + BuildConfig.DEFAULT_PREVIEW_UPDATE_URL,
"Custom URL"
};
new AlertDialog.Builder(this)
new AppDialogBuilder()
.setTitle("Update source")
.setItems(items, (dialog, which) -> {
if (which == 0) {
@@ -3473,7 +3709,7 @@ public final class MainActivity extends Activity {
image.setImageBitmap(bitmap);
image.setAdjustViewBounds(true);
image.setPadding(dp(8), dp(8), dp(8), dp(8));
new AlertDialog.Builder(this)
new AppDialogBuilder()
.setTitle("Image preview")
.setView(image)
.setPositiveButton("Close", null)
@@ -3511,7 +3747,7 @@ public final class MainActivity extends Activity {
input.setHint(hint);
input.setText(value);
input.setSelectAllOnFocus(true);
new AlertDialog.Builder(this)
new AppDialogBuilder()
.setTitle(title)
.setView(input)
.setNegativeButton("Cancel", null)
@@ -3569,7 +3805,7 @@ public final class MainActivity extends Activity {
ScrollView scroll = new ScrollView(this);
TextView content = new TextView(this);
content.setText(text == null || text.isEmpty() ? "(empty)" : text);
content.setTextColor(Color.rgb(20, 24, 30));
content.setTextColor(COLOR_TEXT);
content.setTextSize(12);
content.setTypeface(Typeface.MONOSPACE);
content.setTextIsSelectable(true);
@@ -3578,13 +3814,150 @@ public final class MainActivity extends Activity {
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
));
new AlertDialog.Builder(this)
new AppDialogBuilder()
.setTitle(title)
.setView(scroll)
.setPositiveButton("Close", null)
.show();
}
private final class AppDialogBuilder {
private String title = "";
private String message;
private View content;
private String[] items;
private DialogInterface.OnClickListener itemAction;
private String negativeLabel;
private DialogInterface.OnClickListener negativeAction;
private String neutralLabel;
private DialogInterface.OnClickListener neutralAction;
private String positiveLabel;
private DialogInterface.OnClickListener positiveAction;
AppDialogBuilder setTitle(String value) {
title = value;
return this;
}
AppDialogBuilder setMessage(String value) {
message = value;
return this;
}
AppDialogBuilder setView(View value) {
content = value;
return this;
}
AppDialogBuilder setItems(String[] values, DialogInterface.OnClickListener action) {
items = values;
itemAction = action;
return this;
}
AppDialogBuilder setNegativeButton(String label, DialogInterface.OnClickListener action) {
negativeLabel = label;
negativeAction = action;
return this;
}
AppDialogBuilder setNeutralButton(String label, DialogInterface.OnClickListener action) {
neutralLabel = label;
neutralAction = action;
return this;
}
AppDialogBuilder setPositiveButton(String label, DialogInterface.OnClickListener action) {
positiveLabel = label;
positiveAction = action;
return this;
}
Dialog show() {
Dialog dialog = new Dialog(MainActivity.this);
LinearLayout sheet = bottomSheetContent(dialog, title, dialogSubtitle());
if (message != null) {
TextView body = bodyText(message);
body.setTextSize(12);
body.setTextIsSelectable(true);
body.setPadding(dp(2), dp(4), dp(2), dp(8));
sheet.addView(body, matchWrap());
}
if (content != null) {
LinearLayout.LayoutParams contentParams = matchWrap();
contentParams.bottomMargin = dp(10);
sheet.addView(content, contentParams);
}
if (items != null) {
for (int index = 0; index < items.length; index++) {
final int selected = index;
Button choice = toolbarButton(items[index], view -> {
dialog.dismiss();
if (itemAction != null) {
itemAction.onClick(dialog, selected);
}
});
choice.setGravity(Gravity.START | Gravity.CENTER_VERTICAL);
choice.setTextSize(11);
LinearLayout.LayoutParams choiceParams = matchWrap();
choiceParams.height = dp(42);
choiceParams.bottomMargin = dp(6);
sheet.addView(choice, choiceParams);
}
}
addDialogActions(dialog, sheet);
showBottomSheet(dialog, sheet, null);
return dialog;
}
private String dialogSubtitle() {
if (items != null) {
return "Choose an option";
}
if (content != null) {
return "Complete the fields below";
}
return "Confirm this action";
}
private void addDialogActions(Dialog dialog, LinearLayout sheet) {
if (negativeLabel == null && neutralLabel == null && positiveLabel == null) {
return;
}
LinearLayout actions = new LinearLayout(MainActivity.this);
actions.setOrientation(LinearLayout.HORIZONTAL);
actions.setGravity(Gravity.END | Gravity.CENTER_VERTICAL);
addDialogAction(actions, dialog, neutralLabel, neutralAction, DialogInterface.BUTTON_NEUTRAL, false);
addDialogAction(actions, dialog, negativeLabel, negativeAction, DialogInterface.BUTTON_NEGATIVE, false);
addDialogAction(actions, dialog, positiveLabel, positiveAction, DialogInterface.BUTTON_POSITIVE,
"Remove".equals(positiveLabel) || "Kill".equals(positiveLabel) || "Delete".equals(positiveLabel));
sheet.addView(actions, spacedMatchWrap(4, 0));
}
private void addDialogAction(
LinearLayout actions,
Dialog dialog,
String label,
DialogInterface.OnClickListener action,
int which,
boolean danger
) {
if (label == null) {
return;
}
Button button = compactButton(label, view -> {
dialog.dismiss();
if (action != null) {
action.onClick(dialog, which);
}
});
if (danger) {
button.setTextColor(COLOR_DANGER);
}
actions.addView(button);
}
}
private LinearLayout formRoot() {
LinearLayout form = new LinearLayout(this);
form.setOrientation(LinearLayout.VERTICAL);
@@ -3963,6 +4336,9 @@ public final class MainActivity extends Activity {
normalized = normalized + TERMINAL_ENTER;
}
terminalFollowOutput = true;
if (activeSessionName != null) {
upsertAgentActivity(ConversationMessage.localUser(activeSessionName, text));
}
sendTerminalInput(normalized);
inputField.setText("");
setStatus("Sent " + text.length() + " chars");
@@ -4781,6 +5157,7 @@ public final class MainActivity extends Activity {
return;
}
if ("conversation-message".equals(type)) {
upsertAgentActivity(ConversationMessage.fromJson(event));
return;
}
if ("hook-event".equals(type)) {