|
@@ -7,23 +7,36 @@ import android.content.pm.PackageManager
|
7
|
7
|
import android.graphics.Color
|
8
|
8
|
import android.os.Build
|
9
|
9
|
import android.view.View
|
|
10
|
+import android.widget.Button
|
10
|
11
|
import android.widget.EditText
|
11
|
12
|
import android.widget.TextView
|
12
|
13
|
import androidx.activity.addCallback
|
|
14
|
+import androidx.work.PeriodicWorkRequest
|
|
15
|
+import androidx.work.WorkManager
|
13
|
16
|
import com.kongzue.dialogx.dialogs.CustomDialog
|
14
|
17
|
import com.kongzue.dialogx.interfaces.OnBindView
|
15
|
18
|
import com.tbruyelle.rxpermissions2.RxPermissions
|
16
|
19
|
import com.xhly.corelib.Const
|
|
20
|
+import com.xhly.corelib.eventbus.UIEvent
|
17
|
21
|
import com.xhly.corelib.utils.GsonUtils
|
|
22
|
+import com.xhly.corelib.utils.LogShow
|
18
|
23
|
import com.xhly.corelib.utils.SystemUtil
|
19
|
24
|
import com.xhly.manageapp.ManageApplication
|
20
|
25
|
import com.xhly.manageapp.R
|
|
26
|
+import com.xhly.manageapp.bean.EventLog
|
21
|
27
|
import com.xhly.manageapp.bean.LoginBean
|
|
28
|
+import com.xhly.manageapp.bean.SocketMsgBean
|
|
29
|
+import com.xhly.manageapp.bean.log.LogdOperateBean
|
|
30
|
+import com.xhly.manageapp.bean.strategy.StrategyBean
|
22
|
31
|
import com.xhly.manageapp.bean.user.UserBean
|
23
|
32
|
import com.xhly.manageapp.contentprovider.ZSpProvider
|
24
|
33
|
import com.xhly.manageapp.databinding.ActivityLoginBinding
|
|
34
|
+import com.xhly.manageapp.service.websocket.AppSocket
|
25
|
35
|
import com.xhly.manageapp.ui.login.viewmodel.LoginViewModel
|
26
|
36
|
import com.xhly.manageapp.ui.main.activity.MainActivity
|
|
37
|
+import com.xhly.manageapp.utils.StrategyUtils
|
|
38
|
+import com.xhly.manageapp.workmanager.TimingWorker
|
|
39
|
+import java.util.concurrent.TimeUnit
|
27
|
40
|
|
28
|
41
|
class LoginActivity : BaseActivity<LoginViewModel, ActivityLoginBinding>() {
|
29
|
42
|
private var regioncode = ""
|
|
@@ -39,6 +52,7 @@ class LoginActivity : BaseActivity<LoginViewModel, ActivityLoginBinding>() {
|
39
|
52
|
}
|
40
|
53
|
}
|
41
|
54
|
}
|
|
55
|
+ startWorkManager()
|
42
|
56
|
}
|
43
|
57
|
|
44
|
58
|
@SuppressLint("CheckResult")
|
|
@@ -120,4 +134,170 @@ class LoginActivity : BaseActivity<LoginViewModel, ActivityLoginBinding>() {
|
120
|
134
|
}).setCancelable(false).setMaskColor(Color.parseColor("#66000000"))
|
121
|
135
|
.setAlign(CustomDialog.ALIGN.CENTER).show()
|
122
|
136
|
}
|
|
137
|
+
|
|
138
|
+ override fun onUiEvent(uiEvent: UIEvent) {
|
|
139
|
+ super.onUiEvent(uiEvent)
|
|
140
|
+ when (uiEvent.getEvent()) {
|
|
141
|
+
|
|
142
|
+ Const.CODE2001.toString() -> {
|
|
143
|
+ val message = uiEvent.message
|
|
144
|
+ showNoticeDialog(message)
|
|
145
|
+ }
|
|
146
|
+
|
|
147
|
+ Const.CODE2002.toString() -> {
|
|
148
|
+ spUtils.setParam(Const.DISABLEPAD, true)
|
|
149
|
+ useTimeStrategy()
|
|
150
|
+ }
|
|
151
|
+
|
|
152
|
+ Const.CODE2003.toString() -> {
|
|
153
|
+ spUtils.setParam(Const.DISABLEPAD, false)
|
|
154
|
+ useTimeStrategy()
|
|
155
|
+ }
|
|
156
|
+
|
|
157
|
+ Const.CODE2004.toString() -> {
|
|
158
|
+
|
|
159
|
+ }
|
|
160
|
+
|
|
161
|
+ Const.CODE2005.toString() -> {
|
|
162
|
+ ManageApplication.rebootDevice()
|
|
163
|
+ }
|
|
164
|
+
|
|
165
|
+ Const.CODE2006.toString() -> {
|
|
166
|
+ ManageApplication.launchFactoryReset()
|
|
167
|
+ }
|
|
168
|
+
|
|
169
|
+ Const.CODE2007.toString() -> {
|
|
170
|
+
|
|
171
|
+ }
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+ Const.LOGAPPSTART -> {
|
|
175
|
+
|
|
176
|
+ }
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+ Const.SDINSTALL -> {
|
|
180
|
+ val data = LogdOperateBean()
|
|
181
|
+ ManageApplication.getDeviceInfo()?.let {
|
|
182
|
+ data.sn = it
|
|
183
|
+ }
|
|
184
|
+ data.comm = "SD卡插入"
|
|
185
|
+ data.doEvent = EventLog.SDEMOUNTEDVENT
|
|
186
|
+ viewModel.eventLog(data)
|
|
187
|
+ }
|
|
188
|
+
|
|
189
|
+ Const.SDUNINSTALL -> {
|
|
190
|
+ val data = LogdOperateBean()
|
|
191
|
+ ManageApplication.getDeviceInfo()?.let {
|
|
192
|
+ data.sn = it
|
|
193
|
+ }
|
|
194
|
+ data.comm = "SD卡拔出"
|
|
195
|
+ data.doEvent = EventLog.SDEJECTEVENT
|
|
196
|
+ viewModel.eventLog(data)
|
|
197
|
+ }
|
|
198
|
+
|
|
199
|
+ Const.SIMINSTALL -> {
|
|
200
|
+ val data = LogdOperateBean()
|
|
201
|
+ ManageApplication.getDeviceInfo()?.let {
|
|
202
|
+ data.sn = it
|
|
203
|
+ }
|
|
204
|
+ data.comm = "SIM卡安装"
|
|
205
|
+ data.doEvent = EventLog.SIMEVENT
|
|
206
|
+ viewModel.eventLog(data)
|
|
207
|
+ }
|
|
208
|
+
|
|
209
|
+ Const.BLUETOOTHOPEN -> {
|
|
210
|
+ val data = LogdOperateBean()
|
|
211
|
+ ManageApplication.getDeviceInfo()?.let {
|
|
212
|
+ data.sn = it
|
|
213
|
+ }
|
|
214
|
+ data.comm = "蓝牙打开"
|
|
215
|
+ data.doEvent = EventLog.BLUETOOHEVENT
|
|
216
|
+ viewModel.eventLog(data)
|
|
217
|
+ }
|
|
218
|
+
|
|
219
|
+ Const.USB_CONNECTED -> {
|
|
220
|
+ val data = LogdOperateBean()
|
|
221
|
+ ManageApplication.getDeviceInfo()?.let {
|
|
222
|
+ data.sn = it
|
|
223
|
+ }
|
|
224
|
+ data.comm = "usb连接"
|
|
225
|
+ data.doEvent = EventLog.USBCONNECTEVENT
|
|
226
|
+ viewModel.eventLog(data)
|
|
227
|
+ }
|
|
228
|
+
|
|
229
|
+ Const.USB_NOCONNECTED -> {
|
|
230
|
+ val data = LogdOperateBean()
|
|
231
|
+ ManageApplication.getDeviceInfo()?.let {
|
|
232
|
+ data.sn = it
|
|
233
|
+ }
|
|
234
|
+ data.comm = "usb断开"
|
|
235
|
+ data.doEvent = EventLog.USBDISCONNECTEVENT
|
|
236
|
+ viewModel.eventLog(data)
|
|
237
|
+ }
|
|
238
|
+ }
|
|
239
|
+
|
|
240
|
+ }
|
|
241
|
+
|
|
242
|
+ private fun showNoticeDialog(msg: String) {
|
|
243
|
+ CustomDialog.build()
|
|
244
|
+ .setCustomView(object : OnBindView<CustomDialog>(R.layout.layout_notice_dialog) {
|
|
245
|
+ override fun onBind(dialog: CustomDialog, v: View) {
|
|
246
|
+ val closeBtn = v.findViewById<Button>(R.id.dialog_close_btn)
|
|
247
|
+ val titleTv = v.findViewById<TextView>(R.id.dialog_title_tv)
|
|
248
|
+ val contentTv = v.findViewById<TextView>(R.id.dialog_content_tv)
|
|
249
|
+ try {
|
|
250
|
+ val msgBean = GsonUtils.parseJsonWithGson(
|
|
251
|
+ msg, SocketMsgBean().javaClass
|
|
252
|
+ ) as SocketMsgBean
|
|
253
|
+ titleTv.text = msgBean.title
|
|
254
|
+ contentTv.text = msgBean.content
|
|
255
|
+ } catch (e: Exception) {
|
|
256
|
+ LogShow("解析失败"+e.toString())
|
|
257
|
+ }
|
|
258
|
+ closeBtn.setOnClickListener {
|
|
259
|
+ dialog.dismiss()
|
|
260
|
+ }
|
|
261
|
+ }
|
|
262
|
+ }).setCancelable(false).setMaskColor(Color.parseColor("#66000000"))
|
|
263
|
+ .setAlign(CustomDialog.ALIGN.CENTER).show()
|
|
264
|
+ }
|
|
265
|
+
|
|
266
|
+ private fun useTimeStrategy() {
|
|
267
|
+ //获得sputils中的平板锁定策略
|
|
268
|
+ try {
|
|
269
|
+ //如果存储的是锁定则锁定
|
|
270
|
+ val param = spUtils.getParam(Const.DISABLEPAD, false) as Boolean
|
|
271
|
+ if (param) {
|
|
272
|
+ mBinding.loginMainLlayout.visibility = View.GONE
|
|
273
|
+ mBinding.lockLlayout.visibility = View.VISIBLE
|
|
274
|
+ } else {
|
|
275
|
+ mBinding.loginMainLlayout.visibility = View.VISIBLE
|
|
276
|
+ mBinding.lockLlayout.visibility = View.GONE
|
|
277
|
+ }
|
|
278
|
+ } catch (e: Exception) {
|
|
279
|
+ val param = spUtils.getParam(Const.DISABLEPAD, false) as Boolean
|
|
280
|
+ if (param) {
|
|
281
|
+ mBinding.loginMainLlayout.visibility = View.GONE
|
|
282
|
+ mBinding.lockLlayout.visibility = View.VISIBLE
|
|
283
|
+ } else {
|
|
284
|
+ mBinding.loginMainLlayout.visibility = View.VISIBLE
|
|
285
|
+ mBinding.lockLlayout.visibility = View.GONE
|
|
286
|
+ }
|
|
287
|
+ }
|
|
288
|
+ }
|
|
289
|
+
|
|
290
|
+ private fun startWorkManager() {
|
|
291
|
+ WorkManager.getInstance(this).cancelAllWork()
|
|
292
|
+ // 周期性任务时间最少15分钟 所以除以实际周期的时间 看需要加入几个任务
|
|
293
|
+ val taskList = arrayListOf(0, 5, 10)
|
|
294
|
+ for (taskNo in taskList) {
|
|
295
|
+ val request = PeriodicWorkRequest
|
|
296
|
+ // 最少15分钟 PeriodicWorkRequest
|
|
297
|
+ .Builder(TimingWorker::class.java, 15, TimeUnit.MINUTES)
|
|
298
|
+ // WorkRequest 根据实际周期以及任务的编号 延迟初始化 0,5,10 分别周期行执行
|
|
299
|
+ .setInitialDelay(taskNo.toLong(), TimeUnit.MINUTES).build()
|
|
300
|
+ WorkManager.getInstance(this).enqueue(request)
|
|
301
|
+ }
|
|
302
|
+ }
|
123
|
303
|
}
|