Skip to content

Commit

Permalink
Rename termux terminal view and session client classes
Browse files Browse the repository at this point in the history
- com.termux.app.terminal.TermuxViewClient has been renamed to TermuxTerminalViewClient
- com.termux.app.terminal.TermuxSessionClient has been renamed to TermuxTerminalSessionClient
- com.termux.shared.shell.TermuxSessionClientBase has been renamed to TermuxTerminalSessionClientBase

This was required because com.termux.app.terminal.TermuxSessionClient was in conflict with com.termux.shared.shell.TermuxSessionClient interface of com.termux.shared.shell.TermuxSession.
  • Loading branch information
agnostic-apollo committed Apr 12, 2021
1 parent a95e187 commit 824b3e6
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 84 deletions.
50 changes: 25 additions & 25 deletions app/src/main/java/com/termux/app/TermuxActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
import com.termux.shared.settings.preferences.TermuxAppSharedPreferences;
import com.termux.app.terminal.TermuxSessionsListViewController;
import com.termux.app.terminal.io.TerminalToolbarViewPager;
import com.termux.app.terminal.TermuxSessionClient;
import com.termux.app.terminal.TermuxViewClient;
import com.termux.app.terminal.TermuxTerminalSessionClient;
import com.termux.app.terminal.TermuxTerminalViewClient;
import com.termux.app.terminal.io.extrakeys.ExtraKeysView;
import com.termux.app.settings.properties.TermuxAppSharedProperties;
import com.termux.shared.interact.DialogUtils;
Expand Down Expand Up @@ -86,13 +86,13 @@ public final class TermuxActivity extends Activity implements ServiceConnection
* The {@link TerminalViewClient} interface implementation to allow for communication between
* {@link TerminalView} and {@link TermuxActivity}.
*/
TermuxViewClient mTermuxViewClient;
TermuxTerminalViewClient mTermuxTerminalViewClient;

/**
* The {@link TerminalSessionClient} interface implementation to allow for communication between
* {@link TerminalSession} and {@link TermuxActivity}.
*/
TermuxSessionClient mTermuxSessionClient;
TermuxTerminalSessionClient mTermuxTerminalSessionClient;

/**
* Termux app shared preferences manager.
Expand Down Expand Up @@ -218,7 +218,7 @@ public void onStart() {
// The service has connected, but data may have changed since we were last in the foreground.
// Get the session stored in shared preferences stored by {@link #onStop} if its valid,
// otherwise get the last session currently running.
mTermuxSessionClient.setCurrentSession(mTermuxSessionClient.getCurrentStoredSessionOrLast());
mTermuxTerminalSessionClient.setCurrentSession(mTermuxTerminalSessionClient.getCurrentStoredSessionOrLast());
termuxSessionListNotifyUpdated();
}

Expand Down Expand Up @@ -264,7 +264,7 @@ public void onServiceConnected(ComponentName componentName, IBinder service) {
if (bundle != null) {
launchFailsafe = bundle.getBoolean(TERMUX_ACTIVITY.ACTION_FAILSAFE_SESSION, false);
}
mTermuxSessionClient.addNewSession(launchFailsafe, null);
mTermuxTerminalSessionClient.addNewSession(launchFailsafe, null);
} catch (WindowManager.BadTokenException e) {
// Activity finished - ignore.
}
Expand All @@ -278,14 +278,14 @@ public void onServiceConnected(ComponentName componentName, IBinder service) {
if (i != null && Intent.ACTION_RUN.equals(i.getAction())) {
// Android 7.1 app shortcut from res/xml/shortcuts.xml.
boolean isFailSafe = i.getBooleanExtra(TERMUX_ACTIVITY.ACTION_FAILSAFE_SESSION, false);
mTermuxSessionClient.addNewSession(isFailSafe, null);
mTermuxTerminalSessionClient.addNewSession(isFailSafe, null);
} else {
mTermuxSessionClient.setCurrentSession(mTermuxSessionClient.getCurrentStoredSessionOrLast());
mTermuxTerminalSessionClient.setCurrentSession(mTermuxTerminalSessionClient.getCurrentStoredSessionOrLast());
}
}

// Update the {@link TerminalSession} and {@link TerminalEmulator} clients.
mTermuxService.setTermuxSessionClient(mTermuxSessionClient);
mTermuxService.setTermuxTerminalSessionClient(mTermuxTerminalSessionClient);
}

@Override
Expand All @@ -307,7 +307,7 @@ protected void onStop() {

// Store current session in shared preferences so that it can be restored later in
// {@link #onStart} if needed.
mTermuxSessionClient.setCurrentStoredSession();
mTermuxTerminalSessionClient.setCurrentStoredSession();

unregisterReceiver(mTermuxActivityBroadcastReceiever);
getDrawer().closeDrawers();
Expand All @@ -321,7 +321,7 @@ public void onDestroy() {

if (mTermuxService != null) {
// Do not leave service and session clients with references to activity.
mTermuxService.unsetTermuxSessionClient();
mTermuxService.unsetTermuxTerminalSessionClient();
mTermuxService = null;
}
unbindService(this);
Expand Down Expand Up @@ -406,11 +406,11 @@ private void saveTerminalToolbarTextInput(Bundle savedInstanceState) {

private void setNewSessionButtonView() {
View newSessionButton = findViewById(R.id.new_session_button);
newSessionButton.setOnClickListener(v -> mTermuxSessionClient.addNewSession(false, null));
newSessionButton.setOnClickListener(v -> mTermuxTerminalSessionClient.addNewSession(false, null));
newSessionButton.setOnLongClickListener(v -> {
DialogUtils.textInput(TermuxActivity.this, R.string.title_create_named_session, null,
R.string.action_create_named_session_confirm, text -> mTermuxSessionClient.addNewSession(false, text),
R.string.action_new_session_failsafe, text -> mTermuxSessionClient.addNewSession(true, text),
R.string.action_create_named_session_confirm, text -> mTermuxTerminalSessionClient.addNewSession(false, text),
R.string.action_new_session_failsafe, text -> mTermuxTerminalSessionClient.addNewSession(true, text),
-1, null, null);
return true;
});
Expand Down Expand Up @@ -447,12 +447,12 @@ private void setSoftKeyboardState() {

private void setTermuxTerminalViewAndClients() {
// Set termux terminal view and session clients
mTermuxSessionClient = new TermuxSessionClient(this);
mTermuxViewClient = new TermuxViewClient(this, mTermuxSessionClient);
mTermuxTerminalSessionClient = new TermuxTerminalSessionClient(this);
mTermuxTerminalViewClient = new TermuxTerminalViewClient(this, mTermuxTerminalSessionClient);

// Set termux terminal view
mTerminalView = findViewById(R.id.terminal_view);
mTerminalView.setTerminalViewClient(mTermuxViewClient);
mTerminalView.setTerminalViewClient(mTermuxTerminalViewClient);

mTerminalView.setTextSize(mPreferences.getFontSize());
mTerminalView.setKeepScreenOn(mPreferences.getKeepScreenOn());
Expand All @@ -462,7 +462,7 @@ private void setTermuxTerminalViewAndClients() {

mTerminalView.requestFocus();

mTermuxSessionClient.checkForFontAndColors();
mTermuxTerminalSessionClient.checkForFontAndColors();
}

private void setTermuxSessionsListView() {
Expand Down Expand Up @@ -543,10 +543,10 @@ public boolean onContextItemSelected(MenuItem item) {

switch (item.getItemId()) {
case CONTEXT_MENU_SELECT_URL_ID:
mTermuxViewClient.showUrlSelection();
mTermuxTerminalViewClient.showUrlSelection();
return true;
case CONTEXT_MENU_SHARE_TRANSCRIPT_ID:
mTermuxViewClient.shareSessionTranscript();
mTermuxTerminalViewClient.shareSessionTranscript();
return true;
case CONTEXT_MENU_AUTOFILL_ID:
requestAutoFill();
Expand All @@ -570,7 +570,7 @@ public boolean onContextItemSelected(MenuItem item) {
startActivity(new Intent(this, SettingsActivity.class));
return true;
case CONTEXT_MENU_REPORT_ID:
mTermuxViewClient.reportIssueFromTranscript();
mTermuxTerminalViewClient.reportIssueFromTranscript();
return true;
default:
return super.onContextItemSelected(item);
Expand Down Expand Up @@ -690,8 +690,8 @@ public TerminalView getTerminalView() {
return mTerminalView;
}

public TermuxSessionClient getTermuxSessionClient() {
return mTermuxSessionClient;
public TermuxTerminalSessionClient getTermuxTerminalSessionClient() {
return mTermuxTerminalSessionClient;
}

@Nullable
Expand Down Expand Up @@ -732,8 +732,8 @@ public void onReceive(Context context, Intent intent) {
return;
}

if(mTermuxSessionClient!= null) {
mTermuxSessionClient.checkForFontAndColors();
if(mTermuxTerminalSessionClient != null) {
mTermuxTerminalSessionClient.checkForFontAndColors();
}

if(mProperties!= null) {
Expand Down
70 changes: 35 additions & 35 deletions app/src/main/java/com/termux/app/TermuxService.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
import android.widget.ArrayAdapter;

import com.termux.R;
import com.termux.app.terminal.TermuxSessionClient;
import com.termux.app.terminal.TermuxTerminalSessionClient;
import com.termux.app.utils.PluginUtils;
import com.termux.shared.termux.TermuxConstants;
import com.termux.shared.termux.TermuxConstants.TERMUX_APP.TERMUX_ACTIVITY;
import com.termux.shared.termux.TermuxConstants.TERMUX_APP.TERMUX_SERVICE;
import com.termux.shared.settings.preferences.TermuxAppSharedPreferences;
import com.termux.shared.shell.TermuxSession;
import com.termux.shared.shell.TermuxSessionClientBase;
import com.termux.shared.shell.TermuxTerminalSessionClientBase;
import com.termux.shared.logger.Logger;
import com.termux.shared.notification.NotificationUtils;
import com.termux.shared.packages.PermissionUtils;
Expand Down Expand Up @@ -92,12 +92,12 @@ class LocalBinder extends Binder {
* that holds activity references for activity related functions.
* Note that the service may often outlive the activity, so need to clear this reference.
*/
com.termux.app.terminal.TermuxSessionClient mTermuxSessionClient;
TermuxTerminalSessionClient mTermuxTerminalSessionClient;

/** The basic implementation of the {@link TerminalSessionClient} interface to be used by {@link TerminalSession}
* that does not hold activity references.
*/
final TermuxSessionClientBase mTermuxSessionClientBase = new TermuxSessionClientBase();
final TermuxTerminalSessionClientBase mTermuxTerminalSessionClientBase = new TermuxTerminalSessionClientBase();

/** The wake lock and wifi lock are always acquired and released together. */
private PowerManager.WakeLock mWakeLock;
Expand Down Expand Up @@ -178,8 +178,8 @@ public boolean onUnbind(Intent intent) {
// Since we cannot rely on {@link TermuxActivity.onDestroy()} to always complete,
// we unset clients here as well if it failed, so that we do not leave service and session
// clients with references to the activity.
if (mTermuxSessionClient != null)
unsetTermuxSessionClient();
if (mTermuxTerminalSessionClient != null)
unsetTermuxTerminalSessionClient();
return false;
}

Expand Down Expand Up @@ -476,7 +476,7 @@ private void executeTermuxSessionCommand(ExecutionCommand executionCommand) {

/**
* Create a {@link TermuxSession}.
* Currently called by {@link TermuxSessionClient#addNewSession(boolean, String)} to add a new {@link TermuxSession}.
* Currently called by {@link TermuxTerminalSessionClient#addNewSession(boolean, String)} to add a new {@link TermuxSession}.
*/
@Nullable
public TermuxSession createTermuxSession(String executablePath, String[] arguments, String workingDirectory, boolean isFailSafe, String sessionName) {
Expand All @@ -501,7 +501,7 @@ public synchronized TermuxSession createTermuxSession(ExecutionCommand execution
// If the execution command was started for a plugin, only then will the stdout be set
// Otherwise if command was manually started by the user like by adding a new terminal session,
// then no need to set stdout
TermuxSession newTermuxSession = TermuxSession.execute(this, executionCommand, getTermuxSessionClient(), this, sessionName, executionCommand.isPluginExecutionCommand);
TermuxSession newTermuxSession = TermuxSession.execute(this, executionCommand, getTermuxTerminalSessionClient(), this, sessionName, executionCommand.isPluginExecutionCommand);
if (newTermuxSession == null) {
Logger.logError(LOG_TAG, "Failed to execute new TermuxSession command for:\n" + executionCommand.getCommandIdAndLabelLogString());
return null;
Expand All @@ -516,8 +516,8 @@ public synchronized TermuxSession createTermuxSession(ExecutionCommand execution

// Notify {@link TermuxSessionsListViewController} that sessions list has been updated if
// activity in is foreground
if (mTermuxSessionClient != null)
mTermuxSessionClient.termuxSessionListNotifyUpdated();
if (mTermuxTerminalSessionClient != null)
mTermuxTerminalSessionClient.termuxSessionListNotifyUpdated();

updateNotification();
TermuxActivity.updateTermuxActivityStyling(this);
Expand Down Expand Up @@ -551,8 +551,8 @@ public void onTermuxSessionExited(final TermuxSession termuxSession) {

// Notify {@link TermuxSessionsListViewController} that sessions list has been updated if
// activity in is foreground
if (mTermuxSessionClient != null)
mTermuxSessionClient.termuxSessionListNotifyUpdated();
if (mTermuxTerminalSessionClient != null)
mTermuxTerminalSessionClient.termuxSessionListNotifyUpdated();
}

updateNotification();
Expand All @@ -569,8 +569,8 @@ private void handleSessionAction(int sessionAction, TerminalSession newTerminalS
switch (sessionAction) {
case TERMUX_SERVICE.VALUE_EXTRA_SESSION_ACTION_SWITCH_TO_NEW_SESSION_AND_OPEN_ACTIVITY:
setCurrentStoredTerminalSession(newTerminalSession);
if (mTermuxSessionClient != null)
mTermuxSessionClient.setCurrentSession(newTerminalSession);
if (mTermuxTerminalSessionClient != null)
mTermuxTerminalSessionClient.setCurrentSession(newTerminalSession);
startTermuxActivity();
break;
case TERMUX_SERVICE.VALUE_EXTRA_SESSION_ACTION_KEEP_CURRENT_SESSION_AND_OPEN_ACTIVITY:
Expand All @@ -580,8 +580,8 @@ private void handleSessionAction(int sessionAction, TerminalSession newTerminalS
break;
case TERMUX_SERVICE.VALUE_EXTRA_SESSION_ACTION_SWITCH_TO_NEW_SESSION_AND_DONT_OPEN_ACTIVITY:
setCurrentStoredTerminalSession(newTerminalSession);
if (mTermuxSessionClient != null)
mTermuxSessionClient.setCurrentSession(newTerminalSession);
if (mTermuxTerminalSessionClient != null)
mTermuxTerminalSessionClient.setCurrentSession(newTerminalSession);
break;
case TERMUX_SERVICE.VALUE_EXTRA_SESSION_ACTION_KEEP_CURRENT_SESSION_AND_DONT_OPEN_ACTIVITY:
if (getTermuxSessionsSize() == 1)
Expand Down Expand Up @@ -610,46 +610,46 @@ private void startTermuxActivity() {

/** If {@link TermuxActivity} has not bound to the {@link TermuxService} yet or is destroyed, then
* interface functions requiring the activity should not be available to the terminal sessions,
* so we just return the {@link #mTermuxSessionClientBase}. Once {@link TermuxActivity} bind
* callback is received, it should call {@link #setTermuxSessionClient} to set the
* {@link TermuxService#mTermuxSessionClient} so that further terminal sessions are directly
* passed the {@link TermuxSessionClient} object which fully implements the
* so we just return the {@link #mTermuxTerminalSessionClientBase}. Once {@link TermuxActivity} bind
* callback is received, it should call {@link #setTermuxTerminalSessionClient} to set the
* {@link TermuxService#mTermuxTerminalSessionClient} so that further terminal sessions are directly
* passed the {@link TermuxTerminalSessionClient} object which fully implements the
* {@link TerminalSessionClient} interface.
*
* @return Returns the {@link TermuxSessionClient} if {@link TermuxActivity} has bound with
* {@link TermuxService}, otherwise {@link TermuxSessionClientBase}.
* @return Returns the {@link TermuxTerminalSessionClient} if {@link TermuxActivity} has bound with
* {@link TermuxService}, otherwise {@link TermuxTerminalSessionClientBase}.
*/
public synchronized TermuxSessionClientBase getTermuxSessionClient() {
if (mTermuxSessionClient != null)
return mTermuxSessionClient;
public synchronized TermuxTerminalSessionClientBase getTermuxTerminalSessionClient() {
if (mTermuxTerminalSessionClient != null)
return mTermuxTerminalSessionClient;
else
return mTermuxSessionClientBase;
return mTermuxTerminalSessionClientBase;
}

/** This should be called when {@link TermuxActivity#onServiceConnected} is called to set the
* {@link TermuxService#mTermuxSessionClient} variable and update the {@link TerminalSession}
* and {@link TerminalEmulator} clients in case they were passed {@link TermuxSessionClientBase}
* {@link TermuxService#mTermuxTerminalSessionClient} variable and update the {@link TerminalSession}
* and {@link TerminalEmulator} clients in case they were passed {@link TermuxTerminalSessionClientBase}
* earlier.
*
* @param termuxSessionClient The {@link TermuxSessionClient} object that fully
* @param termuxTerminalSessionClient The {@link TermuxTerminalSessionClient} object that fully
* implements the {@link TerminalSessionClient} interface.
*/
public synchronized void setTermuxSessionClient(TermuxSessionClient termuxSessionClient) {
mTermuxSessionClient = termuxSessionClient;
public synchronized void setTermuxTerminalSessionClient(TermuxTerminalSessionClient termuxTerminalSessionClient) {
mTermuxTerminalSessionClient = termuxTerminalSessionClient;

for (int i = 0; i < mTermuxSessions.size(); i++)
mTermuxSessions.get(i).getTerminalSession().updateTerminalSessionClient(mTermuxSessionClient);
mTermuxSessions.get(i).getTerminalSession().updateTerminalSessionClient(mTermuxTerminalSessionClient);
}

/** This should be called when {@link TermuxActivity} has been destroyed and in {@link #onUnbind(Intent)}
* so that the {@link TermuxService} and {@link TerminalSession} and {@link TerminalEmulator}
* clients do not hold an activity references.
*/
public synchronized void unsetTermuxSessionClient() {
public synchronized void unsetTermuxTerminalSessionClient() {
for (int i = 0; i < mTermuxSessions.size(); i++)
mTermuxSessions.get(i).getTerminalSession().updateTerminalSessionClient(mTermuxSessionClientBase);
mTermuxSessions.get(i).getTerminalSession().updateTerminalSessionClient(mTermuxTerminalSessionClientBase);

mTermuxSessionClient = null;
mTermuxTerminalSessionClient = null;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ public View getView(int position, View convertView, @NonNull ViewGroup parent) {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
TermuxSession clickedSession = getItem(position);
mActivity.getTermuxSessionClient().setCurrentSession(clickedSession.getTerminalSession());
mActivity.getTermuxTerminalSessionClient().setCurrentSession(clickedSession.getTerminalSession());
mActivity.getDrawer().closeDrawers();
}

@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
final TermuxSession selectedSession = getItem(position);
mActivity.getTermuxSessionClient().renameSession(selectedSession.getTerminalSession());
mActivity.getTermuxTerminalSessionClient().renameSession(selectedSession.getTerminalSession());
return true;
}

Expand Down
Loading

0 comments on commit 824b3e6

Please sign in to comment.