Browse Source

1.系统时间设置添加请求判断,只有请求了才设置时间,防止重复设置导致的socket断联。

20241218TB223FC(测试jar包)
wangwanlei 1 month ago
parent
commit
02d2f6b945

+ 7
- 4
app/src/main/java/com/xhly/manageapp/ui/login/activity/LoginActivity.kt View File

@@ -78,11 +78,14 @@ class LoginActivity : BaseActivity<LoginViewModel, ActivityLoginBinding>() {
78 78
             }
79 79
         }
80 80
         viewModel.timeResultData.observe(this){
81
-            ManageApplication.setSysTime(it)
82
-            if (syncTimeClickFlag){
83
-                Toast(getString(R.string.syncsucess))
81
+            if (SystemUtil.updateTimeFlag){
82
+                SystemUtil.updateTimeFlag=false
83
+                ManageApplication.setSysTime(it)
84
+                if (syncTimeClickFlag){
85
+                    Toast(getString(R.string.syncsucess))
86
+                }
87
+                syncTimeClickFlag=false
84 88
             }
85
-            syncTimeClickFlag=false
86 89
         }
87 90
         viewModel.controlResultData.observe(this){
88 91
             //为真则可以进入管理页面

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

@@ -90,6 +90,7 @@ import com.xhly.manageapp.utils.CustomAppUtils
90 90
 import com.xhly.manageapp.utils.InstallUtils
91 91
 import com.xhly.manageapp.utils.PadInfoUtils
92 92
 import com.xhly.manageapp.utils.StrategyUtils
93
+import com.xhly.manageapp.utils.SystemClock
93 94
 import com.xhly.manageapp.workmanager.TimingWorker
94 95
 import kotlinx.coroutines.Dispatchers
95 96
 import kotlinx.coroutines.delay
@@ -598,11 +599,15 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(), Downloa
598 599
             }
599 600
         }
600 601
         viewModel.timeResultData.observe(this) {
601
-            ManageApplication.setSysTime(it)
602
-            try {
603
-                tipsDialog?.dismiss()
604
-            }catch (e:Exception){
602
+            if (SystemUtil.updateTimeFlag){
603
+                SystemUtil.updateTimeFlag=false
604
+                ManageApplication.setSysTime(it)
605
+                LogShow("当前设置的时间是"+it+"|||"+SystemClock.getDateString(it))
606
+                try {
607
+                    tipsDialog?.dismiss()
608
+                }catch (e:Exception){
605 609
 
610
+                }
606 611
             }
607 612
         }
608 613
 

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

@@ -6,6 +6,7 @@ import com.xhly.corelib.base.viewmodel.CommonBaseViewModel
6 6
 import com.xhly.corelib.network.RetrofitService
7 7
 import com.xhly.corelib.utils.LogShow
8 8
 import com.xhly.corelib.utils.MD5Utils
9
+import com.xhly.corelib.utils.SystemUtil
9 10
 import com.xhly.manageapp.bean.log.LogEventBean
10 11
 import com.xhly.manageapp.bean.log.LogPushBean
11 12
 import com.xhly.manageapp.bean.log.LogPushResultBean
@@ -120,6 +121,7 @@ open class BaseViewModel : CommonBaseViewModel() {
120 121
             val startTime = System.currentTimeMillis()
121 122
             val postSyncTime = loginService.postSyncTime()
122 123
             if (postSyncTime.code == 0) {
124
+                SystemUtil.updateTimeFlag=true
123 125
                 val endTime = System.currentTimeMillis()
124 126
                 val obj = postSyncTime.obj
125 127
                 timeResult.value = obj + (endTime - startTime) / 2

+ 2
- 1
corelib/src/main/java/com/xhly/corelib/utils/SystemUtil.java View File

@@ -37,7 +37,8 @@ import java.util.Locale;
37 37
  * 邮箱:zhan_0313@163.com
38 38
  */
39 39
 public class SystemUtil {
40
-
40
+    //标记是否请求了时间,请求了才更新
41
+    public static boolean updateTimeFlag=false;
41 42
 
42 43
     /**
43 44
      * 获取当前手机系统语言。

Loading…
Cancel
Save