优化:主动控制·客户端历史列表增加设备名称远程发短信增加卡槽备注 #201

This commit is contained in:
pppscn 2022-08-08 15:50:46 +08:00
parent 432bbeaa16
commit 91b3cd11dc
6 changed files with 41 additions and 6 deletions

View File

@ -137,12 +137,18 @@ class ClientFragment : BaseFragment<FragmentClientBinding?>(),
}
Log.d(TAG, "serverHistory = $serverHistory")
MaterialDialog.Builder(context!!)
MaterialDialog.Builder(requireContext())
.title(R.string.server_history)
.items(serverHistory.keys)
.itemsCallbackSingleChoice(0) { _: MaterialDialog?, _: View?, _: Int, text: CharSequence ->
//XToastUtils.info("$which: $text")
binding!!.etServerAddress.setText(text)
val matches = Regex("【(.*)】(.*)", RegexOption.IGNORE_CASE).findAll(text).toList().flatMap(MatchResult::groupValues)
Log.i(TAG, "matches = $matches")
if (matches.isNotEmpty()) {
binding!!.etServerAddress.setText(matches[2])
} else {
binding!!.etServerAddress.setText(text)
}
binding!!.etSignKey.setText(serverHistory[text])
true // allow selection
}
@ -241,9 +247,13 @@ class ClientFragment : BaseFragment<FragmentClientBinding?>(),
if (resp.code == 200) {
serverConfig = resp.data!!
if (needToast) XToastUtils.success(ResUtils.getString(R.string.request_succeeded))
//删除3.0.8之前保存的记录
serverHistory.remove(HttpServerUtils.serverAddress.toString())
//添加到历史记录
serverHistory[HttpServerUtils.serverAddress.toString()] = HttpServerUtils.clientSignKey ?: ""
val key = "${serverConfig?.extraDeviceMark}${HttpServerUtils.serverAddress.toString()}"
serverHistory[key] = HttpServerUtils.clientSignKey ?: ""
HttpServerUtils.serverHistory = Gson().toJson(serverHistory)
HttpServerUtils.serverConfig = Gson().toJson(serverConfig)
} else {
if (needToast) XToastUtils.error(ResUtils.getString(R.string.request_failed) + resp.msg)
}

View File

@ -10,6 +10,7 @@ import com.idormy.sms.forwarder.R
import com.idormy.sms.forwarder.core.BaseFragment
import com.idormy.sms.forwarder.databinding.FragmentClientSmsSendBinding
import com.idormy.sms.forwarder.server.model.BaseResponse
import com.idormy.sms.forwarder.server.model.ConfigData
import com.idormy.sms.forwarder.utils.*
import com.jeremyliao.liveeventbus.LiveEventBus
import com.xuexiang.xaop.annotation.SingleClick
@ -56,6 +57,14 @@ class SmsSendFragment : BaseFragment<FragmentClientSmsSendBinding?>(), View.OnCl
binding!!.btnSubmit.text = getString(R.string.send)
}
})
//卡槽信息
val serverConfigStr = HttpServerUtils.serverConfig
if (!TextUtils.isEmpty(serverConfigStr)) {
val serverConfig: ConfigData = Gson().fromJson(serverConfigStr, object : TypeToken<ConfigData>() {}.type)
binding!!.rbSimSlot1.text = "SIM1" + serverConfig.extraSim1
binding!!.rbSimSlot2.text = "SIM2" + serverConfig.extraSim2
}
}
override fun initListeners() {

View File

@ -245,6 +245,7 @@ const val SP_ENABLE_API_WOL = "enable_api_wol"
const val SP_WOL_HISTORY = "wol_history"
const val SP_SERVER_ADDRESS = "server_address"
const val SP_SERVER_HISTORY = "server_history"
const val SP_SERVER_CONFIG = "server_config"
const val SP_CLIENT_SIGN_KEY = "client_sign_key"
var CLIENT_FRAGMENT_LIST = listOf(
PageInfo(getString(R.string.api_clone), "com.idormy.sms.forwarder.fragment.client.CloneFragment", "{\"\":\"\"}", CoreAnim.slide, R.drawable.icon_api_clone),

View File

@ -56,6 +56,14 @@ class HttpServerUtils private constructor() {
MMKVUtils.put(SP_SERVER_HISTORY, serverHistory)
}
//服务端配置
@JvmStatic
var serverConfig: String?
get() = MMKVUtils.getString(SP_SERVER_CONFIG, "")
set(serverConfig) {
MMKVUtils.put(SP_SERVER_CONFIG, serverConfig)
}
//客户端签名密钥
@JvmStatic
var clientSignKey: String?

View File

@ -41,17 +41,17 @@
<RadioGroup
android:id="@+id/rg_sim_slot"
style="@style/rg_style"
android:orientation="horizontal">
android:orientation="vertical">
<RadioButton
android:id="@+id/rb_sim_slot_1"
style="@style/rg_rb_style"
style="@style/rg_rb_style_match"
android:checked="true"
android:text="@string/sim1" />
<RadioButton
android:id="@+id/rb_sim_slot_2"
style="@style/rg_rb_style"
style="@style/rg_rb_style_match"
android:text="@string/sim2" />
</RadioGroup>

View File

@ -191,4 +191,11 @@
<item name="android:textSize">13sp</item>
</style>
<style name="rg_rb_style_match">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:singleLine">true</item>
<item name="android:textSize">13sp</item>
</style>
</resources>