소스 검색

1.设置更新策略的点击时间限制。

2.设置自动跳转应用接口,优先请求接口,接口出问题取本地数据,本地不存在,则按照没有跳转应用处理。
3.页面销毁时销毁socket
20241218TB223FC(测试jar包)
wangwanlei 9 달 전
부모
커밋
80b76f5d34

+ 7
- 2
app/src/main/java/com/xhly/manageapp/AppAdapter.kt 파일 보기

@@ -24,7 +24,7 @@ import java.util.Calendar
24 24
 class AppAdapter(var context: Context, var data: ArrayList<AppInfo>) :
25 25
     RecyclerView.Adapter<AppAdapter.AppViewHolder>() {
26 26
      var changePwdListener:ChangePwdListener?=null
27
-
27
+    var lastTimeLong=0L
28 28
     override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AppViewHolder {
29 29
         val inflate = ItemAppBinding.inflate(LayoutInflater.from(context), parent, false)
30 30
         return AppViewHolder(inflate)
@@ -62,7 +62,12 @@ class AppAdapter(var context: Context, var data: ArrayList<AppInfo>) :
62 62
                     it.changeCode()
63 63
                 }
64 64
             }else if (appInfo.packageName.equals(Const.UPDATESTRATEGYPKGNAME)){
65
-                UIEvent(Const.CODE2004.toString()).post()
65
+                if (lastTimeLong+1*60*1000<System.currentTimeMillis()){
66
+                    lastTimeLong=System.currentTimeMillis()
67
+                    UIEvent(Const.CODE2004.toString()).post()
68
+                }else{
69
+                    Toaster.show("请求过于频繁,请稍等")
70
+                }
66 71
             }else if (appInfo.packageName.equals(Const.WIFISEETTINGPKG)){
67 72
                 context.startActivity(Intent(Settings.ACTION_WIFI_SETTINGS))
68 73
             }else if (appInfo.packageName.equals(Const.STOREAPPPKG)){

+ 5
- 14
app/src/main/java/com/xhly/manageapp/bean/scheme/AutoAppBean.kt 파일 보기

@@ -1,10 +1,9 @@
1 1
 package com.xhly.manageapp.bean.scheme
2 2
 
3
-class AutoAppBean {
4
-    /**
5
-     * 主键id
6
-     */
7
-    var autoaid:Long?=0L
3
+import java.io.Serializable
4
+
5
+class AutoAppBean:Serializable {
6
+
8 7
 
9 8
     /**
10 9
      * 应用包名
@@ -17,17 +16,9 @@ class AutoAppBean {
17 16
     var authUrl:String?=null
18 17
 
19 18
     /**
20
-     * 单点类型:1账号 2手机号 3身份证号
19
+     * 认证类型:1账号2学号3手机号码4身份证号
21 20
      */
22 21
     var singleType:String?=null
23 22
 
24
-    /**
25
-     * 是否启用1启用2禁用
26
-     */
27
-    var enabled:Int=0
28 23
 
29
-    /**
30
-     * 版本
31
-     */
32
-    var rversion:Long?=0L
33 24
 }

+ 42
- 27
app/src/main/java/com/xhly/manageapp/ui/main/activity/MainActivity.kt 파일 보기

@@ -7,6 +7,7 @@ import DownloadItem
7 7
 import android.Manifest
8 8
 import android.annotation.SuppressLint
9 9
 import android.app.ActivityManager
10
+import android.content.ComponentName
10 11
 import android.content.Context
11 12
 import android.content.Intent
12 13
 import android.content.IntentFilter
@@ -17,6 +18,7 @@ import android.graphics.drawable.Drawable
17 18
 import android.net.ConnectivityManager
18 19
 import android.os.Build
19 20
 import android.provider.Settings
21
+import android.view.MotionEvent
20 22
 import android.view.View
21 23
 import android.widget.Button
22 24
 import android.widget.EditText
@@ -60,6 +62,7 @@ import com.xhly.manageapp.bean.app.AppModel
60 62
 import com.xhly.manageapp.bean.log.LogPushBean
61 63
 import com.xhly.manageapp.bean.log.LogdOperateBean
62 64
 import com.xhly.manageapp.bean.log.UpdateBean
65
+import com.xhly.manageapp.bean.scheme.AutoAppBean
63 66
 import com.xhly.manageapp.bean.school.SchoolDeviceSetBean
64 67
 import com.xhly.manageapp.bean.strategy.StrategyBean
65 68
 import com.xhly.manageapp.bean.user.UserBean
@@ -110,6 +113,9 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(),Download
110 113
     private var accountDialog:CustomDialog?=null
111 114
     //创建应用卸载集合,方便获得应用信息
112 115
     private val unInstallAppList= arrayListOf<AppInfo>()
116
+
117
+    //标记是否可以点击啊
118
+    private var canClickFlag=false
113 119
     override fun getBinding() = ActivityMainBinding.inflate(layoutInflater)
114 120
 
115 121
     @SuppressLint("CheckResult")
@@ -206,32 +212,6 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(),Download
206 212
                             FileUtils.deleteCurrentFlie(it)
207 213
                         }
208 214
                         val file = getExternalFilesDir(null)
209
-                    /*    viewModel.viewModelScope.launch {
210
-                            modelList.forEach { app ->
211
-                                try {
212
-                                    //获得已安装的应用判断版本,未安装的则直接静默安装。
213
-                                    val filter =
214
-                                        appList.filter { it.packageName.equals(app.appPackage) }
215
-                                    //列表中不存在,或者版本较低则更新
216
-                                    val apkPath = app.apkPath
217
-                                    val appName = app.appName
218
-                                    if (filter.isNotEmpty()) {
219
-                                        val currentApp = filter[0]
220
-                                        if (app.versionNum > currentApp.versionNum) {
221
-                                            //版本低则更新安装。
222
-                                            //AppDownLoadUtils.addToDownloadQueue(apkPath, appName,app.appPackage)
223
-                                            DownLoadUtils.addDownload(apkPath,appName,File(file.toString(), "$appName.apk").toString(),app.appPackage)
224
-                                        }
225
-                                    } else {
226
-                                        //不存在,直接下载安装。
227
-                                        //AppDownLoadUtils.addToDownloadQueue(apkPath, appName,app.appPackage)
228
-                                        DownLoadUtils.addDownload(apkPath,appName,File(file.toString(), "$appName.apk").toString(),app.appPackage)
229
-                                    }
230
-                                } catch (e: Exception) {
231
-                                    LogShow("问题" + e.toString())
232
-                                }
233
-                            }
234
-                        }*/
235 215
                         modelList.forEach { app ->
236 216
                             try {
237 217
                                 //获得已安装的应用判断版本,未安装的则直接静默安装。
@@ -408,7 +388,33 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(),Download
408 388
         viewModel.autoAppData.observe(this){
409 389
             //连接不为空,并且应用已安装则跳转应用
410 390
             if (it.authUrl!=null&&AppUtils.isAppInstalled(this,it.appPackage)){
411
-                ZJAPPUtils.openApk(this,it.appPackage)
391
+                spUtils.saveJson(Const.AUTOAPPKEY,it)
392
+                val launchIntent = Intent()
393
+                launchIntent.setComponent(
394
+                    ComponentName(
395
+                        it.appPackage!!,
396
+                        it.authUrl!!
397
+                    )
398
+                )
399
+                startActivity(launchIntent)
400
+            }else{
401
+               try {
402
+                   val autoAppBean = spUtils.getFromJson(Const.AUTOAPPKEY, AutoAppBean().javaClass) as AutoAppBean
403
+                   if (it.authUrl!=null&&AppUtils.isAppInstalled(this,it.appPackage)){
404
+                       val launchIntent = Intent()
405
+                       launchIntent.setComponent(
406
+                           ComponentName(
407
+                               autoAppBean.appPackage!!,
408
+                               autoAppBean.authUrl!!
409
+                           )
410
+                       )
411
+                       startActivity(launchIntent)
412
+                   }else{
413
+                       canClickFlag=true
414
+                   }
415
+               }catch (e:Exception){
416
+                   canClickFlag=true
417
+               }
412 418
             }
413 419
         }
414 420
         startWorkManager()
@@ -1266,6 +1272,7 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(),Download
1266 1272
             timer?.cancel()
1267 1273
             timer = null
1268 1274
         }
1275
+        AppSocket.onDestroy()
1269 1276
         DownLoadUtils.removeCallback(this)
1270 1277
         mMyInstallReceiver?.let {
1271 1278
             unregisterReceiver(it)
@@ -1307,4 +1314,12 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(),Download
1307 1314
     override fun onLoading(downItem: DownloadItem) {
1308 1315
 
1309 1316
     }
1317
+
1318
+    override fun dispatchTouchEvent(ev: MotionEvent?): Boolean {
1319
+        return if (canClickFlag){
1320
+            super.dispatchTouchEvent(ev)
1321
+        }else{
1322
+             true
1323
+        }
1324
+    }
1310 1325
 }

+ 14
- 8
app/src/main/java/com/xhly/manageapp/viewmodel/BaseViewModel.kt 파일 보기

@@ -4,6 +4,7 @@ import androidx.lifecycle.LiveData
4 4
 import androidx.lifecycle.MutableLiveData
5 5
 import com.xhly.corelib.base.viewmodel.CommonBaseViewModel
6 6
 import com.xhly.corelib.network.RetrofitService
7
+import com.xhly.corelib.utils.LogShow
7 8
 import com.xhly.corelib.utils.MD5Utils
8 9
 import com.xhly.manageapp.bean.log.LogEventBean
9 10
 import com.xhly.manageapp.bean.log.LogPushBean
@@ -175,14 +176,19 @@ open class BaseViewModel : CommonBaseViewModel() {
175 176
 
176 177
     fun postAutoAppDetail(regionid:Long){
177 178
         launchUI {
178
-            val map=HashMap<String,Any>()
179
-            map["regionid"]=regionid
180
-            val result= loginService.postAutoAppDetail(map)
181
-            if (result.code==0){
182
-                result.obj.let {
183
-                    autoAppResult.value=it
184
-                }
185
-            }
179
+           try {
180
+               val map=HashMap<String,Any>()
181
+               map["regionid"]=regionid
182
+               val result= loginService.postAutoAppDetail(map)
183
+               if (result.code==0){
184
+                   autoAppResult.value=result.obj
185
+               }else{
186
+                   autoAppResult.value=AutoAppBean()
187
+               }
188
+           }catch (e:Exception){
189
+               autoAppResult.value=AutoAppBean()
190
+               LogShow(e.toString())
191
+           }
186 192
         }
187 193
     }
188 194
 }

+ 4
- 2
corelib/src/main/java/com/xhly/corelib/Const.kt 파일 보기

@@ -61,8 +61,10 @@ object Const {
61 61
     //标记平板禁用(来源于socket)
62 62
     const val DISABLEPAD = "DISABLEPAD"
63 63
 
64
-    //标记平板在禁用的事件范围(来源于策略)
65
-    const val DISABLEPADTIME = "DISABLEPADTIME"
64
+    /**
65
+     * 用来存储自动跳转应用相关的数据
66
+     */
67
+    const val AUTOAPPKEY = "AUTOAPPKEY"
66 68
 
67 69
     //作为存储白名单应用的key
68 70
     const val WHITELISTAPP = "WHITELISTAPP"

Loading…
취소
저장