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