diff --git a/app/src/main/java/io/neoterm/component/color/NeoColorScheme.kt b/app/src/main/java/io/neoterm/component/color/NeoColorScheme.kt index 8773ec9..01f661b 100644 --- a/app/src/main/java/io/neoterm/component/color/NeoColorScheme.kt +++ b/app/src/main/java/io/neoterm/component/color/NeoColorScheme.kt @@ -58,7 +58,7 @@ open class NeoColorScheme { fun loadConfigure(file: File): Boolean { // TODO: Refactor with NeoExtraKey#loadConfigure - val loaderService = ComponentManager.getService() + val loaderService = ComponentManager.getComponent() val configure: NeoConfigureFile? try { diff --git a/app/src/main/java/io/neoterm/component/eks/NeoExtraKey.kt b/app/src/main/java/io/neoterm/component/eks/NeoExtraKey.kt index ef14219..d343805 100644 --- a/app/src/main/java/io/neoterm/component/eks/NeoExtraKey.kt +++ b/app/src/main/java/io/neoterm/component/eks/NeoExtraKey.kt @@ -44,7 +44,7 @@ class NeoExtraKey { fun loadConfigure(file: File): Boolean { // TODO: Refactor with NeoColorScheme#loadConfigure - val loaderService = ComponentManager.getService() + val loaderService = ComponentManager.getComponent() val configure: NeoConfigureFile? try { diff --git a/app/src/main/java/io/neoterm/component/pm/NeoPackageComponent.java b/app/src/main/java/io/neoterm/component/pm/NeoPackageComponent.java index a9dec7f..3858bb4 100644 --- a/app/src/main/java/io/neoterm/component/pm/NeoPackageComponent.java +++ b/app/src/main/java/io/neoterm/component/pm/NeoPackageComponent.java @@ -29,7 +29,11 @@ public class NeoPackageComponent implements NeoComponent { return queryEnabled ? neoPackages.size() : -1; } - public void refreshPackageList(File packageListFile, boolean clearPrevious) throws IOException { + public SourceManager getSourceManager() { + return new SourceManager(); + } + + public void reloadPackages(File packageListFile, boolean clearPrevious) throws IOException { synchronized (lock) { if (isRefreshing) { return; diff --git a/app/src/main/java/io/neoterm/component/pm/SourceManager.kt b/app/src/main/java/io/neoterm/component/pm/SourceManager.kt new file mode 100644 index 0000000..a8bf7d1 --- /dev/null +++ b/app/src/main/java/io/neoterm/component/pm/SourceManager.kt @@ -0,0 +1,27 @@ +package io.neoterm.component.pm + +import io.neoterm.App +import io.neoterm.R +import io.neoterm.frontend.preference.NeoPreference + +/** + * @author kiva + */ +class SourceManager internal constructor() { + val sources = mutableSetOf() + + init { + NeoPreference.loadStrings(NeoPreference.KEY_SOURCES).mapTo(sources, { it }) + if (sources.isEmpty()) { + sources.addAll(App.get().resources.getStringArray(R.array.pref_package_source_values)) + } + } + + fun addSource(sourceUrl: String) { + sources.add(sourceUrl) + } + + fun applyChanges() { + NeoPreference.storeStrings(NeoPreference.KEY_SOURCES, sources) + } +} diff --git a/app/src/main/java/io/neoterm/frontend/client/TermViewClient.kt b/app/src/main/java/io/neoterm/frontend/client/TermViewClient.kt index 466b3e4..9348930 100644 --- a/app/src/main/java/io/neoterm/frontend/client/TermViewClient.kt +++ b/app/src/main/java/io/neoterm/frontend/client/TermViewClient.kt @@ -203,7 +203,7 @@ class TermViewClient(val context: Context) : TerminalViewClient { if (lastTitle != title || force) { removeSuggestions() - ComponentManager.getService().showShortcutKeys(title, extraKeysView) + ComponentManager.getComponent().showShortcutKeys(title, extraKeysView) extraKeysView.updateButtons() lastTitle = title } diff --git a/app/src/main/java/io/neoterm/frontend/completion/view/CandidatePopupWindow.kt b/app/src/main/java/io/neoterm/frontend/completion/view/CandidatePopupWindow.kt index fd17249..587df86 100644 --- a/app/src/main/java/io/neoterm/frontend/completion/view/CandidatePopupWindow.kt +++ b/app/src/main/java/io/neoterm/frontend/completion/view/CandidatePopupWindow.kt @@ -135,7 +135,7 @@ class CandidatePopupWindow(val context: Context) { val splitView: View = rootView.findViewById(R.id.complete_split) init { - val colorScheme = ComponentManager.getService().getCurrentColorScheme() + val colorScheme = ComponentManager.getComponent().getCurrentColorScheme() val textColor = TerminalColors.parse(colorScheme.foregroundColor) display.setTextColor(textColor) description.setTextColor(textColor) diff --git a/app/src/main/java/io/neoterm/frontend/component/ComponentManager.kt b/app/src/main/java/io/neoterm/frontend/component/ComponentManager.kt index df28afd..dbc85c0 100644 --- a/app/src/main/java/io/neoterm/frontend/component/ComponentManager.kt +++ b/app/src/main/java/io/neoterm/frontend/component/ComponentManager.kt @@ -25,7 +25,7 @@ object ComponentManager { } } - inline fun getService(): T { + inline fun getComponent(): T { val serviceInterface = T::class.java val service: NeoComponent = COMPONENTS[serviceInterface] ?: throw ComponentNotFoundException(serviceInterface.simpleName) diff --git a/app/src/main/java/io/neoterm/frontend/floating/TerminalDialog.kt b/app/src/main/java/io/neoterm/frontend/floating/TerminalDialog.kt index 02f7900..195d638 100644 --- a/app/src/main/java/io/neoterm/frontend/floating/TerminalDialog.kt +++ b/app/src/main/java/io/neoterm/frontend/floating/TerminalDialog.kt @@ -4,9 +4,9 @@ import android.app.AlertDialog import android.content.Context import android.content.DialogInterface import io.neoterm.backend.TerminalSession -import io.neoterm.frontend.shell.ShellParameter import io.neoterm.frontend.client.BasicSessionCallback import io.neoterm.frontend.client.BasicViewClient +import io.neoterm.frontend.shell.ShellParameter import io.neoterm.utils.TerminalUtils /** @@ -76,7 +76,6 @@ class TerminalDialog(val context: Context) { fun show(title: String?) { dialog?.setTitle(title) - dialog?.setCancelable(false) dialog?.setCanceledOnTouchOutside(false) dialog?.show() } 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 a6be237..2c50d2a 100644 --- a/app/src/main/java/io/neoterm/frontend/preference/NeoPreference.kt +++ b/app/src/main/java/io/neoterm/frontend/preference/NeoPreference.kt @@ -23,6 +23,7 @@ object NeoPreference { const val KEY_FONT_SIZE = "neoterm_general_font_size" const val KEY_CURRENT_SESSION = "neoterm_service_current_session" const val KEY_SYSTEM_SHELL = "neoterm_core_system_shell" + const val KEY_SOURCES = "neoterm_source_source_list" // const val KEY_FLOATING_WINDOW_X = "neoterm_floating_window_x" // const val KEY_FLOATING_WINDOW_Y = "neoterm_floating_window_y" // const val KEY_FLOATING_WIDTH = "neoterm_floating_window_width" @@ -61,6 +62,14 @@ object NeoPreference { } } + fun storeStrings(key: String, value: Set) { + preference!!.edit().putStringSet(key, value).apply() + } + + fun loadStrings(key: String) : Set { + return preference!!.getStringSet(key, setOf()) + } + fun store(key: Int, value: Any) { store(App.get().getString(key), value) } diff --git a/app/src/main/java/io/neoterm/ui/customize/CustomizeActivity.kt b/app/src/main/java/io/neoterm/ui/customize/CustomizeActivity.kt index 9e2bb33..fb8bce1 100644 --- a/app/src/main/java/io/neoterm/ui/customize/CustomizeActivity.kt +++ b/app/src/main/java/io/neoterm/ui/customize/CustomizeActivity.kt @@ -56,8 +56,8 @@ class CustomizeActivity : BaseCustomizeActivity() { } private fun setupSpinners() { - val fontComponent = ComponentManager.getService() - val colorSchemeComponent = ComponentManager.getService() + val fontComponent = ComponentManager.getComponent() + val colorSchemeComponent = ComponentManager.getComponent() setupSpinner(R.id.custom_font_spinner, fontComponent.getFontNames(), fontComponent.getCurrentFontName(), object : AdapterView.OnItemSelectedListener { diff --git a/app/src/main/java/io/neoterm/ui/pm/PackageManagerActivity.kt b/app/src/main/java/io/neoterm/ui/pm/PackageManagerActivity.kt index ca977c4..922a1a3 100644 --- a/app/src/main/java/io/neoterm/ui/pm/PackageManagerActivity.kt +++ b/app/src/main/java/io/neoterm/ui/pm/PackageManagerActivity.kt @@ -3,7 +3,6 @@ package io.neoterm.ui.pm import android.animation.Animator import android.animation.AnimatorListenerAdapter import android.animation.ObjectAnimator -import android.annotation.SuppressLint import android.os.Bundle import android.support.v4.view.MenuItemCompat import android.support.v7.app.AlertDialog @@ -23,12 +22,13 @@ import com.github.wrdlbrnft.sortedlistadapter.SortedListAdapter import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView import io.neoterm.R import io.neoterm.backend.TerminalSession -import io.neoterm.component.pm.SourceUtils import io.neoterm.component.pm.NeoPackageComponent +import io.neoterm.component.pm.SourceManager +import io.neoterm.component.pm.SourceUtils +import io.neoterm.frontend.component.ComponentManager import io.neoterm.frontend.floating.TerminalDialog import io.neoterm.frontend.preference.NeoPreference import io.neoterm.frontend.preference.NeoTermPath -import io.neoterm.frontend.component.ComponentManager import io.neoterm.ui.pm.adapter.PackageAdapter import io.neoterm.ui.pm.model.PackageModel import io.neoterm.utils.PackageUtils @@ -121,57 +121,49 @@ class PackageManagerActivity : AppCompatActivity(), SearchView.OnQueryTextListen } private fun changeSource() { - val sourceList = resources.getStringArray(R.array.pref_package_source_values) + val sourceManager = ComponentManager.getComponent().sourceManager + val sourceList = sourceManager.sources + val currentSource = NeoPreference.loadString(R.string.key_package_source, NeoTermPath.DEFAULT_SOURCE) var checkedItem = sourceList.indexOf(currentSource) if (checkedItem == -1) { - checkedItem = sourceList.size - 1 + // Users may edit source.list on his own + checkedItem = sourceList.size + sourceManager.addSource(currentSource) } - @SuppressLint("ShowToast") - var toast = Toast.makeText(this, "", Toast.LENGTH_SHORT) var selectedIndex = 0 - AlertDialog.Builder(this) .setTitle(R.string.pref_package_source) - .setSingleChoiceItems(R.array.pref_package_source_entries, checkedItem, { dialog, which -> - if (which == sourceList.size - 1) { - changeSourceToUserInput() - dialog.dismiss() - } else { - selectedIndex = which - toast.cancel() - toast = Toast.makeText(this@PackageManagerActivity, sourceList[which], Toast.LENGTH_SHORT) - toast.show() - } + .setSingleChoiceItems(sourceList.toTypedArray(), checkedItem, { _, which -> + selectedIndex = which }) .setPositiveButton(android.R.string.yes, { _, _ -> - if (selectedIndex != sourceList.size - 1) { - changeSourceInternal(sourceList[selectedIndex]) - } + changeSourceInternal(sourceManager, sourceList.elementAt(selectedIndex)) + }) + .setNeutralButton(R.string.new_source, { _, _ -> + changeSourceToUserInput(sourceManager) }) .setNegativeButton(android.R.string.no, null) .show() } - private fun changeSourceToUserInput() { + private fun changeSourceToUserInput(sourceManager: SourceManager) { val editText = EditText(this) - val currentSource = NeoPreference.loadString(R.string.key_package_source, NeoTermPath.DEFAULT_SOURCE) - editText.setText(currentSource) - editText.requestFocus() - editText.setSelection(0, currentSource.length) AlertDialog.Builder(this) .setTitle(R.string.pref_package_source) .setView(editText) .setNegativeButton(android.R.string.no, null) .setPositiveButton(android.R.string.yes, { _, _ -> val source = editText.text.toString() - changeSourceInternal(source) + changeSourceInternal(sourceManager, source) }) .show() } - private fun changeSourceInternal(source: String) { + private fun changeSourceInternal(sourceManager: SourceManager, source: String) { + sourceManager.addSource(source) + sourceManager.applyChanges() NeoPreference.store(R.string.key_package_source, source) PackageUtils.syncSource() executeAptUpdate() @@ -213,12 +205,12 @@ class PackageManagerActivity : AppCompatActivity(), SearchView.OnQueryTextListen progressBar.visibility = View.VISIBLE progressBar.alpha = 0.0f Thread { - val pm = ComponentManager.getService() + val pm = ComponentManager.getComponent() val sourceFiles = SourceUtils.detectSourceFiles() pm.clearPackages() for (index in sourceFiles.indices) { - pm.refreshPackageList(sourceFiles[index], false) + pm.reloadPackages(sourceFiles[index], false) } val packages = pm.packages diff --git a/app/src/main/java/io/neoterm/ui/term/NeoTermRemoteInterface.kt b/app/src/main/java/io/neoterm/ui/term/NeoTermRemoteInterface.kt index 4ebca6b..d0c41dc 100644 --- a/app/src/main/java/io/neoterm/ui/term/NeoTermRemoteInterface.kt +++ b/app/src/main/java/io/neoterm/ui/term/NeoTermRemoteInterface.kt @@ -105,7 +105,7 @@ class NeoTermRemoteInterface : AppCompatActivity(), ServiceConnection { private fun handleUserScript() { val filesToHandle = mutableListOf() - val userScriptService = ComponentManager.getService() + val userScriptService = ComponentManager.getComponent() val userScripts = userScriptService.userScripts if (userScripts.isEmpty()) { App.get().errorDialog(this, R.string.no_user_script_found, { finish() }) diff --git a/app/src/main/java/io/neoterm/ui/term/tab/TermTab.kt b/app/src/main/java/io/neoterm/ui/term/tab/TermTab.kt index 5774417..b767d05 100644 --- a/app/src/main/java/io/neoterm/ui/term/tab/TermTab.kt +++ b/app/src/main/java/io/neoterm/ui/term/tab/TermTab.kt @@ -22,7 +22,7 @@ class TermTab(title: CharSequence) : Tab(title), TermUiPresenter { var toolbar: Toolbar? = null fun updateColorScheme() { - val colorSchemeManager = ComponentManager.getService() + val colorSchemeManager = ComponentManager.getComponent() colorSchemeManager.applyColorScheme(termData.termView, termData.extraKeysView, colorSchemeManager.getCurrentColorScheme()) } diff --git a/app/src/main/java/io/neoterm/ui/term/tab/TermTabDecorator.kt b/app/src/main/java/io/neoterm/ui/term/tab/TermTabDecorator.kt index de0e8a9..fa1851c 100644 --- a/app/src/main/java/io/neoterm/ui/term/tab/TermTabDecorator.kt +++ b/app/src/main/java/io/neoterm/ui/term/tab/TermTabDecorator.kt @@ -51,7 +51,7 @@ class TermTabDecorator(val context: NeoTermActivity) : TabSwitcherDecorator() { TerminalUtils.setupTerminalView(view) TerminalUtils.setupExtraKeysView(extraKeysView) - val colorSchemeManager = ComponentManager.getService() + val colorSchemeManager = ComponentManager.getComponent() colorSchemeManager.applyColorScheme(view, extraKeysView, colorSchemeManager.getCurrentColorScheme()) if (tab is TermTab) { diff --git a/app/src/main/java/io/neoterm/utils/TerminalUtils.kt b/app/src/main/java/io/neoterm/utils/TerminalUtils.kt index 0ceac3d..10731b9 100644 --- a/app/src/main/java/io/neoterm/utils/TerminalUtils.kt +++ b/app/src/main/java/io/neoterm/utils/TerminalUtils.kt @@ -19,7 +19,7 @@ object TerminalUtils { fun setupTerminalView(terminalView: TerminalView?, terminalViewClient: TerminalViewClient? = null) { terminalView?.textSize = NeoPreference.loadInt(NeoPreference.KEY_FONT_SIZE, 30) - val fontComponent = ComponentManager.getService() + val fontComponent = ComponentManager.getComponent() fontComponent.applyFont(terminalView, null, fontComponent.getCurrentFont()) if (terminalViewClient != null) { @@ -28,7 +28,7 @@ object TerminalUtils { } fun setupExtraKeysView(extraKeysView: ExtraKeysView?) { - val fontComponent = ComponentManager.getService() + val fontComponent = ComponentManager.getComponent() val font = fontComponent.getCurrentFont() fontComponent.applyFont(null, extraKeysView, font) } diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 7c6b10e..807c2a6 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -62,11 +62,6 @@ 完成 安装 - - mirrors.geekpie.org - neoterm.studio - 输入… - 拓展键盘 响铃,振动,Shell,初始命令 全屏,标题栏,切换动画 @@ -124,4 +119,5 @@ 支付宝 新建配色方案 常见问题 + 新建 \ No newline at end of file diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index c7bd42f..45d0740 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -62,11 +62,6 @@ 完成 安裝 - - mirrors.geekpie.org - neoterm.studio - 手動輸入… - 擴充鍵盤 響鈴,震動,Shell,初始化指令 全螢幕,標題欄,切換動畫 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c98444a..c523f93 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -119,6 +119,7 @@ nullptr for accompanying me\nCoolApk User @NimaQu for providing server\nQQ User @My for providing free network New Color Scheme FAQ + New sh @@ -141,16 +142,14 @@ System First - + mirrors.geekpie.org neoterm.studio - Input… https://mirrors.geekpie.org/neoterm http://neoterm.studio - User-Input