浏览代码

1.将socket消息处理放在主页中。

master
wangwanlei 11 个月前
父节点
当前提交
63c3468bf0

+ 0
- 60
app/src/main/java/com/xhly/manageapp/service/websocket/AppSocket.kt 查看文件

@@ -40,7 +40,6 @@ import java.util.UUID
40 40
 class AppSocket : SocketClient() {
41 41
     var logService = RetrofitService.create<LogService>()
42 42
     private val serviceScope = CoroutineScope(MainScope().coroutineContext)
43
-    private var appList = arrayListOf<AppInfo>()
44 43
 
45 44
 
46 45
     val spUtils by lazy { SharedPreferencesUtils.getInstance(context) }
@@ -51,11 +50,9 @@ class AppSocket : SocketClient() {
51 50
     }
52 51
 
53 52
     override fun startSocket(context: Context?) {
54
-        EventBus.getDefault().register(this)
55 53
         connectUrl = Const.WSURL
56 54
         /* startNotification()*/
57 55
         LogShow("已经创建")
58
-        appList = AppUtils.GetAppList(context) as ArrayList<AppInfo>
59 56
         //downLoadFile("")
60 57
         super.startSocket(context)
61 58
     }
@@ -85,67 +82,10 @@ class AppSocket : SocketClient() {
85 82
         WebSocketHelper.getInstance().sendSocketString(GsonUtils.parseClassToJson(webData))
86 83
     }
87 84
 
88
-    @Subscribe(threadMode = ThreadMode.MAIN)
89
-    fun onUiEvent(uiEvent: UIEvent) {
90
-        when (uiEvent.event) {
91
-            Const.CODE2001.toString() -> {
92
-                Toast.makeText(context, "这就是新消息", Toast.LENGTH_LONG).show()
93
-            }
94
-
95
-            Const.CODE2002.toString() -> {
96
-                Toast.makeText(context, "限制使用", Toast.LENGTH_LONG).show()
97
-                spUtils.setParam(Const.DISABLEPAD, true)
98
-                goMainActivity()
99
-            }
100
-
101
-            Const.CODE2003.toString() -> {
102
-                Toast.makeText(context, "解除限制", Toast.LENGTH_LONG).show()
103
-                spUtils.setParam(Const.DISABLEPAD, false)
104
-                goMainActivity()
105
-            }
106
-
107
-            Const.CODE2004.toString() -> {
108
-               //请求接口更新策略
109
-            }
110
-
111
-            Const.CODE2005.toString() -> {
112
-                ManageApplication.rebootDevice()
113
-            }
114
-
115
-            Const.CODE2006.toString() -> {
116
-                ManageApplication.launchFactoryReset()
117
-            }
118
-
119
-        }
120
-    }
121
-
122
-    private fun goMainActivity() {
123
-        try {
124
-            // 为应用程序的启动Activity 准备Intent
125
-            val launchIntent = Intent()
126
-            launchIntent.setComponent(
127
-                ComponentName(
128
-                    "com.xhly.manageapp",
129
-                    "com.xhly.manageapp.ui.MainActivity"
130
-                )
131
-            )
132
-            launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
133
-            context.startActivity(launchIntent)
134
-        } catch (e: Exception) {
135
-            LogShow("跳转失败$e")
136
-        }
137
-    }
138 85
 
139
-    //用来发送事件日志
140
-    private fun eventLog(operateBean: LogdOperateBean) {
141
-        serviceScope.launch {
142
-            logService.postLogdoperateAdd(operateBean)
143
-        }
144
-    }
145 86
 
146 87
     override fun onDestroy() {
147 88
         super.onDestroy()
148
-        EventBus.getDefault().unregister(this)
149 89
         serviceScope.cancel()
150 90
         /* stopForeground(Service.STOP_FOREGROUND_REMOVE)*/
151 91
         val intent = Intent()

+ 29
- 0
app/src/main/java/com/xhly/manageapp/ui/main/activity/MainActivity.kt 查看文件

@@ -93,6 +93,7 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
93 93
         viewModel.strategyData.observe(this) {
94 94
             spUtils.saveJson(Const.STRATEGYBEANKEY, it)
95 95
             StrategyUtils.setStrategy(it)
96
+            useTimeStrategy()
96 97
         }
97 98
         viewModel.appStrategyData.observe(this) {
98 99
             //存储app时间策略
@@ -306,6 +307,34 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
306 307
                 }
307 308
             }
308 309
 
310
+            Const.CODE2001.toString() -> {
311
+
312
+            }
313
+
314
+            Const.CODE2002.toString() -> {
315
+                spUtils.setParam(Const.DISABLEPAD, true)
316
+                useTimeStrategy()
317
+            }
318
+
319
+            Const.CODE2003.toString() -> {
320
+                spUtils.setParam(Const.DISABLEPAD, false)
321
+                useTimeStrategy()
322
+            }
323
+
324
+            Const.CODE2004.toString() -> {
325
+                //请求接口更新策略
326
+                viewModel.uploadAppStrategy()
327
+                viewModel.updateStrategy()
328
+            }
329
+
330
+            Const.CODE2005.toString() -> {
331
+                ManageApplication.rebootDevice()
332
+            }
333
+
334
+            Const.CODE2006.toString() -> {
335
+                ManageApplication.launchFactoryReset()
336
+            }
337
+
309 338
             Const.LOGAPPSTART -> {
310 339
                 val message = uiEvent.message
311 340
                 if (AppSocket.lastPkgName == message) {

正在加载...
取消
保存