Browse Source

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

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

+ 7
- 2
app/src/main/java/com/xhly/manageapp/AppAdapter.kt View File

24
 class AppAdapter(var context: Context, var data: ArrayList<AppInfo>) :
24
 class AppAdapter(var context: Context, var data: ArrayList<AppInfo>) :
25
     RecyclerView.Adapter<AppAdapter.AppViewHolder>() {
25
     RecyclerView.Adapter<AppAdapter.AppViewHolder>() {
26
      var changePwdListener:ChangePwdListener?=null
26
      var changePwdListener:ChangePwdListener?=null
27
-
27
+    var lastTimeLong=0L
28
     override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AppViewHolder {
28
     override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AppViewHolder {
29
         val inflate = ItemAppBinding.inflate(LayoutInflater.from(context), parent, false)
29
         val inflate = ItemAppBinding.inflate(LayoutInflater.from(context), parent, false)
30
         return AppViewHolder(inflate)
30
         return AppViewHolder(inflate)
62
                     it.changeCode()
62
                     it.changeCode()
63
                 }
63
                 }
64
             }else if (appInfo.packageName.equals(Const.UPDATESTRATEGYPKGNAME)){
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
             }else if (appInfo.packageName.equals(Const.WIFISEETTINGPKG)){
71
             }else if (appInfo.packageName.equals(Const.WIFISEETTINGPKG)){
67
                 context.startActivity(Intent(Settings.ACTION_WIFI_SETTINGS))
72
                 context.startActivity(Intent(Settings.ACTION_WIFI_SETTINGS))
68
             }else if (appInfo.packageName.equals(Const.STOREAPPPKG)){
73
             }else if (appInfo.packageName.equals(Const.STOREAPPPKG)){

+ 5
- 14
app/src/main/java/com/xhly/manageapp/bean/scheme/AutoAppBean.kt View File

1
 package com.xhly.manageapp.bean.scheme
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
     var authUrl:String?=null
16
     var authUrl:String?=null
18
 
17
 
19
     /**
18
     /**
20
-     * 单点类型:1账号 2手机号 3身份证号
19
+     * 认证类型:1账号2学号3手机号码4身份证号
21
      */
20
      */
22
     var singleType:String?=null
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 View File

7
 import android.Manifest
7
 import android.Manifest
8
 import android.annotation.SuppressLint
8
 import android.annotation.SuppressLint
9
 import android.app.ActivityManager
9
 import android.app.ActivityManager
10
+import android.content.ComponentName
10
 import android.content.Context
11
 import android.content.Context
11
 import android.content.Intent
12
 import android.content.Intent
12
 import android.content.IntentFilter
13
 import android.content.IntentFilter
17
 import android.net.ConnectivityManager
18
 import android.net.ConnectivityManager
18
 import android.os.Build
19
 import android.os.Build
19
 import android.provider.Settings
20
 import android.provider.Settings
21
+import android.view.MotionEvent
20
 import android.view.View
22
 import android.view.View
21
 import android.widget.Button
23
 import android.widget.Button
22
 import android.widget.EditText
24
 import android.widget.EditText
60
 import com.xhly.manageapp.bean.log.LogPushBean
62
 import com.xhly.manageapp.bean.log.LogPushBean
61
 import com.xhly.manageapp.bean.log.LogdOperateBean
63
 import com.xhly.manageapp.bean.log.LogdOperateBean
62
 import com.xhly.manageapp.bean.log.UpdateBean
64
 import com.xhly.manageapp.bean.log.UpdateBean
65
+import com.xhly.manageapp.bean.scheme.AutoAppBean
63
 import com.xhly.manageapp.bean.school.SchoolDeviceSetBean
66
 import com.xhly.manageapp.bean.school.SchoolDeviceSetBean
64
 import com.xhly.manageapp.bean.strategy.StrategyBean
67
 import com.xhly.manageapp.bean.strategy.StrategyBean
65
 import com.xhly.manageapp.bean.user.UserBean
68
 import com.xhly.manageapp.bean.user.UserBean
110
     private var accountDialog:CustomDialog?=null
113
     private var accountDialog:CustomDialog?=null
111
     //创建应用卸载集合,方便获得应用信息
114
     //创建应用卸载集合,方便获得应用信息
112
     private val unInstallAppList= arrayListOf<AppInfo>()
115
     private val unInstallAppList= arrayListOf<AppInfo>()
116
+
117
+    //标记是否可以点击啊
118
+    private var canClickFlag=false
113
     override fun getBinding() = ActivityMainBinding.inflate(layoutInflater)
119
     override fun getBinding() = ActivityMainBinding.inflate(layoutInflater)
114
 
120
 
115
     @SuppressLint("CheckResult")
121
     @SuppressLint("CheckResult")
206
                             FileUtils.deleteCurrentFlie(it)
212
                             FileUtils.deleteCurrentFlie(it)
207
                         }
213
                         }
208
                         val file = getExternalFilesDir(null)
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
                         modelList.forEach { app ->
215
                         modelList.forEach { app ->
236
                             try {
216
                             try {
237
                                 //获得已安装的应用判断版本,未安装的则直接静默安装。
217
                                 //获得已安装的应用判断版本,未安装的则直接静默安装。
408
         viewModel.autoAppData.observe(this){
388
         viewModel.autoAppData.observe(this){
409
             //连接不为空,并且应用已安装则跳转应用
389
             //连接不为空,并且应用已安装则跳转应用
410
             if (it.authUrl!=null&&AppUtils.isAppInstalled(this,it.appPackage)){
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
         startWorkManager()
420
         startWorkManager()
1266
             timer?.cancel()
1272
             timer?.cancel()
1267
             timer = null
1273
             timer = null
1268
         }
1274
         }
1275
+        AppSocket.onDestroy()
1269
         DownLoadUtils.removeCallback(this)
1276
         DownLoadUtils.removeCallback(this)
1270
         mMyInstallReceiver?.let {
1277
         mMyInstallReceiver?.let {
1271
             unregisterReceiver(it)
1278
             unregisterReceiver(it)
1307
     override fun onLoading(downItem: DownloadItem) {
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 View File

4
 import androidx.lifecycle.MutableLiveData
4
 import androidx.lifecycle.MutableLiveData
5
 import com.xhly.corelib.base.viewmodel.CommonBaseViewModel
5
 import com.xhly.corelib.base.viewmodel.CommonBaseViewModel
6
 import com.xhly.corelib.network.RetrofitService
6
 import com.xhly.corelib.network.RetrofitService
7
+import com.xhly.corelib.utils.LogShow
7
 import com.xhly.corelib.utils.MD5Utils
8
 import com.xhly.corelib.utils.MD5Utils
8
 import com.xhly.manageapp.bean.log.LogEventBean
9
 import com.xhly.manageapp.bean.log.LogEventBean
9
 import com.xhly.manageapp.bean.log.LogPushBean
10
 import com.xhly.manageapp.bean.log.LogPushBean
175
 
176
 
176
     fun postAutoAppDetail(regionid:Long){
177
     fun postAutoAppDetail(regionid:Long){
177
         launchUI {
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 View File

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

Loading…
Cancel
Save