From c127ad172dffcead6a33bf0ecfaacb27c1716ec0 Mon Sep 17 00:00:00 2001 From: zt515 Date: Wed, 6 Dec 2017 23:58:40 +0800 Subject: [PATCH] Preference: make it beautiful --- .../neoterm/frontend/preference/NeoPreference.kt | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/neoterm/frontend/preference/NeoPreference.kt b/app/src/main/java/io/neoterm/frontend/preference/NeoPreference.kt index bce1caf..8472fbe 100644 --- a/app/src/main/java/io/neoterm/frontend/preference/NeoPreference.kt +++ b/app/src/main/java/io/neoterm/frontend/preference/NeoPreference.kt @@ -114,15 +114,11 @@ object NeoPreference { } fun getCurrentSession(termService: NeoTermService?): TerminalSession? { - val sessionHandle = PreferenceManager.getDefaultSharedPreferences(termService!!).getString(KEY_CURRENT_SESSION, "") - var i = 0 - val len = termService.sessions.size - while (i < len) { - val session = termService.sessions[i] - if (session.mHandle == sessionHandle) return session - i++ - } - return null + val sessionHandle = PreferenceManager.getDefaultSharedPreferences(termService!!) + .getString(KEY_CURRENT_SESSION, "") + + return termService.sessions + .singleOrNull { it.mHandle == sessionHandle } } fun setLoginShellName(loginProgramName: String?): Boolean {