From 6aee153630687791a4a5e767ac5a82fde57e74df Mon Sep 17 00:00:00 2001 From: DevKumar00001 Date: Mon, 9 Oct 2023 20:02:32 +0530 Subject: [PATCH] feat: Don't allow go back until the session is running --- .../ui/activities/TerminalActivity.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/android/code/editor/ui/activities/TerminalActivity.java b/app/src/main/java/android/code/editor/ui/activities/TerminalActivity.java index 2104738..96be5c8 100644 --- a/app/src/main/java/android/code/editor/ui/activities/TerminalActivity.java +++ b/app/src/main/java/android/code/editor/ui/activities/TerminalActivity.java @@ -27,6 +27,7 @@ import android.view.View; import android.view.Window; import android.view.WindowManager; +import androidx.annotation.MainThread; import com.blankj.utilcode.util.KeyboardUtils; import com.termux.terminal.TerminalEmulator; import com.termux.terminal.TerminalSession; @@ -38,6 +39,7 @@ public class TerminalActivity extends BaseActivity private ActivityTerminalBinding binding; private String cwd; + private TerminalSession session; @Override protected void onCreate(Bundle savedInstanceState) { @@ -59,14 +61,15 @@ protected void onCreate(Bundle savedInstanceState) { binding.terminalView.setTextSize(28); String[] env = {}; String[] argsList = {}; - binding.terminalView.attachSession( + session = new TerminalSession( "/system/bin/sh", cwd, env, argsList, TerminalEmulator.DEFAULT_TERMINAL_CURSOR_STYLE, - this)); + this); + binding.terminalView.attachSession(session); binding.terminalView.setTerminalViewClient(this); } @@ -106,6 +109,11 @@ public void copyModeChanged(boolean copyMode) {} @Override public boolean onKeyDown(int keyCode, KeyEvent e, TerminalSession session) { + if (!session.isRunning()) { + if (e.getKeyCode() == KeyEvent.KEYCODE_ENTER) { + finish(); + } + } return false; } @@ -180,4 +188,12 @@ public Integer getTerminalCursorStyle() { @Override public void onClipboardText(TerminalSession arg0, String arg1) {} + + @Override + @MainThread + public void onBackPressed() { + if (!session.isRunning()) { + super.onBackPressed(); + } + } }