debug: 绑定页显示MQTT连接状态,未连接时自动重连
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -32,6 +32,7 @@ class BindFragment : BaseFragment<FragmentBindBinding>() {
|
|||||||
@Inject lateinit var devicePrefs: DevicePrefs
|
@Inject lateinit var devicePrefs: DevicePrefs
|
||||||
@Inject lateinit var eventBus: EventBus
|
@Inject lateinit var eventBus: EventBus
|
||||||
@Inject lateinit var gson: Gson
|
@Inject lateinit var gson: Gson
|
||||||
|
@Inject lateinit var mqttManager: com.xiaoqu.watch.service.manager.MqttManager
|
||||||
|
|
||||||
override fun createBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentBindBinding {
|
override fun createBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentBindBinding {
|
||||||
return FragmentBindBinding.inflate(inflater, container, false)
|
return FragmentBindBinding.inflate(inflater, container, false)
|
||||||
@@ -43,6 +44,9 @@ class BindFragment : BaseFragment<FragmentBindBinding>() {
|
|||||||
// 生成并显示二维码
|
// 生成并显示二维码
|
||||||
generateQrCode()
|
generateQrCode()
|
||||||
|
|
||||||
|
// 显示 MQTT 连接状态(调试用)
|
||||||
|
showMqttStatus()
|
||||||
|
|
||||||
// 绑定消息由 MainActivity 统一处理(Activity 级别,不受 Fragment 生命周期影响)
|
// 绑定消息由 MainActivity 统一处理(Activity 级别,不受 Fragment 生命周期影响)
|
||||||
// 这里只监听用于显示 Loading 状态
|
// 这里只监听用于显示 Loading 状态
|
||||||
observeBindEvent()
|
observeBindEvent()
|
||||||
@@ -158,4 +162,18 @@ class BindFragment : BaseFragment<FragmentBindBinding>() {
|
|||||||
binding.qrWrap.visibility = View.GONE
|
binding.qrWrap.visibility = View.GONE
|
||||||
binding.loadingWrap.visibility = View.VISIBLE
|
binding.loadingWrap.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 显示 MQTT 连接状态(调试用,确认扫码时连接是否正常) */
|
||||||
|
private fun showMqttStatus() {
|
||||||
|
val connected = mqttManager.isConnected
|
||||||
|
val imei = devicePrefs.imei
|
||||||
|
val msg = if (connected) "MQTT已连接 (IMEI=$imei)" else "MQTT未连接!"
|
||||||
|
android.widget.Toast.makeText(requireContext(), msg, android.widget.Toast.LENGTH_LONG).show()
|
||||||
|
Timber.d("绑定页: $msg")
|
||||||
|
|
||||||
|
// 未连接则尝试重连
|
||||||
|
if (!connected) {
|
||||||
|
mqttManager.connect()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user