|
@@ -175,6 +175,8 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(), Downloa
|
175
|
175
|
|
176
|
176
|
//判断是否在onresume状态
|
177
|
177
|
private var isResumeFlag = true
|
|
178
|
+ //判断是否在onDestroy状态
|
|
179
|
+ private var isDestroyFlag=false
|
178
|
180
|
//执行了自启请求
|
179
|
181
|
private var netAutoAppFlag=false
|
180
|
182
|
|
|
@@ -579,59 +581,65 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(), Downloa
|
579
|
581
|
}
|
580
|
582
|
|
581
|
583
|
viewModel.viewModelScope.launch {
|
582
|
|
- viewModel.autoAppData.collect {
|
583
|
|
- it?.let {
|
584
|
|
- if (!netAutoAppFlag){
|
585
|
|
- return@collect
|
586
|
|
- }else{
|
587
|
|
- netAutoAppFlag=false
|
588
|
|
- }
|
589
|
|
- //连接不为空,并且应用已安装则跳转应用
|
590
|
|
- /* it.authUrl="com.xhkjedu.xh_control_browser.MainActivity"
|
591
|
|
- it.appPackage="com.xhkjedu.xh_control_browser"*/
|
592
|
|
- LogShow("锁定了吧" + mainLockFlag)
|
593
|
|
- //未锁定则执行跳转,锁定则跳转主页再次锁定并且不在请求接口
|
594
|
|
- if (!mainLockFlag) {
|
595
|
|
- //如果地址为空并且请求为true则不跳转,否则跳转
|
596
|
|
- try {
|
597
|
|
- if ((it.authUrl.isNullOrEmpty()||it.appPackage.isNullOrEmpty())&&it.netSucessFlag){
|
598
|
|
- //请求成功但地址为空,不跳转
|
599
|
|
- canClickFlag = true
|
600
|
|
- autoAppFlag = false
|
601
|
|
- spUtils.saveJson(Const.AUTOAPPKEY, it)
|
602
|
|
- } else if ((!it.authUrl.isNullOrEmpty()&&!it.appPackage.isNullOrEmpty()) && AppUtils.isAppInstalled(this@MainActivity, it.appPackage)) {
|
603
|
|
- //请求成功地址不为空,并且安装了跳转
|
604
|
|
- spUtils.saveJson(Const.AUTOAPPKEY, it)
|
605
|
|
- LogShow("打开app拉起111")
|
606
|
|
- startAutoApp(it)
|
607
|
|
- } else if (!it.netSucessFlag){
|
608
|
|
- //请求失败走缓存
|
609
|
|
- val autoAppBean = spUtils.getFromJson(
|
610
|
|
- Const.AUTOAPPKEY,
|
611
|
|
- AutoAppBean().javaClass
|
612
|
|
- ) as AutoAppBean
|
613
|
|
- if ((!autoAppBean.authUrl.isNullOrEmpty()&&!autoAppBean.appPackage.isNullOrEmpty())&&
|
614
|
|
- AppUtils.isAppInstalled(this@MainActivity, autoAppBean.appPackage) && !it.netSucessFlag) {
|
615
|
|
- //缓存地址不为空,并且安装了则跳转
|
616
|
|
- LogShow("打开app拉起222")
|
617
|
|
- startAutoApp(autoAppBean)
|
618
|
|
- } else {
|
619
|
|
- //其余情况都允许触控
|
|
584
|
+ lifecycleScope.launch {
|
|
585
|
+ withContext(Dispatchers.IO){
|
|
586
|
+ delay(2000)
|
|
587
|
+ }
|
|
588
|
+ viewModel.autoAppData.collect {
|
|
589
|
+ it?.let {
|
|
590
|
+ if (!netAutoAppFlag||isDestroyFlag){
|
|
591
|
+ return@collect
|
|
592
|
+ }else{
|
|
593
|
+ netAutoAppFlag=false
|
|
594
|
+ }
|
|
595
|
+ //连接不为空,并且应用已安装则跳转应用
|
|
596
|
+ /* it.authUrl="com.xhkjedu.xh_control_browser.MainActivity"
|
|
597
|
+ it.appPackage="com.xhkjedu.xh_control_browser"*/
|
|
598
|
+ LogShow("锁定了吧" + mainLockFlag)
|
|
599
|
+ //未锁定则执行跳转,锁定则跳转主页再次锁定并且不在请求接口
|
|
600
|
+ if (!mainLockFlag) {
|
|
601
|
+ //如果地址为空并且请求为true则不跳转,否则跳转
|
|
602
|
+ try {
|
|
603
|
+ if ((it.authUrl.isNullOrEmpty()||it.appPackage.isNullOrEmpty())&&it.netSucessFlag){
|
|
604
|
+ //请求成功但地址为空,不跳转
|
|
605
|
+ canClickFlag = true
|
|
606
|
+ autoAppFlag = false
|
|
607
|
+ spUtils.saveJson(Const.AUTOAPPKEY, it)
|
|
608
|
+ } else if ((!it.authUrl.isNullOrEmpty()&&!it.appPackage.isNullOrEmpty()) && AppUtils.isAppInstalled(this@MainActivity, it.appPackage)) {
|
|
609
|
+ //请求成功地址不为空,并且安装了跳转
|
|
610
|
+ spUtils.saveJson(Const.AUTOAPPKEY, it)
|
|
611
|
+ LogShow("打开app拉起111")
|
|
612
|
+ startAutoApp(it)
|
|
613
|
+ } else if (!it.netSucessFlag){
|
|
614
|
+ //请求失败走缓存
|
|
615
|
+ val autoAppBean = spUtils.getFromJson(
|
|
616
|
+ Const.AUTOAPPKEY,
|
|
617
|
+ AutoAppBean().javaClass
|
|
618
|
+ ) as AutoAppBean
|
|
619
|
+ if ((!autoAppBean.authUrl.isNullOrEmpty()&&!autoAppBean.appPackage.isNullOrEmpty())&&
|
|
620
|
+ AppUtils.isAppInstalled(this@MainActivity, autoAppBean.appPackage) && !it.netSucessFlag) {
|
|
621
|
+ //缓存地址不为空,并且安装了则跳转
|
|
622
|
+ LogShow("打开app拉起222")
|
|
623
|
+ startAutoApp(autoAppBean)
|
|
624
|
+ } else {
|
|
625
|
+ //其余情况都允许触控
|
|
626
|
+ canClickFlag = true
|
|
627
|
+ }
|
|
628
|
+ }else{
|
620
|
629
|
canClickFlag = true
|
621
|
630
|
}
|
622
|
|
- }else{
|
|
631
|
+ } catch (e: Exception) {
|
623
|
632
|
canClickFlag = true
|
624
|
633
|
}
|
625
|
|
- } catch (e: Exception) {
|
|
634
|
+ } else {
|
626
|
635
|
canClickFlag = true
|
|
636
|
+ autoAppFlag = false
|
|
637
|
+ startIntentActivity(MainActivity().javaClass)
|
627
|
638
|
}
|
628
|
|
- } else {
|
629
|
|
- canClickFlag = true
|
630
|
|
- autoAppFlag = false
|
631
|
|
- startIntentActivity(MainActivity().javaClass)
|
632
|
|
- }
|
633
|
639
|
|
|
640
|
+ }
|
634
|
641
|
}
|
|
642
|
+
|
635
|
643
|
}
|
636
|
644
|
}
|
637
|
645
|
viewModel.timeResultData.observe(this) {
|
|
@@ -649,6 +657,7 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(), Downloa
|
649
|
657
|
|
650
|
658
|
lifecycleScope.launch {
|
651
|
659
|
isCreatFlag = true
|
|
660
|
+ isDestroyFlag=false
|
652
|
661
|
withContext(Dispatchers.IO){
|
653
|
662
|
delay(2000)
|
654
|
663
|
}
|
|
@@ -690,6 +699,9 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(), Downloa
|
690
|
699
|
val parseClassToJson = GsonUtils.parseClassToJson(it)
|
691
|
700
|
launchIntent.putExtra("authData", parseClassToJson)
|
692
|
701
|
}
|
|
702
|
+ if (isDestroyFlag){
|
|
703
|
+ return
|
|
704
|
+ }
|
693
|
705
|
startActivity(launchIntent)
|
694
|
706
|
} catch (e: Exception) {
|
695
|
707
|
canClickFlag = true
|
|
@@ -2084,9 +2096,17 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(), Downloa
|
2084
|
2096
|
|
2085
|
2097
|
override fun onDestroy() {
|
2086
|
2098
|
super.onDestroy()
|
|
2099
|
+ isDestroyFlag=true
|
2087
|
2100
|
if (timer != null) {
|
2088
|
2101
|
timer?.cancel()
|
2089
|
2102
|
timer = null
|
|
2103
|
+ }
|
|
2104
|
+ try {
|
|
2105
|
+ //销毁时清除所有缓存
|
|
2106
|
+ val appList = AppUtils.GetAppList(this@MainActivity)
|
|
2107
|
+ StrategyUtils.clearMemory(this@MainActivity, appList)
|
|
2108
|
+ }catch (e:Exception){
|
|
2109
|
+
|
2090
|
2110
|
}
|
2091
|
2111
|
locationClient?.stop()
|
2092
|
2112
|
AppSocket.onDestroy()
|