Improve: Show help

This commit is contained in:
zt515 2017-08-07 19:47:52 +08:00
parent c9937f1c6e
commit c337988b69
8 changed files with 82 additions and 21 deletions

View File

@ -13,10 +13,10 @@
android:name=".App"
android:allowBackup="true"
android:extractNativeLibs="true"
android:resizeableActivity="true"
android:fullBackupContent="@xml/backup_config"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:resizeableActivity="true"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
@ -68,6 +68,15 @@
<action android:name="android.intent.action.SEND_MULTIPLE" />
<action android:name="android.intent.action.MAIN" />
<data android:mimeType="*/*" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<data android:scheme="file" />
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.MAIN" />
<data android:mimeType="*/*" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

View File

@ -1,6 +1,11 @@
package io.neoterm
import android.app.AlertDialog
import android.app.Application
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.view.WindowManager
import io.neoterm.customize.NeoInitializer
import io.neoterm.frontend.preference.NeoPreference
import io.neoterm.utils.CrashHandler
@ -17,11 +22,34 @@ class App : Application() {
NeoInitializer.initialize(this)
}
companion object {
private var app: App? = null
fun errorDialog(context: Context, message: Int, dismissCallback: (() -> Unit)?) {
errorDialog(context, getString(message), dismissCallback)
}
fun errorDialog(context: Context, message: String, dismissCallback: (() -> Unit)?) {
AlertDialog.Builder(context)
.setTitle(R.string.error)
.setMessage(message)
.setNegativeButton(android.R.string.no, null)
.setPositiveButton(R.string.show_help, { _, _ ->
openHelpLink()
})
.setOnDismissListener {
dismissCallback?.invoke()
}
.show()
}
fun openHelpLink() {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://neoterm.github.io/NeoTerm-wiki")))
}
companion object {
private var app: App? = null
fun get(): App {
return app!!
}
}
}

View File

@ -137,7 +137,8 @@ object NLog {
returnTag = sGlobalTag
} else {
returnTag = "$sGlobalTag-$returnTag"
val targetElement = Thread.currentThread().stackTrace[3]
// DO NOT USE Thread.currentThread
val targetElement = Throwable().stackTrace[3]
var className = targetElement.className
val classNameInfo = className.split("\\.".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
if (classNameInfo.isNotEmpty()) {

View File

@ -6,6 +6,7 @@ import android.support.v7.app.AlertDialog
import android.support.v7.app.AppCompatActivity
import android.widget.Button
import android.widget.Toast
import io.neoterm.App
import io.neoterm.R
import io.neoterm.customize.setup.BaseFileInstaller
import io.neoterm.utils.PackageUtils
@ -46,7 +47,11 @@ class SetupActivity : AppCompatActivity() {
.setPositiveButton(R.string.retry, { dialog, _ ->
dialog.dismiss()
BaseFileInstaller.installBaseFiles(this@SetupActivity, resultListener)
}).show()
})
.setNeutralButton(R.string.show_help, { _, _ ->
App.get().openHelpLink()
})
.show()
}
}
BaseFileInstaller.installBaseFiles(this, resultListener)

View File

@ -23,6 +23,9 @@ import io.neoterm.services.NeoTermService
import io.neoterm.utils.TerminalUtils
import java.io.File
import android.content.Intent.ShortcutIconResource
import android.util.Log
import io.neoterm.App
import io.neoterm.frontend.logging.NLog
import io.neoterm.frontend.service.ServiceManager
@ -37,7 +40,7 @@ class NeoTermRemoteInterface : AppCompatActivity(), ServiceConnection {
val serviceIntent = Intent(this, NeoTermService::class.java)
startService(serviceIntent)
if (!bindService(serviceIntent, this, 0)) {
finish()
App.get().errorDialog(this, R.string.service_connection_failed, { finish() })
}
}
@ -77,8 +80,7 @@ class NeoTermRemoteInterface : AppCompatActivity(), ServiceConnection {
when (intent.action) {
ACTION_EXECUTE -> {
if (!intent.hasExtra(EXTRA_COMMAND)) {
Toast.makeText(this, R.string.no_command_extra, Toast.LENGTH_SHORT).show()
finish()
App.get().errorDialog(this, R.string.no_command_extra, { finish() })
return
}
val command = intent.getStringExtra(EXTRA_COMMAND)
@ -133,9 +135,17 @@ class NeoTermRemoteInterface : AppCompatActivity(), ServiceConnection {
}
private fun handleUserScript() {
val filesToHandle = mutableListOf<String>()
val userScriptService = ServiceManager.getService<UserScriptService>()
val userScripts = userScriptService.userScripts
if (userScripts.isEmpty()) {
App.get().errorDialog(this, R.string.no_user_script_found, { finish() })
return
}
if (intent.hasExtra(Intent.EXTRA_STREAM)) {
// action send
val extra = intent.extras.get(Intent.EXTRA_STREAM)
val filesToHandle = mutableListOf<String>()
when (extra) {
is ArrayList<*> -> {
@ -148,16 +158,15 @@ class NeoTermRemoteInterface : AppCompatActivity(), ServiceConnection {
filesToHandle.add(File(extra.path).absolutePath)
}
}
} else if (intent.data != null) {
// action view
filesToHandle.add(File(intent.data.path).absolutePath)
}
val userScriptManager = ServiceManager.getService<UserScriptService>()
val userScripts = userScriptManager.userScripts
if (userScripts.isNotEmpty() && filesToHandle.isNotEmpty()) {
setupUserScriptView(filesToHandle, userScripts)
} else {
Toast.makeText(this, R.string.no_user_script_found_or_files_selected, Toast.LENGTH_LONG).show()
finish()
}
if (filesToHandle.isNotEmpty()) {
setupUserScriptView(filesToHandle, userScripts)
} else {
App.get().errorDialog(this, R.string.no_files_selected, { finish() })
}
}

View File

@ -89,7 +89,8 @@
<string name="exit">退出</string>
<string name="term_here">在此处打开终端</string>
<string name="user_script">用户脚本</string>
<string name="no_user_script_found_or_files_selected">没有找到可用的用户脚本或者没有文件被选择</string>
<string name="no_user_script_found">没有找到可用的用户脚本</string>
<string name="no_files_selected">没有文件被选择</string>
<string name="files_to_handle">处理的文件</string>
<string name="available_user_scripts">可用的用户脚本</string>
<string name="confirm_remove_file_from_list">从操作列表中移除文件?</string>
@ -107,4 +108,6 @@
<string name="installing_topic">安装已开始,请注意屏幕上出现的提示</string>
<string name="session_closed">会话已关闭</string>
<string name="restore_session">取消</string>
<string name="show_help">查看帮助</string>
<string name="service_connection_failed">无法连接到服务</string>
</resources>

View File

@ -89,7 +89,8 @@
<string name="exit">離開</string>
<string name="term_here">在此處打開終端</string>
<string name="user_script">使用者腳本</string>
<string name="no_user_script_found_or_files_selected">没有找到可用的使用者腳本或是沒有檔案被選擇</string>
<string name="no_user_script_found">没有找到可用的使用者腳本</string>
<string name="no_files_selected">沒有檔案被選擇</string>
<string name="files_to_handle">處理的檔案</string>
<string name="available_user_scripts">可用的使用者腳本</string>
<string name="confirm_remove_file_from_list">從操作列表中中移除檔案?</string>
@ -107,4 +108,6 @@
<string name="installing_topic">安裝已開始,請注意荧幕上出現的提示</string>
<string name="session_closed">會話已關閉</string>
<string name="restore_session">取消</string>
<string name="show_help">查看幫助</string>
<string name="service_connection_failed">無法連接到服務</string>
</resources>

View File

@ -87,7 +87,8 @@
<string name="term_here">Term Here</string>
<string name="user_script">User Script</string>
<string name="command_shortcut">Command Shortcut</string>
<string name="no_user_script_found_or_files_selected">No user script found or no files selected</string>
<string name="no_user_script_found">No user script found</string>
<string name="no_files_selected">No files selected</string>
<string name="files_to_handle">Files to Handle</string>
<string name="available_user_scripts">Available User Scripts</string>
<string name="confirm_remove_file_from_list">Remove file from list?</string>
@ -102,6 +103,8 @@
<string name="installing_topic">Installation started. Please pay attention to the prompt that appears on the screen</string>
<string name="session_closed">Session was closed</string>
<string name="restore_session">Cancel</string>
<string name="show_help">Show Help</string>
<string name="service_connection_failed">Failed to connect to service</string>
<string-array name="pref_general_shell_entries" translatable="false">
<item>sh</item>