Preference: improve code readability

This commit is contained in:
zt515 2017-12-10 23:32:00 +08:00
parent ac3b942d36
commit cc01509067
5 changed files with 51 additions and 50 deletions

View File

@ -7,7 +7,7 @@ import io.neoterm.R
import io.neoterm.frontend.config.NeoPreference
import io.neoterm.frontend.config.NeoTermPath
import io.neoterm.frontend.component.NeoComponent
import io.neoterm.frontend.config.DefaultPreference
import io.neoterm.frontend.config.DefaultValues
import io.neoterm.frontend.terminal.TerminalView
import io.neoterm.frontend.terminal.eks.ExtraKeysView
import io.neoterm.utils.AssetsUtils
@ -33,7 +33,7 @@ class FontComponent : NeoComponent {
}
fun getCurrentFontName(): String {
val defaultFont = DefaultPreference.defaultFont
val defaultFont = DefaultValues.defaultFont
var currentFontName = NeoPreference.loadString(R.string.key_customization_font, defaultFont)
if (!fonts.containsKey(currentFontName)) {
currentFontName = defaultFont
@ -64,7 +64,7 @@ class FontComponent : NeoComponent {
fonts.put(fontName, font)
}
val defaultFont = DefaultPreference.defaultFont
val defaultFont = DefaultValues.defaultFont
if (fonts.containsKey(defaultFont)) {
DEFAULT_FONT = fonts[defaultFont]!!
return true
@ -84,7 +84,7 @@ class FontComponent : NeoComponent {
}
private fun loadDefaultFontFromAsset(context: Context): NeoFont {
val defaultFont = DefaultPreference.defaultFont
val defaultFont = DefaultValues.defaultFont
return NeoFont(Typeface.createFromAsset(context.assets, "fonts/$defaultFont.ttf"))
}
@ -110,7 +110,7 @@ class FontComponent : NeoComponent {
fonts = mutableMapOf()
val context = App.get()
val defaultFont = DefaultPreference.defaultFont
val defaultFont = DefaultValues.defaultFont
val defaultFontFile = fontFile(defaultFont)
if (!defaultFontFile.exists()) {

View File

@ -5,7 +5,7 @@ import io.neoterm.component.color.DefaultColorScheme
/**
* @author kiva
*/
object DefaultPreference {
object DefaultValues {
const val fontSize = 30
const val enableBell = false

View File

@ -134,17 +134,17 @@ object NeoPreference {
}
fun getLoginShellName(): String {
return loadString(R.string.key_general_shell, DefaultPreference.loginShell)
return loadString(R.string.key_general_shell, DefaultValues.loginShell)
}
fun getLoginShellPath(): String {
val loginProgramName = getLoginShellName()
// Some programs like ssh needs it
val shell = File(NeoTermPath.NEOTERM_SHELL_PATH)
val shell = File(NeoTermPath.NEOTERM_LOGIN_SHELL_PATH)
val loginProgramPath = findLoginProgram(loginProgramName) ?: {
setLoginShellName(DefaultPreference.loginShell)
"${NeoTermPath.USR_PATH}/bin/${DefaultPreference.loginShell}"
setLoginShellName(DefaultValues.loginShell)
"${NeoTermPath.USR_PATH}/bin/${DefaultValues.loginShell}"
}()
if (!shell.exists()) {
@ -161,12 +161,12 @@ object NeoPreference {
private fun symlinkLoginShell(loginProgramPath: String) {
File(NeoTermPath.CUSTOM_PATH).mkdirs()
try {
val shellSymlink = File(NeoTermPath.NEOTERM_SHELL_PATH)
val shellSymlink = File(NeoTermPath.NEOTERM_LOGIN_SHELL_PATH)
if (shellSymlink.exists()) {
shellSymlink.delete()
}
Os.symlink(loginProgramPath, NeoTermPath.NEOTERM_SHELL_PATH)
Os.chmod(NeoTermPath.NEOTERM_SHELL_PATH, 448 /* Decimal of 0700 */)
Os.symlink(loginProgramPath, NeoTermPath.NEOTERM_LOGIN_SHELL_PATH)
Os.chmod(NeoTermPath.NEOTERM_LOGIN_SHELL_PATH, 448 /* Decimal of 0700 */)
} catch (e: ErrnoException) {
NLog.e("Preference", "Failed to symlink login shell: ${e.localizedMessage}")
e.printStackTrace()
@ -180,67 +180,67 @@ object NeoPreference {
fun getFontSize(): Int {
return loadInt(KEY_FONT_SIZE,
DefaultPreference.fontSize)
DefaultValues.fontSize)
}
fun getInitialCommand(): String {
return loadString(R.string.key_general_initial_command,
DefaultPreference.initialCommand)
DefaultValues.initialCommand)
}
fun isBellEnabled(): Boolean {
return loadBoolean(R.string.key_general_bell,
DefaultPreference.enableBell)
DefaultValues.enableBell)
}
fun isVibrateEnabled(): Boolean {
return loadBoolean(R.string.key_general_vibrate,
DefaultPreference.enableVibrate)
DefaultValues.enableVibrate)
}
fun isExecveWrapperEnabled() : Boolean {
return loadBoolean(R.string.key_general_use_execve_wrapper,
DefaultPreference.enableExecveWrapper)
DefaultValues.enableExecveWrapper)
}
fun isSpecialVolumeKeysEnabled() : Boolean {
return loadBoolean(R.string.key_general_volume_as_control,
DefaultPreference.enableSpecialVolumeKeys)
DefaultValues.enableSpecialVolumeKeys)
}
fun isAutoCompletionEnabled() : Boolean {
return loadBoolean(R.string.key_general_auto_completion,
DefaultPreference.enableAutoCompletion)
DefaultValues.enableAutoCompletion)
}
fun isBackButtonBeMappedToEscapeEnabled(): Boolean {
return loadBoolean(R.string.key_generaL_backspace_map_to_esc,
DefaultPreference.enableBackButtonBeMappedToEscape)
DefaultValues.enableBackButtonBeMappedToEscape)
}
fun isExtraKeysEnabled(): Boolean {
return loadBoolean(R.string.key_ui_eks_enabled,
DefaultPreference.enableExtraKeys)
DefaultValues.enableExtraKeys)
}
fun isExplicitExtraKeysWeightEnabled() :Boolean {
return loadBoolean(R.string.key_ui_eks_weight_explicit,
DefaultPreference.enableExplicitExtraKeysWeight)
DefaultValues.enableExplicitExtraKeysWeight)
}
fun isFullScreenEnabled() : Boolean {
return loadBoolean(R.string.key_ui_fullscreen,
DefaultPreference.enableFullScreen)
DefaultValues.enableFullScreen)
}
fun isHideToolbarEnabled() :Boolean {
return loadBoolean(R.string.key_ui_hide_toolbar,
DefaultPreference.enableAutoHideToolbar)
DefaultValues.enableAutoHideToolbar)
}
fun isNextTabEnabled() :Boolean {
return loadBoolean(R.string.key_ui_next_tab_anim,
DefaultPreference.enableSwitchNextTab)
DefaultValues.enableSwitchNextTab)
}
// fun storeWindowSize(context: Context, width: Int, height: Int) {

View File

@ -8,21 +8,22 @@ import android.annotation.SuppressLint
object NeoTermPath {
@SuppressLint("SdCardPath")
const val ROOT_PATH = "/data/data/io.neoterm/files"
const val USR_PATH = "${ROOT_PATH}/usr"
const val HOME_PATH = "${ROOT_PATH}/home"
const val APT_BIN_PATH = "${USR_PATH}/bin/apt"
const val LIB_PATH = "${USR_PATH}/lib"
const val USR_PATH = "$ROOT_PATH/usr"
const val HOME_PATH = "$ROOT_PATH/home"
const val APT_BIN_PATH = "$USR_PATH/bin/apt"
const val LIB_PATH = "$USR_PATH/lib"
const val CUSTOM_PATH = "${HOME_PATH}/.neoterm"
const val NEOTERM_SHELL_PATH = "${CUSTOM_PATH}/shell"
const val EKS_PATH = "${CUSTOM_PATH}/eks"
const val EKS_DEFAULT_FILE = "${EKS_PATH}/default.nl"
const val FONT_PATH = "${CUSTOM_PATH}/font"
const val COLORS_PATH = "${CUSTOM_PATH}/color"
const val USER_SCRIPT_PATH = "${CUSTOM_PATH}/script"
const val CUSTOM_PATH = "$HOME_PATH/.neoterm"
const val NEOTERM_LOGIN_SHELL_PATH = "$CUSTOM_PATH/shell"
const val EKS_PATH = "$CUSTOM_PATH/eks"
const val EKS_DEFAULT_FILE = "$EKS_PATH/default.nl"
const val FONT_PATH = "$CUSTOM_PATH/font"
const val COLORS_PATH = "$CUSTOM_PATH/color"
const val USER_SCRIPT_PATH = "$CUSTOM_PATH/script"
const val PROFILE_PATH = "$CUSTOM_PATH/profile"
const val SOURCE_FILE = "${USR_PATH}/etc/apt/sources.list"
const val PACKAGE_LIST_DIR = "${USR_PATH}/var/lib/apt/lists"
const val SOURCE_FILE = "$USR_PATH/etc/apt/sources.list"
const val PACKAGE_LIST_DIR = "$USR_PATH/var/lib/apt/lists"
const val SOURCE = "http://neoterm.studio"
@ -33,6 +34,6 @@ object NeoTermPath {
init {
DEFAULT_SOURCE = SOURCE
SERVER_BASE_URL = DEFAULT_SOURCE
SERVER_BOOT_URL = "${SERVER_BASE_URL}/boot"
SERVER_BOOT_URL = "$SERVER_BASE_URL/boot"
}
}

View File

@ -3,23 +3,23 @@ package io.neoterm.frontend.session.shell
import io.neoterm.component.color.ColorSchemeComponent
import io.neoterm.component.font.FontComponent
import io.neoterm.frontend.component.ComponentManager
import io.neoterm.frontend.config.DefaultPreference
import io.neoterm.frontend.config.DefaultValues
import io.neoterm.frontend.config.NeoPreference
/**
* @author kiva
*/
class ShellProfile {
var loginShell = DefaultPreference.loginShell
var initialCommand = DefaultPreference.initialCommand
var loginShell = DefaultValues.loginShell
var initialCommand = DefaultValues.initialCommand
var enableBell = DefaultPreference.enableBell
var enableVibrate = DefaultPreference.enableVibrate
var enableExecveWrapper = DefaultPreference.enableExecveWrapper
var enableSpecialVolumeKeys = DefaultPreference.enableSpecialVolumeKeys
var enableAutoCompletion = DefaultPreference.enableAutoCompletion
var enableBackButtonBeMappedToEscape = DefaultPreference.enableBackButtonBeMappedToEscape
var enableExtraKeys = DefaultPreference.enableExtraKeys
var enableBell = DefaultValues.enableBell
var enableVibrate = DefaultValues.enableVibrate
var enableExecveWrapper = DefaultValues.enableExecveWrapper
var enableSpecialVolumeKeys = DefaultValues.enableSpecialVolumeKeys
var enableAutoCompletion = DefaultValues.enableAutoCompletion
var enableBackButtonBeMappedToEscape = DefaultValues.enableBackButtonBeMappedToEscape
var enableExtraKeys = DefaultValues.enableExtraKeys
var profileFont: String
var profileColorScheme: String