Setup: More friendly
This commit is contained in:
parent
96fd70a559
commit
cb12df3ee8
@ -133,7 +133,7 @@
|
||||
android:label="@string/error"
|
||||
android:theme="@style/AppTheme.NoActionBar.Dark" />
|
||||
<activity
|
||||
android:name=".ui.setup.SetupActivity"
|
||||
android:name=".ui.showConfirmDialog.SetupActivity"
|
||||
android:exported="true"
|
||||
android:theme="@style/AppTheme.NoActionBar" />
|
||||
<activity
|
||||
|
@ -159,10 +159,10 @@ class PackageManagerActivity : AppCompatActivity(), SearchView.OnQueryTextListen
|
||||
}
|
||||
|
||||
private fun executeAptUpdate() {
|
||||
PackageUtils.executeApt(this, "update", null, { exitStatus, dialog ->
|
||||
PackageUtils.apt(this, "update", null, { exitStatus, dialog ->
|
||||
if (exitStatus != 0) {
|
||||
dialog.setTitle(getString(R.string.error))
|
||||
return@executeApt
|
||||
return@apt
|
||||
}
|
||||
Toast.makeText(this, R.string.apt_update_ok, Toast.LENGTH_SHORT).show()
|
||||
dialog.dismiss()
|
||||
@ -171,14 +171,14 @@ class PackageManagerActivity : AppCompatActivity(), SearchView.OnQueryTextListen
|
||||
}
|
||||
|
||||
private fun executeAptUpgrade() {
|
||||
PackageUtils.executeApt(this, "update", null, { exitStatus, dialog ->
|
||||
PackageUtils.apt(this, "update", null, { exitStatus, dialog ->
|
||||
if (exitStatus != 0) {
|
||||
dialog.setTitle(getString(R.string.error))
|
||||
return@executeApt
|
||||
return@apt
|
||||
}
|
||||
dialog.dismiss()
|
||||
|
||||
PackageUtils.executeApt(this, "upgrade", arrayOf("-y"), out@ { exitStatus, dialog ->
|
||||
PackageUtils.apt(this, "upgrade", arrayOf("-y"), out@ { exitStatus, dialog ->
|
||||
if (exitStatus != 0) {
|
||||
dialog.setTitle(getString(R.string.error))
|
||||
return@out
|
||||
|
@ -40,7 +40,7 @@ class GeneralSettingsActivity : BasePreferenceActivity() {
|
||||
.setTitle(getString(R.string.shell_not_found, shellName))
|
||||
.setMessage(R.string.shell_not_found_message)
|
||||
.setPositiveButton(R.string.install, { _, _ ->
|
||||
PackageUtils.executeApt(this, "install", arrayOf("-y", shellName), { exitStatus, dialog ->
|
||||
PackageUtils.apt(this, "install", arrayOf("-y", shellName), { exitStatus, dialog ->
|
||||
if (exitStatus == 0) {
|
||||
dialog.dismiss()
|
||||
postChangeShell(shellName)
|
||||
|
@ -5,7 +5,9 @@ import android.os.Bundle
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.view.View
|
||||
import android.widget.*
|
||||
import io.neoterm.App
|
||||
import io.neoterm.R
|
||||
import io.neoterm.component.setup.ResultListener
|
||||
import io.neoterm.component.setup.SetupHelper
|
||||
import io.neoterm.component.setup.SourceConnection
|
||||
import io.neoterm.component.setup.connection.AssetsFileConnection
|
||||
@ -16,12 +18,13 @@ import io.neoterm.component.setup.helper.URLAvailability
|
||||
import io.neoterm.frontend.config.NeoTermPath
|
||||
import io.neoterm.utils.PackageUtils
|
||||
import java.io.File
|
||||
import java.lang.Exception
|
||||
|
||||
|
||||
/**
|
||||
* @author kiva
|
||||
*/
|
||||
class SetupActivity : AppCompatActivity(), View.OnClickListener {
|
||||
class SetupActivity : AppCompatActivity(), View.OnClickListener, ResultListener {
|
||||
|
||||
private var aptUpdated = false
|
||||
private var setupParameter = ""
|
||||
@ -38,6 +41,7 @@ class SetupActivity : AppCompatActivity(), View.OnClickListener {
|
||||
setContentView(R.layout.ui_setup)
|
||||
|
||||
val parameterEditor = findViewById<EditText>(R.id.setup_source_parameter)
|
||||
val tipText = findViewById<TextView>(R.id.setup_url_tip_text)
|
||||
|
||||
val onCheckedChangeListener = CompoundButton.OnCheckedChangeListener { button, checked ->
|
||||
if (checked) {
|
||||
@ -48,6 +52,7 @@ class SetupActivity : AppCompatActivity(), View.OnClickListener {
|
||||
return@OnCheckedChangeListener
|
||||
}
|
||||
parameterEditor.setHint(hintMapping[index + 1])
|
||||
tipText.setText(hintMapping[index + 1])
|
||||
setDefaultValue(parameterEditor, id)
|
||||
}
|
||||
}
|
||||
@ -70,11 +75,11 @@ class SetupActivity : AppCompatActivity(), View.OnClickListener {
|
||||
Thread {
|
||||
val errorMessage = validateParameter(id, setupParameter)
|
||||
|
||||
SetupActivity@this.runOnUiThread {
|
||||
SetupActivity@ this.runOnUiThread {
|
||||
dialog.dismiss()
|
||||
editor.error = errorMessage
|
||||
if (errorMessage != null) {
|
||||
AlertDialog.Builder(SetupActivity@this)
|
||||
AlertDialog.Builder(SetupActivity@ this)
|
||||
.setMessage(errorMessage)
|
||||
.setPositiveButton(android.R.string.yes, null)
|
||||
.show()
|
||||
@ -82,7 +87,7 @@ class SetupActivity : AppCompatActivity(), View.OnClickListener {
|
||||
}
|
||||
|
||||
val connection = createSourceConnection(id, setupParameter)
|
||||
setup(connection)
|
||||
showConfirmDialog(connection)
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
@ -93,7 +98,7 @@ class SetupActivity : AppCompatActivity(), View.OnClickListener {
|
||||
R.id.setup_method_online -> NetworkConnection(parameter)
|
||||
R.id.setup_method_assets -> AssetsFileConnection()
|
||||
R.id.setup_method_backup -> BackupFileConnection(parameter)
|
||||
else -> throw IllegalArgumentException("Unexpected setup method!")
|
||||
else -> throw IllegalArgumentException("Unexpected showConfirmDialog method!")
|
||||
}
|
||||
}
|
||||
|
||||
@ -131,37 +136,49 @@ class SetupActivity : AppCompatActivity(), View.OnClickListener {
|
||||
parameterEditor.setText(setupParameter)
|
||||
}
|
||||
|
||||
private fun setup(connection: SourceConnection) {
|
||||
// TODO: Refactor
|
||||
// var resultListener: SetupHelper.ResultListener? = null
|
||||
// resultListener = SetupHelper.ResultListener { error ->
|
||||
// if (error == null) {
|
||||
// setResult(Activity.RESULT_OK)
|
||||
// PackageUtils.syncSource()
|
||||
// executeAptUpdate()
|
||||
// } else {
|
||||
// AlertDialog.Builder(this@SetupActivity)
|
||||
// .setTitle(R.string.error)
|
||||
// .setMessage(error.toString())
|
||||
// .setNegativeButton(R.string.use_system_shell, { _, _ ->
|
||||
// setResult(Activity.RESULT_CANCELED)
|
||||
// finish()
|
||||
// })
|
||||
// .setPositiveButton(R.string.retry, { dialog, _ ->
|
||||
// dialog.dismiss()
|
||||
// SetupHelper.setup(this@SetupActivity, resultListener)
|
||||
// })
|
||||
// .setNeutralButton(R.string.show_help, { _, _ ->
|
||||
// App.get().openHelpLink()
|
||||
// })
|
||||
// .show()
|
||||
// }
|
||||
// }
|
||||
// SetupHelper.setup(this, resultListener)
|
||||
private fun showConfirmDialog(connection: SourceConnection) {
|
||||
val needSetup = !SetupHelper.needSetup()
|
||||
val titleId = if (needSetup) R.string.setup_confirm else R.string.setup_reset_confirm
|
||||
val messageId = if (needSetup) R.string.setup_confirm_text else R.string.setup_reset_confirm_text
|
||||
|
||||
AlertDialog.Builder(this)
|
||||
.setTitle(titleId)
|
||||
.setMessage(messageId)
|
||||
.setPositiveButton(android.R.string.yes, { _, _ ->
|
||||
doSetup(connection)
|
||||
})
|
||||
.setNegativeButton(android.R.string.no, null)
|
||||
.show()
|
||||
}
|
||||
|
||||
private fun doSetup(connection: SourceConnection) {
|
||||
SetupHelper.setup(this@SetupActivity, connection, this)
|
||||
}
|
||||
|
||||
override fun onResult(error: Exception?) {
|
||||
if (error == null) {
|
||||
setResult(RESULT_OK)
|
||||
PackageUtils.syncSource()
|
||||
executeAptUpdate()
|
||||
|
||||
} else {
|
||||
AlertDialog.Builder(this@SetupActivity)
|
||||
.setTitle(R.string.error)
|
||||
.setMessage(error.toString())
|
||||
.setNegativeButton(R.string.use_system_shell, { _, _ ->
|
||||
setResult(RESULT_CANCELED)
|
||||
finish()
|
||||
})
|
||||
.setNeutralButton(R.string.show_help, { _, _ ->
|
||||
App.get().openHelpLink()
|
||||
})
|
||||
.setPositiveButton(android.R.string.yes, null)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
||||
private fun executeAptUpdate() {
|
||||
PackageUtils.executeApt(this, "update", null, { exitStatus, dialog ->
|
||||
PackageUtils.apt(this, "update", null, { exitStatus, dialog ->
|
||||
if (exitStatus == 0) {
|
||||
dialog.dismiss()
|
||||
aptUpdated = true
|
||||
@ -173,7 +190,7 @@ class SetupActivity : AppCompatActivity(), View.OnClickListener {
|
||||
}
|
||||
|
||||
private fun executeAptUpgrade() {
|
||||
PackageUtils.executeApt(this, "upgrade", arrayOf("-y"), { exitStatus, dialog ->
|
||||
PackageUtils.apt(this, "upgrade", arrayOf("-y"), { exitStatus, dialog ->
|
||||
if (exitStatus == 0) {
|
||||
dialog.dismiss()
|
||||
finish()
|
||||
|
@ -27,7 +27,7 @@ object PackageUtils {
|
||||
.toString()
|
||||
}
|
||||
|
||||
fun executeApt(context: Context, subCommand: String, extraArgs: Array<String>?, callback: (Int, TerminalDialog) -> Unit) {
|
||||
fun apt(context: Context, subCommand: String, extraArgs: Array<String>?, callback: (Int, TerminalDialog) -> Unit) {
|
||||
val argArray =
|
||||
if (extraArgs != null) arrayOf(NeoTermPath.APT_BIN_PATH, subCommand, *extraArgs)
|
||||
else arrayOf(NeoTermPath.APT_BIN_PATH, subCommand)
|
||||
|
@ -66,6 +66,7 @@
|
||||
<string name="package_settings_desc">软件源,更新,升级</string>
|
||||
<string name="install_font">安装字体</string>
|
||||
<string name="install_color">安装配色方案</string>
|
||||
|
||||
<string name="setup_info">你好,NeoTerm</string>
|
||||
<string name="setup_next">开始!</string>
|
||||
<string name="setup_setup_method">选择你的安装方式</string>
|
||||
@ -84,6 +85,11 @@
|
||||
<string name="setup_error_no_internet">无网络连接</string>
|
||||
<string name="setup_error_connection_failed">无法连接到服务器</string>
|
||||
<string name="setup_preparing">准备中…</string>
|
||||
<string name="setup_confirm">最后一步</string>
|
||||
<string name="setup_confirm_text">目前为止一切顺利,继续?</string>
|
||||
<string name="setup_reset_confirm">重置确认</string>
|
||||
<string name="setup_reset_confirm_text">这个操作会清空你的所有数据,是否继续?</string>
|
||||
|
||||
<string name="crash_model">设备: %s</string>
|
||||
<string name="crash_app">应用: %s</string>
|
||||
<string name="crash_stack_trace">堆栈信息</string>
|
||||
|
@ -22,8 +22,8 @@
|
||||
<string name="setup_source_parameter">Source Parameter</string>
|
||||
<string name="setup_input_source_parameter">Input source parameter…</string>
|
||||
<string name="setup_dots" translatable="false">…</string>
|
||||
<string name="setup_hint_online">URL of mirror that contains setup zip files</string>
|
||||
<string name="setup_hint_local">File path to setup zip files</string>
|
||||
<string name="setup_hint_online">URL of mirror that contains showConfirmDialog zip files</string>
|
||||
<string name="setup_hint_local">File path to showConfirmDialog zip files</string>
|
||||
<string name="setup_hint_assets">Not available</string>
|
||||
<string name="setup_hint_backup">File path to backup file(*.neobackup)</string>
|
||||
<string name="setup_error_file_not_found">File not found</string>
|
||||
@ -31,6 +31,10 @@
|
||||
<string name="setup_error_no_internet">No Internet connection</string>
|
||||
<string name="setup_error_connection_failed">Failed to connect to server</string>
|
||||
<string name="setup_preparing">Preparing…</string>
|
||||
<string name="setup_confirm">Finish Setup</string>
|
||||
<string name="setup_confirm_text">Everything goes well till now, continue?</string>
|
||||
<string name="setup_reset_confirm">Reset Confirm</string>
|
||||
<string name="setup_reset_confirm_text">This operation will clear all your data! Continue?</string>
|
||||
|
||||
<string name="about">About</string>
|
||||
<string name="settings">Settings</string>
|
||||
|
@ -43,7 +43,7 @@
|
||||
android:key="@string/discovery"
|
||||
android:title="@string/discovery">
|
||||
<intent
|
||||
android:targetClass="io.neoterm.ui.setup.SetupActivity"
|
||||
android:targetClass="io.neotermshowConfirmDialogetup.SetupActivity"
|
||||
android:targetPackage="io.neoterm" />
|
||||
</Preference>
|
||||
-->
|
||||
|
Loading…
Reference in New Issue
Block a user