Fix dialog display exception

This commit is contained in:
方块君 2022-05-12 18:31:27 +08:00
parent 7f2cc78878
commit 1034405543
3 changed files with 108 additions and 81 deletions

View File

@ -34,6 +34,7 @@ import java.io.InputStreamReader
import java.net.HttpURLConnection import java.net.HttpURLConnection
import java.net.URL import java.net.URL
import java.util.regex.Pattern import java.util.regex.Pattern
import kotlin.system.exitProcess
class MainHook : IXposedHookLoadPackage, IXposedHookZygoteInit { class MainHook : IXposedHookLoadPackage, IXposedHookZygoteInit {
@ -104,91 +105,109 @@ class MainHook : IXposedHookLoadPackage, IXposedHookZygoteInit {
} }
findMethod("com.miHoYo.GetMobileInfo.MainActivity") { name == "onCreate" }.hookBefore { param -> findMethod("com.miHoYo.GetMobileInfo.MainActivity") { name == "onCreate" }.hookBefore { param ->
activity = param.thisObject as Activity activity = param.thisObject as Activity
AlertDialog.Builder(activity).apply { showDialog()
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) {}
@SuppressLint("CommitPrefEdits") private fun showDialog() {
override fun afterTextChanged(p0: Editable) { AlertDialog.Builder(activity).apply {
sp.edit().run { setCancelable(false)
putString("serverip", p0.toString()) setTitle(moduleRes.getString(R.string.SelectServer))
apply() 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 { setPositiveButton(moduleRes.getString(R.string.Back)) { _, _ ->
text = moduleRes.getString(R.string.ForcedMode) showDialog()
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()
} }
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 setNeutralButton(moduleRes.getString(R.string.OfficialServer)) { _, _ ->
server = "" forceUrl = false
} server = ""
}.show() }
} }.show()
} }
inner class MoveOnTouchListener : View.OnTouchListener { inner class MoveOnTouchListener : View.OnTouchListener {

View File

@ -4,10 +4,14 @@
<string name="CustomServer">自定义服务器</string> <string name="CustomServer">自定义服务器</string>
<string name="OfficialServer">官方服务器</string> <string name="OfficialServer">官方服务器</string>
<string name="SelectServer">选择服务器</string> <string name="SelectServer">选择服务器</string>
<string name="Tips">第一次使用请输入好服务器地址后进入官方服务器下载资源,之后便可进入私服。\n强制模式: 强制替换全部域名\n\n请输入服务器地址: </string> <string name="Tips">第一次使用请输入好服务器地址后进入官方服务器下载资源,之后便可进入私服。</string>
<string name="ForcedMode">强制模式 (需重启)</string> <string name="ForcedMode">强制模式 (需重启)</string>
<string name="ServerAddressError">服务器地址错误</string> <string name="ServerAddressError">服务器地址错误</string>
<string name="ProxyList">只代理列表内的地址 (需重启)</string> <string name="ProxyList">只代理列表内的地址 (需重启)</string>
<string name="EnableTools">启用悬浮球工具</string> <string name="EnableTools">启用悬浮球工具</string>
<string name="HookConfig">Hook 配置文件? (需重启)</string> <string name="HookConfig">Hook 配置文件? (需重启)</string>
<string name="Tips2">强制模式: 强制替换全部域名\n\n请输入服务器地址: </string>
<string name="Back">返回</string>
<string name="ExitGames">退出游戏</string>
<string name="Settings">设置</string>
</resources> </resources>

View File

@ -3,10 +3,14 @@
<string name="CustomServer">Custom server</string> <string name="CustomServer">Custom server</string>
<string name="OfficialServer">Official server</string> <string name="OfficialServer">Official server</string>
<string name="SelectServer">Select server</string> <string name="SelectServer">Select server</string>
<string name="Tips">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: </string> <string name="Tips">For the first time, please enter the server address and enter the official server to download resources. Then you can enter the private server.</string>
<string name="ForcedMode">Forced mode (restart required)</string> <string name="ForcedMode">Forced mode (restart required)</string>
<string name="ServerAddressError">Server address error.</string> <string name="ServerAddressError">Server address error.</string>
<string name="ProxyList">Only addresses in the proxy list (restart required)</string> <string name="ProxyList">Only addresses in the proxy list (restart required)</string>
<string name="EnableTools">Enable tools</string> <string name="EnableTools">Enable tools</string>
<string name="HookConfig">Hook profile? (restart required)</string> <string name="HookConfig">Hook profile? (restart required)</string>
<string name="Tips2">Forced mode: Forced replacement of all domain names\n\nInput server address: </string>
<string name="Back">Back</string>
<string name="ExitGames">Exit games</string>
<string name="Settings">Settings</string>
</resources> </resources>