Improve: Close tab
This commit is contained in:
@ -173,7 +173,7 @@ public final class BaseFileInstaller {
|
|||||||
|
|
||||||
private static HttpURLConnection openBaseFileConnection() throws IOException {
|
private static HttpURLConnection openBaseFileConnection() throws IOException {
|
||||||
String arch = determineArchName();
|
String arch = determineArchName();
|
||||||
String baseUrl = NeoTermPath.INSTANCE.getDEFAULT_SOURCE();
|
String baseUrl = NeoTermPath.RELEASE_SOURCE;
|
||||||
|
|
||||||
// Use the same source
|
// Use the same source
|
||||||
NeoPreference.INSTANCE.store(R.string.key_package_source, baseUrl);
|
NeoPreference.INSTANCE.store(R.string.key_package_source, baseUrl);
|
||||||
@ -181,12 +181,6 @@ public final class BaseFileInstaller {
|
|||||||
return (HttpURLConnection) new URL(baseUrl + "/boot/" + arch + ".zip").openConnection();
|
return (HttpURLConnection) new URL(baseUrl + "/boot/" + arch + ".zip").openConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
// private static URL determineZipUrl() throws MalformedURLException {
|
|
||||||
// String archName = determineArchName();
|
|
||||||
// String baseUrl = NeoTermPath.INSTANCE.getSERVER_BOOT_URL();
|
|
||||||
// return new URL(baseUrl + "/" + archName + ".zip");
|
|
||||||
// }
|
|
||||||
|
|
||||||
private static String determineArchName() {
|
private static String determineArchName() {
|
||||||
for (String androidArch : Build.SUPPORTED_ABIS) {
|
for (String androidArch : Build.SUPPORTED_ABIS) {
|
||||||
switch (androidArch) {
|
switch (androidArch) {
|
||||||
|
@ -137,7 +137,7 @@ object NLog {
|
|||||||
returnTag = sGlobalTag
|
returnTag = sGlobalTag
|
||||||
} else {
|
} else {
|
||||||
returnTag = "$sGlobalTag-$returnTag"
|
returnTag = "$sGlobalTag-$returnTag"
|
||||||
val targetElement = Throwable().stackTrace[3]
|
val targetElement = Thread.currentThread().stackTrace[3]
|
||||||
var className = targetElement.className
|
var className = targetElement.className
|
||||||
val classNameInfo = className.split("\\.".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
|
val classNameInfo = className.split("\\.".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
|
||||||
if (classNameInfo.isNotEmpty()) {
|
if (classNameInfo.isNotEmpty()) {
|
||||||
@ -151,13 +151,13 @@ object NLog {
|
|||||||
}
|
}
|
||||||
if (sLogHeadSwitch) {
|
if (sLogHeadSwitch) {
|
||||||
val head = Formatter()
|
val head = Formatter()
|
||||||
.format("%s, %s(%s:%d)",
|
.format("[Thread:%s], %s(%s:%d): ",
|
||||||
Thread.currentThread().name,
|
Thread.currentThread().name,
|
||||||
targetElement.methodName,
|
targetElement.methodName,
|
||||||
targetElement.fileName,
|
targetElement.fileName,
|
||||||
targetElement.lineNumber)
|
targetElement.lineNumber)
|
||||||
.toString()
|
.toString()
|
||||||
return arrayOf(returnTag, head + LINE_SEP, " [$head]: ")
|
return arrayOf(returnTag, head, head)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return arrayOf(returnTag, "", ": ")
|
return arrayOf(returnTag, "", ": ")
|
||||||
|
@ -179,23 +179,7 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection, SharedPreference
|
|||||||
|
|
||||||
override fun onTabRemoved(tabSwitcher: TabSwitcher, index: Int, tab: Tab, animation: Animation) {
|
override fun onTabRemoved(tabSwitcher: TabSwitcher, index: Int, tab: Tab, animation: Animation) {
|
||||||
if (tab is TermTab) {
|
if (tab is TermTab) {
|
||||||
Snackbar.make(tabSwitcher, R.string.session_closed, Snackbar.LENGTH_LONG)
|
closeTab(tab)
|
||||||
.setAction(R.string.restore_session, { _ ->
|
|
||||||
tabSwitcher.addTab(tab)
|
|
||||||
})
|
|
||||||
.addCallback(object : Snackbar.Callback() {
|
|
||||||
override fun onDismissed(transientBottomBar: Snackbar?, event: Int) {
|
|
||||||
super.onDismissed(transientBottomBar, event)
|
|
||||||
if (event == DISMISS_EVENT_SWIPE
|
|
||||||
|| event == DISMISS_EVENT_TIMEOUT
|
|
||||||
|| event == DISMISS_EVENT_CONSECUTIVE) {
|
|
||||||
tab.termData.termSession?.finishIfRunning()
|
|
||||||
removeFinishedSession(tab.termData.termSession)
|
|
||||||
tab.cleanup()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.show()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -227,6 +211,7 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection, SharedPreference
|
|||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
PreferenceManager.getDefaultSharedPreferences(this)
|
PreferenceManager.getDefaultSharedPreferences(this)
|
||||||
.unregisterOnSharedPreferenceChangeListener(this)
|
.unregisterOnSharedPreferenceChangeListener(this)
|
||||||
|
|
||||||
if (termService != null) {
|
if (termService != null) {
|
||||||
if (termService!!.sessions.isEmpty()) {
|
if (termService!!.sessions.isEmpty()) {
|
||||||
termService!!.stopSelf()
|
termService!!.stopSelf()
|
||||||
@ -523,6 +508,12 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection, SharedPreference
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun closeTab(tab: TermTab) {
|
||||||
|
SessionRemover.removeSession(tab)
|
||||||
|
removeFinishedSession(tab.termData.termSession)
|
||||||
|
Snackbar.make(tabSwitcher, R.string.session_closed, Snackbar.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
|
||||||
private fun toggleSwitcher(showSwitcher: Boolean, easterEgg: Boolean) {
|
private fun toggleSwitcher(showSwitcher: Boolean, easterEgg: Boolean) {
|
||||||
if (tabSwitcher.count > 0) {
|
if (tabSwitcher.count > 0) {
|
||||||
if (showSwitcher) {
|
if (showSwitcher) {
|
||||||
@ -606,5 +597,4 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection, SharedPreference
|
|||||||
toolbar.title = titleChangedEvent.title
|
toolbar.title = titleChangedEvent.title
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
13
app/src/main/java/io/neoterm/ui/term/SessionRemover.kt
Normal file
13
app/src/main/java/io/neoterm/ui/term/SessionRemover.kt
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package io.neoterm.ui.term
|
||||||
|
|
||||||
|
import io.neoterm.ui.term.tab.TermTab
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author kiva
|
||||||
|
*/
|
||||||
|
object SessionRemover {
|
||||||
|
fun removeSession(tab: TermTab) {
|
||||||
|
tab.termData.termSession?.finishIfRunning()
|
||||||
|
tab.cleanup()
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user