Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
41e50322be | ||
|
|
f1db46ecbe |
@@ -23,7 +23,6 @@ import android.os.Looper;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.text.InputType;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.view.Gravity;
|
||||
import android.view.HapticFeedbackConstants;
|
||||
import android.view.KeyEvent;
|
||||
@@ -73,8 +72,7 @@ public final class MainActivity extends Activity {
|
||||
private static final int STATUS_SUCCESS = 2;
|
||||
private static final int STATUS_ERROR = 3;
|
||||
private static final int TERMINAL_VIEW_CHAT = 0;
|
||||
private static final int TERMINAL_VIEW_READING = 1;
|
||||
private static final int TERMINAL_VIEW_FULL = 2;
|
||||
private static final int TERMINAL_VIEW_FULL = 1;
|
||||
private static final long TERMINAL_RENDER_INTERVAL_MS = 80L;
|
||||
private static final long[] SOCKET_RECONNECT_DELAYS_MS = {1000L, 2000L, 4000L, 8000L, 15000L};
|
||||
private static final int COLOR_APP_BG = Color.rgb(18, 20, 24);
|
||||
@@ -130,6 +128,7 @@ public final class MainActivity extends Activity {
|
||||
private TextView terminalMetaText;
|
||||
private TextView terminalConnectionText;
|
||||
private Button terminalReadingButton;
|
||||
private Button terminalFullButton;
|
||||
private ScrollView terminalScroll;
|
||||
private LinearLayout terminalChatList;
|
||||
private TextView terminalLiveStatusText;
|
||||
@@ -138,6 +137,7 @@ public final class MainActivity extends Activity {
|
||||
private final Button[] terminalAccessoryTabButtons = new Button[4];
|
||||
private View terminalAccessoryBar;
|
||||
private View terminalComposerBar;
|
||||
private View terminalComposerTabs;
|
||||
private LinearLayout terminalImagePreviewBar;
|
||||
private ImageView terminalImagePreview;
|
||||
private TextView terminalImagePreviewPath;
|
||||
@@ -153,7 +153,6 @@ public final class MainActivity extends Activity {
|
||||
private int lastActiveSessionCount = -1;
|
||||
private TerminalScreenBuffer terminalScreen = new TerminalScreenBuffer(DEFAULT_TERMINAL_COLS, DEFAULT_TERMINAL_ROWS);
|
||||
private final StringBuilder queuedTerminalInput = new StringBuilder();
|
||||
private final Set<String> terminalExpandedBlocks = new HashSet<>();
|
||||
private final Set<String> terminalExpandedMessages = new HashSet<>();
|
||||
private final List<ConversationMessage> terminalConversationMessages = new ArrayList<>();
|
||||
private boolean terminalConnected;
|
||||
@@ -1613,7 +1612,6 @@ public final class MainActivity extends Activity {
|
||||
terminalSelectionEnabled = false;
|
||||
terminalFollowOutput = true;
|
||||
terminalKeyPage = 0;
|
||||
terminalExpandedBlocks.clear();
|
||||
terminalExpandedMessages.clear();
|
||||
terminalConversationMessages.clear();
|
||||
terminalLiveStatusText = null;
|
||||
@@ -1664,6 +1662,7 @@ public final class MainActivity extends Activity {
|
||||
1
|
||||
));
|
||||
terminalAccessoryBar = createAccessoryBar();
|
||||
terminalAccessoryBar.setVisibility(terminalViewMode == TERMINAL_VIEW_CHAT ? View.GONE : View.VISIBLE);
|
||||
root.addView(terminalAccessoryBar, new LinearLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
dp(TERMINAL_KEYS_HEIGHT_DP)
|
||||
@@ -1766,25 +1765,17 @@ public final class MainActivity extends Activity {
|
||||
dp(13)
|
||||
));
|
||||
bar.addView(titleBlock, new LinearLayout.LayoutParams(0, dp(32), 1));
|
||||
terminalReadingButton = terminalToolButton("聊", view -> showTerminalViewPicker());
|
||||
terminalReadingButton.setContentDescription("Choose chat or terminal view");
|
||||
terminalReadingButton = terminalToolButton("聊", view -> showTerminalView(TERMINAL_VIEW_CHAT, true));
|
||||
terminalReadingButton.setContentDescription("Chat view");
|
||||
terminalFullButton = terminalToolButton("终", view -> showTerminalView(TERMINAL_VIEW_FULL, true));
|
||||
terminalFullButton.setContentDescription("Full terminal view");
|
||||
styleTerminalReadingButton();
|
||||
bar.addView(terminalReadingButton);
|
||||
bar.addView(terminalFullButton);
|
||||
bar.addView(terminalToolButton("☰", view -> showTerminalActions(sessionName)));
|
||||
return bar;
|
||||
}
|
||||
|
||||
private void showTerminalViewPicker() {
|
||||
String[] items = {"Chat", "Chinese reading", "Full terminal"};
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle("Session view")
|
||||
.setSingleChoiceItems(items, terminalViewMode, (dialog, which) -> {
|
||||
showTerminalView(which, true);
|
||||
dialog.dismiss();
|
||||
})
|
||||
.show();
|
||||
}
|
||||
|
||||
private void showTerminalView(int mode, boolean announce) {
|
||||
terminalViewMode = mode;
|
||||
if (terminalScroll == null || terminalText == null || terminalChatList == null) {
|
||||
@@ -1799,10 +1790,9 @@ public final class MainActivity extends Activity {
|
||||
));
|
||||
renderTerminalConversation();
|
||||
} else {
|
||||
boolean reading = mode == TERMINAL_VIEW_READING;
|
||||
terminalText.setHorizontallyScrolling(!reading);
|
||||
terminalText.setGravity((reading ? Gravity.TOP : Gravity.BOTTOM) | Gravity.START);
|
||||
terminalText.setMovementMethod(reading ? LinkMovementMethod.getInstance() : null);
|
||||
terminalText.setHorizontallyScrolling(true);
|
||||
terminalText.setGravity(Gravity.BOTTOM | Gravity.START);
|
||||
terminalText.setMovementMethod(null);
|
||||
terminalScroll.addView(terminalText, new ScrollView.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT
|
||||
@@ -1810,24 +1800,32 @@ public final class MainActivity extends Activity {
|
||||
renderTerminalNow();
|
||||
}
|
||||
styleTerminalReadingButton();
|
||||
boolean chat = mode == TERMINAL_VIEW_CHAT;
|
||||
if (terminalAccessoryBar != null) {
|
||||
terminalAccessoryBar.setVisibility(chat ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
if (terminalComposerTabs != null) {
|
||||
terminalComposerTabs.setVisibility(chat ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
if (inputField != null) {
|
||||
inputField.setHint(chat ? "Message" : "type command or text");
|
||||
}
|
||||
if (announce) {
|
||||
setStatus(mode == TERMINAL_VIEW_CHAT
|
||||
? "Chat view"
|
||||
: mode == TERMINAL_VIEW_READING ? "Chinese reading mode" : "Full terminal mode");
|
||||
setStatus(mode == TERMINAL_VIEW_CHAT ? "Chat view" : "Full terminal mode");
|
||||
}
|
||||
}
|
||||
|
||||
private void styleTerminalReadingButton() {
|
||||
if (terminalReadingButton == null) {
|
||||
if (terminalReadingButton == null || terminalFullButton == null) {
|
||||
return;
|
||||
}
|
||||
terminalReadingButton.setText(terminalViewMode == TERMINAL_VIEW_CHAT
|
||||
? "聊" : terminalViewMode == TERMINAL_VIEW_READING ? "读" : "终");
|
||||
terminalReadingButton.setTextColor(terminalViewMode != TERMINAL_VIEW_FULL
|
||||
? Color.rgb(14, 38, 24) : COLOR_TEXT_MUTED);
|
||||
terminalReadingButton.setBackground(terminalViewMode != TERMINAL_VIEW_FULL
|
||||
? rounded(COLOR_ACCENT, 7, COLOR_ACCENT, 1)
|
||||
: buttonBackground());
|
||||
styleTerminalViewButton(terminalReadingButton, terminalViewMode == TERMINAL_VIEW_CHAT);
|
||||
styleTerminalViewButton(terminalFullButton, terminalViewMode == TERMINAL_VIEW_FULL);
|
||||
}
|
||||
|
||||
private void styleTerminalViewButton(Button button, boolean selected) {
|
||||
button.setTextColor(selected ? Color.rgb(14, 38, 24) : COLOR_TEXT_MUTED);
|
||||
button.setBackground(selected ? rounded(COLOR_ACCENT, 7, COLOR_ACCENT, 1) : buttonBackground());
|
||||
}
|
||||
|
||||
private HorizontalScrollView createTerminalGroupBar() {
|
||||
@@ -1986,12 +1984,12 @@ public final class MainActivity extends Activity {
|
||||
|
||||
LinearLayout bubble = new LinearLayout(this);
|
||||
bubble.setOrientation(LinearLayout.VERTICAL);
|
||||
bubble.setPadding(dp(12), dp(9), dp(12), dp(10));
|
||||
bubble.setPadding(user || tool ? dp(12) : dp(2), dp(9), user || tool ? dp(12) : dp(4), dp(10));
|
||||
bubble.setBackground(tool
|
||||
? rounded(COLOR_PANEL, 8, COLOR_BORDER, 1)
|
||||
: user
|
||||
? rounded(COLOR_ACCENT_DARK, 8, COLOR_ACCENT, 1)
|
||||
: rounded(COLOR_CARD, 8, COLOR_BORDER_SOFT, 1));
|
||||
: rounded(Color.TRANSPARENT, 0, Color.TRANSPARENT, 0));
|
||||
|
||||
TextView meta = new TextView(this);
|
||||
meta.setTextColor(user ? COLOR_ACCENT : tool ? COLOR_ACCENT_WARM : COLOR_TEXT_MUTED);
|
||||
@@ -1999,10 +1997,10 @@ public final class MainActivity extends Activity {
|
||||
meta.setTypeface(Typeface.MONOSPACE, Typeface.BOLD);
|
||||
meta.setSingleLine(true);
|
||||
meta.setEllipsize(TextUtils.TruncateAt.END);
|
||||
meta.setText(tool
|
||||
? conversationToolTitle(message)
|
||||
: (user ? "You" : "Assistant") + conversationStatusPart(message));
|
||||
bubble.addView(meta, matchWrap());
|
||||
meta.setText(tool ? conversationToolTitle(message) : conversationStatusPart(message).replaceFirst("^ · ", ""));
|
||||
if (tool || (!"complete".equals(message.status) && !message.status.isEmpty())) {
|
||||
bubble.addView(meta, matchWrap());
|
||||
}
|
||||
|
||||
boolean expanded = terminalExpandedMessages.contains(message.messageId);
|
||||
if (!tool || expanded) {
|
||||
@@ -2025,14 +2023,14 @@ public final class MainActivity extends Activity {
|
||||
LinearLayout.LayoutParams bubbleParams = new LinearLayout.LayoutParams(
|
||||
0,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||
tool ? 1f : 0.82f
|
||||
tool ? 1f : user ? 0.82f : 0.94f
|
||||
);
|
||||
if (!tool) {
|
||||
View spacer = new View(this);
|
||||
LinearLayout.LayoutParams spacerParams = new LinearLayout.LayoutParams(
|
||||
0,
|
||||
1,
|
||||
0.18f
|
||||
user ? 0.18f : 0.06f
|
||||
);
|
||||
if (user) {
|
||||
row.addView(spacer, spacerParams);
|
||||
@@ -2456,6 +2454,8 @@ public final class MainActivity extends Activity {
|
||||
|
||||
LinearLayout tabGrid = new LinearLayout(this);
|
||||
tabGrid.setOrientation(LinearLayout.VERTICAL);
|
||||
terminalComposerTabs = tabGrid;
|
||||
tabGrid.setVisibility(terminalViewMode == TERMINAL_VIEW_CHAT ? View.GONE : View.VISIBLE);
|
||||
LinearLayout firstTabRow = terminalKeyRow();
|
||||
LinearLayout secondTabRow = terminalKeyRow();
|
||||
addAccessoryTab(firstTabRow, "Edit", 0);
|
||||
@@ -2482,7 +2482,7 @@ public final class MainActivity extends Activity {
|
||||
inputField = new EditText(this);
|
||||
inputField.setTextColor(COLOR_TEXT);
|
||||
inputField.setHintTextColor(COLOR_TEXT_DIM);
|
||||
inputField.setHint("type command or text");
|
||||
inputField.setHint(terminalViewMode == TERMINAL_VIEW_CHAT ? "Message" : "type command or text");
|
||||
inputField.setSingleLine(false);
|
||||
inputField.setMinLines(3);
|
||||
inputField.setMaxLines(5);
|
||||
@@ -3607,19 +3607,8 @@ public final class MainActivity extends Activity {
|
||||
return;
|
||||
}
|
||||
lastTerminalRenderMs = System.currentTimeMillis();
|
||||
if (terminalViewMode == TERMINAL_VIEW_READING) {
|
||||
terminalText.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
terminalText.setHighlightColor(Color.TRANSPARENT);
|
||||
terminalText.setText(terminalScreen.renderFocused(terminalExpandedBlocks, key -> {
|
||||
if (!terminalExpandedBlocks.add(key)) {
|
||||
terminalExpandedBlocks.remove(key);
|
||||
}
|
||||
renderTerminalNow();
|
||||
}));
|
||||
} else {
|
||||
terminalText.setMovementMethod(null);
|
||||
terminalText.setText(terminalScreen.render());
|
||||
}
|
||||
terminalText.setMovementMethod(null);
|
||||
terminalText.setText(terminalScreen.render());
|
||||
updateTerminalLivePanel();
|
||||
if (terminalViewMode != TERMINAL_VIEW_CHAT && terminalFollowOutput) {
|
||||
terminalScroll.post(() -> terminalScroll.fullScroll(View.FOCUS_DOWN));
|
||||
|
||||
Reference in New Issue
Block a user