|
@@ -56,6 +56,8 @@ import com.xhly.manageapp.utils.StrategyUtils
|
56
|
56
|
import com.xhly.manageapp.workmanager.TimingWorker
|
57
|
57
|
import kotlinx.coroutines.launch
|
58
|
58
|
import java.util.Calendar
|
|
59
|
+import java.util.Timer
|
|
60
|
+import java.util.TimerTask
|
59
|
61
|
import java.util.concurrent.TimeUnit
|
60
|
62
|
|
61
|
63
|
|
|
@@ -65,6 +67,7 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
|
65
|
67
|
private var mMyInstallReceiver: AppInstallReceiver? = null
|
66
|
68
|
private var dataList: ArrayList<AppInfo> = arrayListOf()
|
67
|
69
|
private var userBean: UserBean? = null
|
|
70
|
+ private var timer: Timer?=null
|
68
|
71
|
override fun getBinding() = ActivityMainBinding.inflate(layoutInflater)
|
69
|
72
|
|
70
|
73
|
override fun initData() {
|
|
@@ -83,8 +86,7 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
|
83
|
86
|
mBinding.btn.setOnClickListener {
|
84
|
87
|
startIntentActivity(ManageActivity().javaClass)
|
85
|
88
|
}
|
86
|
|
- registerAppInstallReceiver()
|
87
|
|
- /*
|
|
89
|
+ registerAppInstallReceiver()/*
|
88
|
90
|
使用情况权限
|
89
|
91
|
val permissionIntent = Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS)
|
90
|
92
|
startActivity(permissionIntent)*/
|
|
@@ -147,17 +149,19 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
|
147
|
149
|
}
|
148
|
150
|
viewModel.updateInfoData.observe(this) {
|
149
|
151
|
//成功则保存不在提交
|
150
|
|
- if (it){
|
151
|
|
- spUtils.setParam(Const.PADUPDATETIMEKEY,System.currentTimeMillis())
|
|
152
|
+ if (it) {
|
|
153
|
+ spUtils.setParam(Const.PADUPDATETIMEKEY, System.currentTimeMillis())
|
152
|
154
|
}
|
153
|
155
|
}
|
154
|
|
- viewModel.schoolSetData.observe(this){
|
155
|
|
- spUtils.saveJson(Const.SCHOOLSETDEVICE,it)
|
|
156
|
+ viewModel.schoolSetData.observe(this) {
|
|
157
|
+ spUtils.saveJson(Const.SCHOOLSETDEVICE, it)
|
|
158
|
+ initSchoolSet(it)
|
156
|
159
|
updateAppRv()
|
157
|
160
|
}
|
158
|
161
|
startWorkManager()
|
159
|
162
|
}
|
160
|
163
|
|
|
164
|
+
|
161
|
165
|
override fun onNewIntent(intent: Intent?) {
|
162
|
166
|
super.onNewIntent(intent)
|
163
|
167
|
}
|
|
@@ -200,12 +204,6 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
|
200
|
204
|
updatePadInfo()
|
201
|
205
|
updateMcApp()
|
202
|
206
|
getLocation()
|
203
|
|
- try {
|
204
|
|
- var s =
|
205
|
|
- "厂商" + CustomOSUtils.getSystemBrand() + ",型号" + CustomOSUtils.getSystemDevice() + ",系统版本" + CustomOSUtils.getSystemDisplay()
|
206
|
|
- } catch (e: Exception) {
|
207
|
|
- LogShow("没有数据")
|
208
|
|
- }
|
209
|
207
|
}
|
210
|
208
|
|
211
|
209
|
private fun updateMcApp() {
|
|
@@ -274,8 +272,7 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
|
274
|
272
|
private fun getLocation() {
|
275
|
273
|
val rxPermissions = RxPermissions(this)
|
276
|
274
|
rxPermissions.request(
|
277
|
|
- Manifest.permission.ACCESS_FINE_LOCATION,
|
278
|
|
- Manifest.permission.ACCESS_COARSE_LOCATION
|
|
275
|
+ Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION
|
279
|
276
|
).subscribe({
|
280
|
277
|
if (it) {
|
281
|
278
|
SystemUtil.getLocation(this)
|
|
@@ -343,6 +340,52 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
|
343
|
340
|
ManageApplication.removeInstallPackageWhiteList(removeList)*/
|
344
|
341
|
}
|
345
|
342
|
|
|
343
|
+ private fun initSchoolSet(schoolDeviceSetBean: SchoolDeviceSetBean? = null) {
|
|
344
|
+ schoolDeviceSetBean?.let {bean->
|
|
345
|
+ //是否启用截屏:1是0否
|
|
346
|
+ ManageApplication.enableCaptureScreen(schoolDeviceSetBean.screenshots == 1)
|
|
347
|
+ if (bean.forceBind == 1) {
|
|
348
|
+ //TODO 设备端如何操作
|
|
349
|
+ }
|
|
350
|
+ if (bean.schoolClass == 1) {
|
|
351
|
+ mBinding.userschoolTv.visibility = View.VISIBLE
|
|
352
|
+ } else {
|
|
353
|
+ mBinding.userschoolTv.visibility = View.INVISIBLE
|
|
354
|
+ }
|
|
355
|
+ //设置护眼模式
|
|
356
|
+ CustomOSUtils.openOrCloseNightMode(this, bean.protectedEyes == 1)
|
|
357
|
+ startTimeTask(bean)
|
|
358
|
+ }
|
|
359
|
+ }
|
|
360
|
+
|
|
361
|
+ private fun startTimeTask(bean: SchoolDeviceSetBean) {
|
|
362
|
+ if (bean.remindDuration==1){
|
|
363
|
+ //如果设置的有时间则执行任务
|
|
364
|
+ if (timer==null){
|
|
365
|
+ timer= Timer()
|
|
366
|
+ }else{
|
|
367
|
+ timer?.cancel()
|
|
368
|
+ }
|
|
369
|
+ timer?.let {
|
|
370
|
+ timer?.schedule( object : TimerTask() {
|
|
371
|
+ override fun run() {
|
|
372
|
+ // 在这里编写您的定时任务代码
|
|
373
|
+ Toast(getString(R.string.durationtips))
|
|
374
|
+ startTimeTask(bean)
|
|
375
|
+ }
|
|
376
|
+ },0L,bean.duration*60*1000L)
|
|
377
|
+ }
|
|
378
|
+ }
|
|
379
|
+ //如果设置的有时间则取消所有任务
|
|
380
|
+ if (bean.remindDuration!=1){
|
|
381
|
+ if (timer!=null){
|
|
382
|
+ timer?.cancel()
|
|
383
|
+ timer=null
|
|
384
|
+ }
|
|
385
|
+ }
|
|
386
|
+ }
|
|
387
|
+
|
|
388
|
+
|
346
|
389
|
override fun onUiEvent(uiEvent: UIEvent) {
|
347
|
390
|
super.onUiEvent(uiEvent)
|
348
|
391
|
when (uiEvent.getEvent()) {
|
|
@@ -474,21 +517,13 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
|
474
|
517
|
|
475
|
518
|
private fun updateAppRv() {
|
476
|
519
|
try {
|
477
|
|
- var schoolDeviceSetBean:SchoolDeviceSetBean?=null
|
478
|
|
- try {
|
479
|
|
- val beanStr =
|
480
|
|
- spUtils.getFromJson(Const.SCHOOLSETDEVICE, SchoolDeviceSetBean().javaClass)
|
481
|
|
- if (beanStr!=null){
|
482
|
|
- schoolDeviceSetBean=beanStr as SchoolDeviceSetBean
|
483
|
|
- }
|
484
|
|
- }catch (e:Exception){
|
485
|
|
- //为了不影响列表显示
|
486
|
|
- }
|
|
520
|
+ var schoolDeviceSetBean: SchoolDeviceSetBean? = null
|
|
521
|
+ schoolDeviceSetBean = StrategyUtils.getSchoolDeviceSetBean(this)
|
487
|
522
|
dataList.clear()
|
488
|
523
|
var appList = AppUtils.GetAppList(this)
|
489
|
524
|
appList.addAll(CustomAppUtils().getCustomAppList(this))
|
490
|
|
- if (schoolDeviceSetBean!=null){
|
491
|
|
- appList=StrategyUtils.setSchoolSetDevice(schoolDeviceSetBean,appList)
|
|
525
|
+ if (schoolDeviceSetBean != null) {
|
|
526
|
+ appList = StrategyUtils.setSchoolSetDevice(schoolDeviceSetBean, appList)
|
492
|
527
|
}
|
493
|
528
|
dataList.addAll(appList)
|
494
|
529
|
if (adapter == null) {
|
|
@@ -559,8 +594,7 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
|
559
|
594
|
dialog.dismiss()
|
560
|
595
|
try {
|
561
|
596
|
val userBean = spUtils.getFromJson(
|
562
|
|
- Const.USERINFO,
|
563
|
|
- UserBean().javaClass
|
|
597
|
+ Const.USERINFO, UserBean().javaClass
|
564
|
598
|
) as UserBean
|
565
|
599
|
viewModel.loginOut(userBean.userid.toString(), code.toString())
|
566
|
600
|
} catch (e: Exception) {
|
|
@@ -584,11 +618,9 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
|
584
|
618
|
val titleTv = v.findViewById<TextView>(R.id.dialog_title_tv)
|
585
|
619
|
val contentTv = v.findViewById<TextView>(R.id.dialog_content_tv)
|
586
|
620
|
try {
|
587
|
|
- val msgBean =
|
588
|
|
- GsonUtils.parseJsonWithGson(
|
589
|
|
- msg,
|
590
|
|
- SocketMsgBean().javaClass
|
591
|
|
- ) as SocketMsgBean
|
|
621
|
+ val msgBean = GsonUtils.parseJsonWithGson(
|
|
622
|
+ msg, SocketMsgBean().javaClass
|
|
623
|
+ ) as SocketMsgBean
|
592
|
624
|
titleTv.text = msgBean.title
|
593
|
625
|
contentTv.text = msgBean.content
|
594
|
626
|
} catch (e: Exception) {
|
|
@@ -612,6 +644,10 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
|
612
|
644
|
|
613
|
645
|
override fun onDestroy() {
|
614
|
646
|
super.onDestroy()
|
|
647
|
+ if (timer!=null){
|
|
648
|
+ timer?.cancel()
|
|
649
|
+ timer=null
|
|
650
|
+ }
|
615
|
651
|
mMyInstallReceiver?.let {
|
616
|
652
|
unregisterReceiver(it)
|
617
|
653
|
}
|