From 1034405543d9b281d506f4604fba6da4219e2894 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=B9=E5=9D=97=E5=90=9B?= Date: Thu, 12 May 2022 18:31:27 +0800 Subject: [PATCH] Fix dialog display exception --- .../main/java/xfk233/GenshinProxy/MainHook.kt | 177 ++++++++++-------- app/src/main/res/values-zh-rCN/strings.xml | 6 +- app/src/main/res/values/strings.xml | 6 +- 3 files changed, 108 insertions(+), 81 deletions(-) diff --git a/app/src/main/java/xfk233/GenshinProxy/MainHook.kt b/app/src/main/java/xfk233/GenshinProxy/MainHook.kt index 5a60cf6..0ad8ced 100644 --- a/app/src/main/java/xfk233/GenshinProxy/MainHook.kt +++ b/app/src/main/java/xfk233/GenshinProxy/MainHook.kt @@ -34,6 +34,7 @@ import java.io.InputStreamReader import java.net.HttpURLConnection import java.net.URL import java.util.regex.Pattern +import kotlin.system.exitProcess class MainHook : IXposedHookLoadPackage, IXposedHookZygoteInit { @@ -104,91 +105,109 @@ class MainHook : IXposedHookLoadPackage, IXposedHookZygoteInit { } findMethod("com.miHoYo.GetMobileInfo.MainActivity") { name == "onCreate" }.hookBefore { param -> activity = param.thisObject as Activity - AlertDialog.Builder(activity).apply { - setCancelable(false) - setTitle(moduleRes.getString(R.string.SelectServer)) - setMessage(moduleRes.getString(R.string.Tips)) - setView(LinearLayout(activity).apply { - orientation = LinearLayout.VERTICAL - addView(EditText(activity).apply { - hint = "http(s)://server.com:1234" - val str = sp.getString("serverip", "") ?: "" - setText(str.toCharArray(), 0, str.length) - addTextChangedListener(object : TextWatcher { - override fun beforeTextChanged(p0: CharSequence, p1: Int, p2: Int, p3: Int) {} - override fun onTextChanged(p0: CharSequence, p1: Int, p2: Int, p3: Int) {} + showDialog() + } + } - @SuppressLint("CommitPrefEdits") - override fun afterTextChanged(p0: Editable) { - sp.edit().run { - putString("serverip", p0.toString()) - apply() + private fun showDialog() { + AlertDialog.Builder(activity).apply { + setCancelable(false) + setTitle(moduleRes.getString(R.string.SelectServer)) + setMessage(moduleRes.getString(R.string.Tips)) + setNegativeButton(moduleRes.getString(R.string.Settings)) {_, _ -> + AlertDialog.Builder(activity).apply { + setMessage(moduleRes.getString(R.string.Tips2)) + setCancelable(false) + setView(ScrollView(context).apply { + addView(LinearLayout(activity).apply { + orientation = LinearLayout.VERTICAL + addView(EditText(activity).apply { + hint = "http(s)://server.com:1234" + val str = sp.getString("serverip", "") ?: "" + setText(str.toCharArray(), 0, str.length) + addTextChangedListener(object : TextWatcher { + override fun beforeTextChanged(p0: CharSequence, p1: Int, p2: Int, p3: Int) {} + override fun onTextChanged(p0: CharSequence, p1: Int, p2: Int, p3: Int) {} + + @SuppressLint("CommitPrefEdits") + override fun afterTextChanged(p0: Editable) { + sp.edit().run { + putString("serverip", p0.toString()) + apply() + } + } + }) + }) + addView(Switch(activity).apply { + text = moduleRes.getString(R.string.ForcedMode) + isChecked = sp.getBoolean("forceUrl", false) + setOnCheckedChangeListener { _, b -> + sp.edit().run { + putBoolean("forceUrl", b) + apply() + } + forceUrl = b } - } + }) + addView(Switch(activity).apply { + text = moduleRes.getString(R.string.ProxyList) + isChecked = sp.getBoolean("ProxyList", false) + setOnCheckedChangeListener { _, b -> + sp.edit().run { + putBoolean("ProxyList", b) + apply() + } + proxyList = b + } + }) + addView(Switch(activity).apply { + text = moduleRes.getString(R.string.HookConfig) + isChecked = sp.getBoolean("HookConfig", false) + setOnCheckedChangeListener { _, b -> + sp.edit().run { + putBoolean("HookConfig", b) + apply() + } + proxyList = b + } + }) + addView(Switch(activity).apply { + text = moduleRes.getString(R.string.EnableTools) + isChecked = sp.getBoolean("EnableTools", false) + setOnCheckedChangeListener { _, b -> + sp.edit().run { + putBoolean("EnableTools", b) + apply() + } + proxyList = b + } + }) }) }) - addView(Switch(activity).apply { - text = moduleRes.getString(R.string.ForcedMode) - isChecked = sp.getBoolean("forceUrl", false) - setOnCheckedChangeListener { _, b -> - sp.edit().run { - putBoolean("forceUrl", b) - apply() - } - forceUrl = b - } - }) - addView(Switch(activity).apply { - text = moduleRes.getString(R.string.ProxyList) - isChecked = sp.getBoolean("ProxyList", false) - setOnCheckedChangeListener { _, b -> - sp.edit().run { - putBoolean("ProxyList", b) - apply() - } - proxyList = b - } - }) - addView(Switch(activity).apply { - text = moduleRes.getString(R.string.HookConfig) - isChecked = sp.getBoolean("HookConfig", false) - setOnCheckedChangeListener { _, b -> - sp.edit().run { - putBoolean("HookConfig", b) - apply() - } - proxyList = b - } - }) - addView(Switch(activity).apply { - text = moduleRes.getString(R.string.EnableTools) - isChecked = sp.getBoolean("EnableTools", false) - setOnCheckedChangeListener { _, b -> - sp.edit().run { - putBoolean("EnableTools", b) - apply() - } - proxyList = b - } - }) - }) - setPositiveButton(moduleRes.getString(R.string.CustomServer)) { _, _ -> - val ip = sp.getString("serverip", "") ?: "" - if (ip == "") { - Toast.makeText(activity, moduleRes.getString(R.string.ServerAddressError), Toast.LENGTH_LONG).show() - activity.finish() - } else { - server = ip - forceUrl = true - if (sp.getBoolean("EnableTools", false)) gmTool() + setPositiveButton(moduleRes.getString(R.string.Back)) { _, _ -> + showDialog() } + setNeutralButton(moduleRes.getString(R.string.ExitGames)) {_, _ -> + exitProcess(0) + } + }.show() + } + setPositiveButton(moduleRes.getString(R.string.CustomServer)) { _, _ -> + val ip = sp.getString("serverip", "") ?: "" + if (ip == "") { + Toast.makeText(activity, moduleRes.getString(R.string.ServerAddressError), Toast.LENGTH_LONG).show() + activity.finish() + } else { + server = ip + forceUrl = true + if (sp.getBoolean("EnableTools", false)) gmTool() } - setNeutralButton(moduleRes.getString(R.string.OfficialServer)) { _, _ -> - forceUrl = false - server = "" - } - }.show() - } + } + setNeutralButton(moduleRes.getString(R.string.OfficialServer)) { _, _ -> + forceUrl = false + server = "" + } + }.show() } inner class MoveOnTouchListener : View.OnTouchListener { diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 4f69dc1..8da5460 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -4,10 +4,14 @@ 自定义服务器 官方服务器 选择服务器 - 第一次使用请输入好服务器地址后进入官方服务器下载资源,之后便可进入私服。\n强制模式: 强制替换全部域名\n\n请输入服务器地址: + 第一次使用请输入好服务器地址后进入官方服务器下载资源,之后便可进入私服。 强制模式 (需重启) 服务器地址错误 只代理列表内的地址 (需重启) 启用悬浮球工具 Hook 配置文件? (需重启) + 强制模式: 强制替换全部域名\n\n请输入服务器地址: + 返回 + 退出游戏 + 设置 \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bddaa30..b924dc5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -3,10 +3,14 @@ Custom server Official server Select server - For the first time, please enter the server address and enter the official server to download resources. Then you can enter the private server.\nForced mode: Forced replacement of all domain names\n\nInput server address: + For the first time, please enter the server address and enter the official server to download resources. Then you can enter the private server. Forced mode (restart required) Server address error. Only addresses in the proxy list (restart required) Enable tools Hook profile? (restart required) + Forced mode: Forced replacement of all domain names\n\nInput server address: + Back + Exit games + Settings \ No newline at end of file