UI: Create XTab

This commit is contained in:
zt515 2017-11-23 23:56:52 +08:00
parent 773ee214fe
commit 2033accbee
6 changed files with 38 additions and 14 deletions

View File

@ -1,7 +1,6 @@
package io.neoterm.frontend.preference package io.neoterm.frontend.preference
import android.annotation.SuppressLint import android.annotation.SuppressLint
import io.neoterm.BuildConfig
/** /**
* @author kiva * @author kiva
@ -24,15 +23,14 @@ object NeoTermPath {
const val SOURCE_FILE = "$USR_PATH/etc/apt/sources.list" const val SOURCE_FILE = "$USR_PATH/etc/apt/sources.list"
const val PACKAGE_LIST_DIR = "$USR_PATH/var/lib/apt/lists" const val PACKAGE_LIST_DIR = "$USR_PATH/var/lib/apt/lists"
const val RELEASE_SOURCE = "https://mirrors.geekpie.org/neoterm" const val SOURCE = "http://neoterm.studio"
const val DEBUG_SOURCE = "http://neoterm.studio"
val DEFAULT_SOURCE: String val DEFAULT_SOURCE: String
val SERVER_BASE_URL: String val SERVER_BASE_URL: String
val SERVER_BOOT_URL: String val SERVER_BOOT_URL: String
init { init {
DEFAULT_SOURCE = DEBUG_SOURCE DEFAULT_SOURCE = SOURCE
SERVER_BASE_URL = DEFAULT_SOURCE SERVER_BASE_URL = DEFAULT_SOURCE
SERVER_BOOT_URL = "$SERVER_BASE_URL/boot" SERVER_BOOT_URL = "$SERVER_BASE_URL/boot"
} }

View File

@ -1,7 +1,11 @@
package io.neoterm.frontend.xorg package io.neoterm.frontend.xorg
import io.neoterm.backend.TerminalSession
/** /**
* @author kiva * @author kiva
*/ */
class XSession class XSession {
}

View File

@ -1,6 +1,5 @@
package io.neoterm.ui.term package io.neoterm.ui.term
import android.annotation.SuppressLint
import android.app.Activity import android.app.Activity
import android.app.AlertDialog import android.app.AlertDialog
import android.content.* import android.content.*
@ -17,7 +16,6 @@ import android.support.v7.widget.Toolbar
import android.view.* import android.view.*
import android.view.inputmethod.InputMethodManager import android.view.inputmethod.InputMethodManager
import android.widget.ImageButton import android.widget.ImageButton
import android.widget.Toast
import de.mrapp.android.tabswitcher.* import de.mrapp.android.tabswitcher.*
import io.neoterm.App import io.neoterm.App
import io.neoterm.R import io.neoterm.R
@ -30,12 +28,12 @@ import io.neoterm.frontend.preference.NeoPermission
import io.neoterm.frontend.preference.NeoPreference import io.neoterm.frontend.preference.NeoPreference
import io.neoterm.frontend.shell.ShellParameter import io.neoterm.frontend.shell.ShellParameter
import io.neoterm.services.NeoTermService import io.neoterm.services.NeoTermService
import io.neoterm.ui.bonus.BonusActivity
import io.neoterm.ui.pm.PackageManagerActivity import io.neoterm.ui.pm.PackageManagerActivity
import io.neoterm.ui.settings.SettingActivity import io.neoterm.ui.settings.SettingActivity
import io.neoterm.ui.setup.SetupActivity import io.neoterm.ui.setup.SetupActivity
import io.neoterm.ui.term.tab.TermTab import io.neoterm.ui.term.tab.TermTab
import io.neoterm.ui.term.tab.TermTabDecorator import io.neoterm.ui.term.tab.TermTabDecorator
import io.neoterm.ui.term.tab.XSessionTab
import io.neoterm.utils.FullScreenHelper import io.neoterm.utils.FullScreenHelper
import io.neoterm.utils.RangedInt import io.neoterm.utils.RangedInt
import org.greenrobot.eventbus.EventBus import org.greenrobot.eventbus.EventBus
@ -154,6 +152,10 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection, SharedPreference
forceAddSystemSession() forceAddSystemSession()
true true
} }
R.id.menu_item_new_x_session -> {
addXSession();
true
}
else -> super.onOptionsItemSelected(item) else -> super.onOptionsItemSelected(item)
} }
} }
@ -434,7 +436,7 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection, SharedPreference
.systemShell(systemShell) .systemShell(systemShell)
val session = termService!!.createTermSession(parameter) val session = termService!!.createTermSession(parameter)
session.mSessionName = sessionName ?: "NeoTerm #${termService!!.sessions.size}" session.mSessionName = sessionName ?: generateSessionName("NeoTerm")
val tab = createTab(session.mSessionName) as TermTab val tab = createTab(session.mSessionName) as TermTab
tab.termData.initializeSessionWith(session, sessionCallback, viewClient) tab.termData.initializeSessionWith(session, sessionCallback, viewClient)
@ -443,6 +445,14 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection, SharedPreference
switchToSession(tab) switchToSession(tab)
} }
private fun addXSession() {
}
private fun generateSessionName(prefix: String): String {
return "$prefix #${termService!!.sessions.size}"
}
private fun switchToSession(session: TerminalSession?) { private fun switchToSession(session: TerminalSession?) {
if (session == null) { if (session == null) {
return return
@ -483,9 +493,14 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection, SharedPreference
} }
private fun createTab(tabTitle: String?): Tab { private fun createTab(tabTitle: String?): Tab {
val tab = TermTab(tabTitle ?: "NeoTerm") return postTabCreated(TermTab(tabTitle ?: "NeoTerm"))
tab.isCloseable = true }
private fun createXTab(tabTitle: String?): Tab {
return postTabCreated(XSessionTab(tabTitle ?: "NeoTerm"))
}
private fun <T : Tab> postTabCreated(tab: T) : T {
// We must create a Bundle for each tab // We must create a Bundle for each tab
// tabs can use them to store status. // tabs can use them to store status.
tab.parameters = Bundle() tab.parameters = Bundle()

View File

@ -5,4 +5,6 @@ import de.mrapp.android.tabswitcher.Tab
/** /**
* @author kiva * @author kiva
*/ */
class XSessionTab(title: CharSequence) : Tab(title) {} class XSessionTab(title: CharSequence) : Tab(title) {
}

View File

@ -17,6 +17,12 @@
android:id="@+id/menu_item_new_system_session" android:id="@+id/menu_item_new_system_session"
android:title="@string/new_system_session" android:title="@string/new_system_session"
app:showAsAction="never" /> app:showAsAction="never" />
<item
android:id="@+id/menu_item_new_x_session"
android:title="@string/new_x_session"
app:showAsAction="never" />
<item <item
android:id="@+id/menu_item_package_settings" android:id="@+id/menu_item_package_settings"
android:title="@string/package_settings" android:title="@string/package_settings"

View File

@ -136,6 +136,7 @@
<string name="select_new_value">Select</string> <string name="select_new_value">Select</string>
<string name="input_new_value">Enter new color</string> <string name="input_new_value">Enter new color</string>
<string name="toggle_eks">Toggle extra keys</string> <string name="toggle_eks">Toggle extra keys</string>
<string name="new_x_session">New X Session</string>
<string-array name="pref_general_shell_entries" translatable="false"> <string-array name="pref_general_shell_entries" translatable="false">
<item>sh</item> <item>sh</item>
@ -145,12 +146,10 @@
</string-array> </string-array>
<string-array name="pref_package_source_entries" translatable="false"> <string-array name="pref_package_source_entries" translatable="false">
<item>mirrors.geekpie.org</item>
<item>neoterm.studio</item> <item>neoterm.studio</item>
</string-array> </string-array>
<string-array name="pref_package_source_values" translatable="false"> <string-array name="pref_package_source_values" translatable="false">
<item>https://mirrors.geekpie.org/neoterm</item>
<item>http://neoterm.studio</item> <item>http://neoterm.studio</item>
</string-array> </string-array>