feat(设置): 添加服务器地址配置功能
添加服务器地址配置界面,允许用户自定义WebSocket服务器地址。包含输入验证,确保地址格式正确(ws://或wss://开头)。
This commit is contained in:
@@ -78,6 +78,8 @@ class SettingsAdvanceActivity : AppCompatActivity() {
|
|||||||
ll_corp_param.visibility = if (Constant.customLink) View.VISIBLE else View.GONE
|
ll_corp_param.visibility = if (Constant.customLink) View.VISIBLE else View.GONE
|
||||||
rl_username.visibility = if (Constant.customMP) View.VISIBLE else View.GONE
|
rl_username.visibility = if (Constant.customMP) View.VISIBLE else View.GONE
|
||||||
rl_qa_url.setOnClickListener { showQaUrlDialog() }
|
rl_qa_url.setOnClickListener { showQaUrlDialog() }
|
||||||
|
rl_host.setOnClickListener { showHostDialog() }
|
||||||
|
tv_select_host.text = Constant.host
|
||||||
rl_corp_name.setOnClickListener { showCorpNameDialog() }
|
rl_corp_name.setOnClickListener { showCorpNameDialog() }
|
||||||
rl_corp.setOnClickListener { showCorpIdDialog() }
|
rl_corp.setOnClickListener { showCorpIdDialog() }
|
||||||
rl_agent.setOnClickListener { showAgentIdDialog() }
|
rl_agent.setOnClickListener { showAgentIdDialog() }
|
||||||
@@ -117,6 +119,32 @@ class SettingsAdvanceActivity : AppCompatActivity() {
|
|||||||
.create(R.style.QMUI_Dialog).show()
|
.create(R.style.QMUI_Dialog).show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun showHostDialog() {
|
||||||
|
val builder = QMUIDialog.EditTextDialogBuilder(this)
|
||||||
|
builder.setTitle("服务器地址")
|
||||||
|
.setPlaceholder("请输入WebSocket服务器地址")
|
||||||
|
.setDefaultText(Constant.host)
|
||||||
|
.setInputType(InputType.TYPE_CLASS_TEXT)
|
||||||
|
.addAction(getString(R.string.cancel)) { dialog, index -> dialog.dismiss() }
|
||||||
|
.addAction(getString(R.string.add)) { dialog, index ->
|
||||||
|
val text = builder.editText.text
|
||||||
|
if (text != null && text.isNotEmpty()) {
|
||||||
|
val host = text.toString().trim()
|
||||||
|
if (host.matches("wss?://[^:]+:\\d+".toRegex())) {
|
||||||
|
dialog.dismiss()
|
||||||
|
Constant.host = host
|
||||||
|
tv_select_host.text = host
|
||||||
|
ToastUtils.showLong("服务器地址已更新")
|
||||||
|
} else {
|
||||||
|
ToastUtils.showLong("格式异常!示例: ws://192.168.1.1:18680")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ToastUtils.showLong("请勿为空!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.create(R.style.QMUI_Dialog).show()
|
||||||
|
}
|
||||||
|
|
||||||
private fun updateRobotQaUrl(callbackUrl: String) {
|
private fun updateRobotQaUrl(callbackUrl: String) {
|
||||||
try {
|
try {
|
||||||
val json = hashMapOf<String, Any>()
|
val json = hashMapOf<String, Any>()
|
||||||
|
|||||||
@@ -317,6 +317,53 @@
|
|||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
|
<RelativeLayout
|
||||||
|
android:id="@+id/rl_host"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingStart="@dimen/setting_start_padding"
|
||||||
|
android:paddingTop="@dimen/setting_vertical_padding"
|
||||||
|
android:paddingEnd="@dimen/setting_end_padding"
|
||||||
|
android:paddingBottom="@dimen/setting_vertical_padding">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tv_select_host"
|
||||||
|
android:layout_width="@dimen/setting_end_font_width"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentEnd="true"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
|
android:layout_marginStart="@dimen/setting_end_start_padding"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:textColor="@color/float_time_color"
|
||||||
|
android:textSize="@dimen/setting_end_font_size"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
|
android:layout_marginStart="@dimen/setting_start_padding"
|
||||||
|
android:layout_toStartOf="@id/tv_select_host"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="服务器地址"
|
||||||
|
android:textColor="@color/color_333333"
|
||||||
|
android:textSize="@dimen/setting_start_font_size" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="WebSocket服务器地址(ws://或wss://开头)"
|
||||||
|
android:textColor="@color/color_999999"
|
||||||
|
android:textSize="@dimen/setting_end_font_size" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
</RelativeLayout>
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:id="@+id/rl_rec_orientation"
|
android:id="@+id/rl_rec_orientation"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|||||||
Reference in New Issue
Block a user