mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-08 03:24:04 +08:00
Fix old bug where termux app would crash if sessions list ListView was not notified of new sessions
To reproduce: 1. Create 2 sessions. 2. From either session, run a random `RUN_COMMAND` intent command with `am` command and shift to the other session. Termux app would crash and throw the `The content of the adapter has changed but ListView did not receive a notification.` exception. TermuxService was previously not notifying the ListView of the sessions list that a new session has been added, if the activity was in foreground.
This commit is contained in:
@@ -319,6 +319,11 @@ public final class TermuxService extends Service {
|
|||||||
TermuxAppSharedPreferences preferences = new TermuxAppSharedPreferences(this);
|
TermuxAppSharedPreferences preferences = new TermuxAppSharedPreferences(this);
|
||||||
preferences.setCurrentSession(newSession.mHandle);
|
preferences.setCurrentSession(newSession.mHandle);
|
||||||
|
|
||||||
|
// Notify {@link TermuxSessionsListViewController} that sessions list has been updated if
|
||||||
|
// activity in is foreground
|
||||||
|
if(mTermuxSessionClient != null)
|
||||||
|
mTermuxSessionClient.terminalSessionListNotifyUpdated();
|
||||||
|
|
||||||
// Launch the main Termux app, which will now show the current session:
|
// Launch the main Termux app, which will now show the current session:
|
||||||
startActivity(new Intent(this, TermuxActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
startActivity(new Intent(this, TermuxActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||||
}
|
}
|
||||||
|
@@ -68,7 +68,7 @@ public class TermuxSessionClient extends TermuxSessionClientBase {
|
|||||||
mActivity.showToast(toToastTitle(updatedSession), true);
|
mActivity.showToast(toToastTitle(updatedSession), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
mActivity.terminalSessionListNotifyUpdated();
|
terminalSessionListNotifyUpdated();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -101,7 +101,7 @@ public class TermuxSessionClient extends TermuxSessionClientBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mActivity.terminalSessionListNotifyUpdated();
|
terminalSessionListNotifyUpdated();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -152,7 +152,7 @@ public class TermuxSessionClient extends TermuxSessionClientBase {
|
|||||||
TerminalSession session = mActivity.getCurrentSession();
|
TerminalSession session = mActivity.getCurrentSession();
|
||||||
final int indexOfSession = mActivity.getTermuxService().getSessions().indexOf(session);
|
final int indexOfSession = mActivity.getTermuxService().getSessions().indexOf(session);
|
||||||
mActivity.showToast(toToastTitle(session), false);
|
mActivity.showToast(toToastTitle(session), false);
|
||||||
mActivity.terminalSessionListNotifyUpdated();
|
terminalSessionListNotifyUpdated();
|
||||||
|
|
||||||
final ListView termuxSessionsListView = mActivity.findViewById(R.id.terminal_sessions_list);
|
final ListView termuxSessionsListView = mActivity.findViewById(R.id.terminal_sessions_list);
|
||||||
termuxSessionsListView.setItemChecked(indexOfSession, true);
|
termuxSessionsListView.setItemChecked(indexOfSession, true);
|
||||||
@@ -178,7 +178,7 @@ public class TermuxSessionClient extends TermuxSessionClientBase {
|
|||||||
|
|
||||||
DialogUtils.textInput(mActivity, R.string.session_rename_title, sessionToRename.mSessionName, R.string.session_rename_positive_button, text -> {
|
DialogUtils.textInput(mActivity, R.string.session_rename_title, sessionToRename.mSessionName, R.string.session_rename_positive_button, text -> {
|
||||||
sessionToRename.mSessionName = text;
|
sessionToRename.mSessionName = text;
|
||||||
mActivity.terminalSessionListNotifyUpdated();
|
terminalSessionListNotifyUpdated();
|
||||||
}, -1, null, -1, null, null);
|
}, -1, null, -1, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -250,7 +250,7 @@ public class TermuxSessionClient extends TermuxSessionClientBase {
|
|||||||
TermuxService service = mActivity.getTermuxService();
|
TermuxService service = mActivity.getTermuxService();
|
||||||
|
|
||||||
int index = service.removeTerminalSession(finishedSession);
|
int index = service.removeTerminalSession(finishedSession);
|
||||||
mActivity.terminalSessionListNotifyUpdated();
|
terminalSessionListNotifyUpdated();
|
||||||
if (mActivity.getTermuxService().getSessions().isEmpty()) {
|
if (mActivity.getTermuxService().getSessions().isEmpty()) {
|
||||||
// There are no sessions to show, so finish the activity.
|
// There are no sessions to show, so finish the activity.
|
||||||
mActivity.finishActivityIfNotFinishing();
|
mActivity.finishActivityIfNotFinishing();
|
||||||
@@ -262,6 +262,10 @@ public class TermuxSessionClient extends TermuxSessionClientBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void terminalSessionListNotifyUpdated() {
|
||||||
|
mActivity.terminalSessionListNotifyUpdated();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
String toToastTitle(TerminalSession session) {
|
String toToastTitle(TerminalSession session) {
|
||||||
|
Reference in New Issue
Block a user