Browse Source

1.当socket消息为999时重连socket。

2025_1_7x505f
wangwanlei 1 month ago
parent
commit
fa65618678

+ 5
- 1
app/src/main/java/com/xhly/manageapp/ui/main/activity/MainActivity.kt View File

633
             viewModel.autoAppData.collect {
633
             viewModel.autoAppData.collect {
634
                 lifecycleScope.launch {
634
                 lifecycleScope.launch {
635
                     withContext(Dispatchers.IO){
635
                     withContext(Dispatchers.IO){
636
-                        delay(10000)
636
+                        delay(15000)
637
                     }
637
                     }
638
                     mBinding.flayoutRoot.visibility = View.GONE
638
                     mBinding.flayoutRoot.visibility = View.GONE
639
                 }
639
                 }
1711
                 viewModel.postExitReseted(sn)
1711
                 viewModel.postExitReseted(sn)
1712
                 startIntentActivity(MainActivity().javaClass)
1712
                 startIntentActivity(MainActivity().javaClass)
1713
             }
1713
             }
1714
+            Const.CODE999.toString()->{
1715
+                viewModel.postSyncTime(true)
1716
+            }
1714
 
1717
 
1715
             Const.INSTALL_FORCEAPP -> {
1718
             Const.INSTALL_FORCEAPP -> {
1716
                 ManageApplication.installPackage(uiEvent.message)
1719
                 ManageApplication.installPackage(uiEvent.message)
1756
 
1759
 
1757
             Const.STARTLOCATION -> {
1760
             Const.STARTLOCATION -> {
1758
                 getLocation()
1761
                 getLocation()
1762
+                updateAllStrategy()
1759
             }
1763
             }
1760
 
1764
 
1761
             Const.THIRDLOGINSUCCESS -> {
1765
             Const.THIRDLOGINSUCCESS -> {

+ 6
- 1
app/src/main/java/com/xhly/manageapp/viewmodel/BaseViewModel.kt View File

3
 import android.app.usage.UsageEvents.Event
3
 import android.app.usage.UsageEvents.Event
4
 import androidx.lifecycle.LiveData
4
 import androidx.lifecycle.LiveData
5
 import androidx.lifecycle.MutableLiveData
5
 import androidx.lifecycle.MutableLiveData
6
+import com.xhly.corelib.Const
6
 import com.xhly.corelib.base.viewmodel.CommonBaseViewModel
7
 import com.xhly.corelib.base.viewmodel.CommonBaseViewModel
8
+import com.xhly.corelib.eventbus.UIEvent
7
 import com.xhly.corelib.network.RetrofitService
9
 import com.xhly.corelib.network.RetrofitService
8
 import com.xhly.corelib.utils.LogShow
10
 import com.xhly.corelib.utils.LogShow
9
 import com.xhly.corelib.utils.MD5Utils
11
 import com.xhly.corelib.utils.MD5Utils
176
     /**
178
     /**
177
      * 同步服务器的时间
179
      * 同步服务器的时间
178
      */
180
      */
179
-    fun postSyncTime() {
181
+    fun postSyncTime(resetAppSocket:Boolean=false) {
180
         launchUI {
182
         launchUI {
181
             val startTime = System.currentTimeMillis()
183
             val startTime = System.currentTimeMillis()
182
             val postSyncTime = loginService.postSyncTime()
184
             val postSyncTime = loginService.postSyncTime()
188
                 LogShow("设置的时间是"+SystemClock.getDateString(l))
190
                 LogShow("设置的时间是"+SystemClock.getDateString(l))
189
                 /*timeResult.value = l*/
191
                 /*timeResult.value = l*/
190
                 timeResult.value = obj
192
                 timeResult.value = obj
193
+                if (resetAppSocket){
194
+                    UIEvent(Const.STARTSOCKET).post()
195
+                }
191
             } else {
196
             } else {
192
                 if (!postSyncTime.msg.isNullOrEmpty()) {
197
                 if (!postSyncTime.msg.isNullOrEmpty()) {
193
                     netMessage.value = postSyncTime.msg
198
                     netMessage.value = postSyncTime.msg

+ 2
- 1
websocket/src/main/java/com/xhly/websocket/utils/SocketPushUtils.kt View File

88
                     }
88
                     }
89
 
89
 
90
                     999 -> {
90
                     999 -> {
91
-                        //错误消息 body msg(错误消息)
91
+                        //错误消息 body msg(错误消息),重新连接socket
92
+                        UIEvent(Const.CODE999.toString()).post()
92
                     }
93
                     }
93
 
94
 
94
                     else -> {
95
                     else -> {

Loading…
Cancel
Save