Improve: Package source dialog
This commit is contained in:
parent
62a388634a
commit
e7e19d0f25
@ -58,7 +58,7 @@ open class NeoColorScheme {
|
||||
|
||||
fun loadConfigure(file: File): Boolean {
|
||||
// TODO: Refactor with NeoExtraKey#loadConfigure
|
||||
val loaderService = ComponentManager.getService<ConfigureComponent>()
|
||||
val loaderService = ComponentManager.getComponent<ConfigureComponent>()
|
||||
|
||||
val configure: NeoConfigureFile?
|
||||
try {
|
||||
|
@ -44,7 +44,7 @@ class NeoExtraKey {
|
||||
|
||||
fun loadConfigure(file: File): Boolean {
|
||||
// TODO: Refactor with NeoColorScheme#loadConfigure
|
||||
val loaderService = ComponentManager.getService<ConfigureComponent>()
|
||||
val loaderService = ComponentManager.getComponent<ConfigureComponent>()
|
||||
|
||||
val configure: NeoConfigureFile?
|
||||
try {
|
||||
|
@ -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;
|
||||
|
27
app/src/main/java/io/neoterm/component/pm/SourceManager.kt
Normal file
27
app/src/main/java/io/neoterm/component/pm/SourceManager.kt
Normal file
@ -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<String>()
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
@ -203,7 +203,7 @@ class TermViewClient(val context: Context) : TerminalViewClient {
|
||||
|
||||
if (lastTitle != title || force) {
|
||||
removeSuggestions()
|
||||
ComponentManager.getService<ExtraKeysComponent>().showShortcutKeys(title, extraKeysView)
|
||||
ComponentManager.getComponent<ExtraKeysComponent>().showShortcutKeys(title, extraKeysView)
|
||||
extraKeysView.updateButtons()
|
||||
lastTitle = title
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ class CandidatePopupWindow(val context: Context) {
|
||||
val splitView: View = rootView.findViewById(R.id.complete_split)
|
||||
|
||||
init {
|
||||
val colorScheme = ComponentManager.getService<ColorSchemeComponent>().getCurrentColorScheme()
|
||||
val colorScheme = ComponentManager.getComponent<ColorSchemeComponent>().getCurrentColorScheme()
|
||||
val textColor = TerminalColors.parse(colorScheme.foregroundColor)
|
||||
display.setTextColor(textColor)
|
||||
description.setTextColor(textColor)
|
||||
|
@ -25,7 +25,7 @@ object ComponentManager {
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <reified T : NeoComponent> getService(): T {
|
||||
inline fun <reified T : NeoComponent> getComponent(): T {
|
||||
val serviceInterface = T::class.java
|
||||
val service: NeoComponent = COMPONENTS[serviceInterface] ?:
|
||||
throw ComponentNotFoundException(serviceInterface.simpleName)
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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<String>) {
|
||||
preference!!.edit().putStringSet(key, value).apply()
|
||||
}
|
||||
|
||||
fun loadStrings(key: String) : Set<String> {
|
||||
return preference!!.getStringSet(key, setOf())
|
||||
}
|
||||
|
||||
fun store(key: Int, value: Any) {
|
||||
store(App.get().getString(key), value)
|
||||
}
|
||||
|
@ -56,8 +56,8 @@ class CustomizeActivity : BaseCustomizeActivity() {
|
||||
}
|
||||
|
||||
private fun setupSpinners() {
|
||||
val fontComponent = ComponentManager.getService<FontComponent>()
|
||||
val colorSchemeComponent = ComponentManager.getService<ColorSchemeComponent>()
|
||||
val fontComponent = ComponentManager.getComponent<FontComponent>()
|
||||
val colorSchemeComponent = ComponentManager.getComponent<ColorSchemeComponent>()
|
||||
|
||||
setupSpinner(R.id.custom_font_spinner, fontComponent.getFontNames(),
|
||||
fontComponent.getCurrentFontName(), object : AdapterView.OnItemSelectedListener {
|
||||
|
@ -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<NeoPackageComponent>().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<NeoPackageComponent>()
|
||||
val pm = ComponentManager.getComponent<NeoPackageComponent>()
|
||||
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
|
||||
|
@ -105,7 +105,7 @@ class NeoTermRemoteInterface : AppCompatActivity(), ServiceConnection {
|
||||
|
||||
private fun handleUserScript() {
|
||||
val filesToHandle = mutableListOf<String>()
|
||||
val userScriptService = ComponentManager.getService<UserScriptComponent>()
|
||||
val userScriptService = ComponentManager.getComponent<UserScriptComponent>()
|
||||
val userScripts = userScriptService.userScripts
|
||||
if (userScripts.isEmpty()) {
|
||||
App.get().errorDialog(this, R.string.no_user_script_found, { finish() })
|
||||
|
@ -22,7 +22,7 @@ class TermTab(title: CharSequence) : Tab(title), TermUiPresenter {
|
||||
var toolbar: Toolbar? = null
|
||||
|
||||
fun updateColorScheme() {
|
||||
val colorSchemeManager = ComponentManager.getService<ColorSchemeComponent>()
|
||||
val colorSchemeManager = ComponentManager.getComponent<ColorSchemeComponent>()
|
||||
colorSchemeManager.applyColorScheme(termData.termView, termData.extraKeysView,
|
||||
colorSchemeManager.getCurrentColorScheme())
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ class TermTabDecorator(val context: NeoTermActivity) : TabSwitcherDecorator() {
|
||||
TerminalUtils.setupTerminalView(view)
|
||||
TerminalUtils.setupExtraKeysView(extraKeysView)
|
||||
|
||||
val colorSchemeManager = ComponentManager.getService<ColorSchemeComponent>()
|
||||
val colorSchemeManager = ComponentManager.getComponent<ColorSchemeComponent>()
|
||||
colorSchemeManager.applyColorScheme(view, extraKeysView, colorSchemeManager.getCurrentColorScheme())
|
||||
|
||||
if (tab is TermTab) {
|
||||
|
@ -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<FontComponent>()
|
||||
val fontComponent = ComponentManager.getComponent<FontComponent>()
|
||||
fontComponent.applyFont(terminalView, null, fontComponent.getCurrentFont())
|
||||
|
||||
if (terminalViewClient != null) {
|
||||
@ -28,7 +28,7 @@ object TerminalUtils {
|
||||
}
|
||||
|
||||
fun setupExtraKeysView(extraKeysView: ExtraKeysView?) {
|
||||
val fontComponent = ComponentManager.getService<FontComponent>()
|
||||
val fontComponent = ComponentManager.getComponent<FontComponent>()
|
||||
val font = fontComponent.getCurrentFont()
|
||||
fontComponent.applyFont(null, extraKeysView, font)
|
||||
}
|
||||
|
@ -62,11 +62,6 @@
|
||||
<string name="done">完成</string>
|
||||
<string name="install">安装</string>
|
||||
|
||||
<string-array name="pref_package_source_entries">
|
||||
<item>mirrors.geekpie.org</item>
|
||||
<item>neoterm.studio</item>
|
||||
<item>输入…</item>
|
||||
</string-array>
|
||||
<string name="pref_customization_eks">拓展键盘</string>
|
||||
<string name="general_settings_desc">响铃,振动,Shell,初始命令</string>
|
||||
<string name="ui_settings_desc">全屏,标题栏,切换动画</string>
|
||||
@ -124,4 +119,5 @@
|
||||
<string name="support_donate_alipay">支付宝</string>
|
||||
<string name="new_color_scheme">新建配色方案</string>
|
||||
<string name="faq">常见问题</string>
|
||||
<string name="new_source">新建</string>
|
||||
</resources>
|
@ -62,11 +62,6 @@
|
||||
<string name="done">完成</string>
|
||||
<string name="install">安裝</string>
|
||||
|
||||
<string-array name="pref_package_source_entries">
|
||||
<item>mirrors.geekpie.org</item>
|
||||
<item>neoterm.studio</item>
|
||||
<item>手動輸入…</item>
|
||||
</string-array>
|
||||
<string name="pref_customization_eks">擴充鍵盤</string>
|
||||
<string name="general_settings_desc">響鈴,震動,Shell,初始化指令</string>
|
||||
<string name="ui_settings_desc">全螢幕,標題欄,切換動畫</string>
|
||||
|
@ -119,6 +119,7 @@
|
||||
<string name="about_credits">nullptr for accompanying me\nCoolApk User @NimaQu for providing server\nQQ User @My for providing free network</string>
|
||||
<string name="new_color_scheme">New Color Scheme</string>
|
||||
<string name="faq">FAQ</string>
|
||||
<string name="new_source">New</string>
|
||||
|
||||
<string-array name="pref_general_shell_entries" translatable="false">
|
||||
<item>sh</item>
|
||||
@ -141,16 +142,14 @@
|
||||
<item>System First</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="pref_package_source_entries">
|
||||
<string-array name="pref_package_source_entries" translatable="false">
|
||||
<item>mirrors.geekpie.org</item>
|
||||
<item>neoterm.studio</item>
|
||||
<item>Input…</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="pref_package_source_values" translatable="false">
|
||||
<item>https://mirrors.geekpie.org/neoterm</item>
|
||||
<item>http://neoterm.studio</item>
|
||||
<item>User-Input</item>
|
||||
</string-array>
|
||||
|
||||
</resources>
|
||||
|
Loading…
x
Reference in New Issue
Block a user