Browse Source

1.不再默认生成应用商店

2.添加应用列表隐藏规则
20241218TB223FC(测试jar包)
wangwanlei 10 months ago
parent
commit
45739b7a0e

+ 26
- 8
app/src/main/java/com/xhly/manageapp/ui/main/activity/MainActivity.kt View File

@@ -28,6 +28,7 @@ import androidx.work.WorkManager
28 28
 import com.bumptech.glide.Glide
29 29
 import com.bumptech.glide.request.target.CustomViewTarget
30 30
 import com.bumptech.glide.request.transition.Transition
31
+import com.google.gson.reflect.TypeToken
31 32
 import com.hjq.toast.Toaster
32 33
 import com.kongzue.dialogx.dialogs.CustomDialog
33 34
 import com.kongzue.dialogx.interfaces.OnBindView
@@ -51,6 +52,7 @@ import com.xhly.manageapp.ManageApplication
51 52
 import com.xhly.manageapp.bean.EventLog
52 53
 import com.xhly.manageapp.bean.SocketMsgBean
53 54
 import com.xhly.manageapp.bean.app.AppInstallBean
55
+import com.xhly.manageapp.bean.app.AppModel
54 56
 import com.xhly.manageapp.bean.log.LogPushBean
55 57
 import com.xhly.manageapp.bean.log.LogdOperateBean
56 58
 import com.xhly.manageapp.bean.log.UpdateBean
@@ -139,7 +141,7 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
139 141
         // csdkManagerUtils.csdkManager.enableAccessibility("com.xhly.manageapp","com.xhly.manageapp.service.TestService",true)
140 142
 
141 143
         viewModel.listAppData.observe(this) { modelList ->
142
-            //存储商店应用包名到本地
144
+            //存储商店应用包名到本地,并且存储商店应用列表数据到本地集合
143 145
             val appNameList = arrayListOf<String>()
144 146
             val whiteList = arrayListOf<String>()
145 147
             modelList.forEach {
@@ -149,7 +151,7 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
149 151
                 }
150 152
             }
151 153
             ManageApplication.addAppWhiteRule(whiteList)
152
-            spUtils.saveJson(Const.APPSTOREKEY, appNameList)
154
+            spUtils.saveJson(Const.APPSTOREDATAKEY,modelList)
153 155
             //获得应用集合,必装应用和推荐应用,再加上预装应用(预装应用直接隐藏),其余应用需要静默卸载,必装应用需要进行静默下载和安装。安装应用从forceapp接口获取
154 156
             val appList = AppUtils.GetAppList(this)
155 157
             val firstAppList = arrayListOf<String>()
@@ -936,14 +938,25 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
936 938
 
937 939
     private fun updateAppRv() {
938 940
         try {
939
-            //获得预装应用和商店应用,商店应用和预装重叠直接显示,其余预装直接隐藏
941
+            //获得预装应用和商店应用,商店应用(隐藏图标的不显示)和预装重叠直接显示,其余预装直接隐藏
940 942
             var schoolDeviceSetBean: SchoolDeviceSetBean? = null
941 943
             schoolDeviceSetBean = StrategyUtils.getSchoolDeviceSetBean(this)
942 944
             val storeList = arrayListOf<String>()
945
+            val storeRemoveList= arrayListOf<String>()
943 946
             try {
944
-                val fromJson = spUtils.getFromJson(Const.APPSTOREKEY, ArrayList<String>().javaClass)
945
-                if (fromJson != null) {
946
-                    storeList.addAll(fromJson as ArrayList<String>)
947
+                val type = object : TypeToken<List<AppModel>>() {}.type
948
+                val appModelList = spUtils.getFromJsonType(
949
+                    Const.APPSTOREDATAKEY,
950
+                    ArrayList<AppModel>().javaClass,
951
+                    type
952
+                ) as ArrayList<AppModel>
953
+                if (appModelList != null) {
954
+                    appModelList.filter { it.showico==1}.forEach {
955
+                        storeList.add(it.appPackage)
956
+                    }
957
+                    appModelList.filter { it.showico==0}.forEach {
958
+                        storeRemoveList.add(it.appPackage)
959
+                    }
947 960
                 }
948 961
             } catch (e: Exception) {
949 962
                 LogShow("商店应用为空")
@@ -960,7 +973,7 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
960 973
                         ArrayList<String>().javaClass
961 974
                     ) as ArrayList<String>
962 975
                 currentList.forEach { pkg ->
963
-                    //学校控制之外的预装应用加入移除集合,应用商店列表包含的不需要加入移除集合
976
+                    //获得预装,在学校控制和应用商店显示以外的app加入移除集合
964 977
                     if (!Const.schoolSetAppList.contains(pkg) && !storeList.contains(pkg)) {
965 978
                         appList.filter { it.packageName == pkg }.forEach {
966 979
                             removeList.add(it)
@@ -971,8 +984,13 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
971 984
 
972 985
             }
973 986
             //如果包含应用商店也移除,因为会在自定义app中添加
974
-            appList.filter { it.packageName == Const.STOREAPPPKG }.forEach {
987
+           /* appList.filter { it.packageName == Const.STOREAPPPKG }.forEach {
975 988
                 removeList.add(it)
989
+            }*/
990
+
991
+            //移除应用列表隐藏的应用
992
+            storeRemoveList.forEach {pkg->
993
+                appList.removeIf { it.packageName==pkg }
976 994
             }
977 995
             //移除学校控制之外预装应用
978 996
             appList.removeAll(removeList)

+ 2
- 2
app/src/main/java/com/xhly/manageapp/utils/CustomAppUtils.kt View File

@@ -11,11 +11,11 @@ import com.xhly.corelib.bean.AppInfo
11 11
 class CustomAppUtils {
12 12
     public fun getCustomAppList(context: Context): ArrayList<AppInfo> {
13 13
         val appList= arrayListOf<AppInfo>()
14
-        appList.add(getCusomAppBean(
14
+     /*   appList.add(getCusomAppBean(
15 15
             context.getString(R.string.appstore),
16 16
             Const.STOREAPPPKG,
17 17
             AppCompatResources.getDrawable(context,R.drawable.icon_store)!!
18
-        ))
18
+        ))*/
19 19
         appList.add(getCusomAppBean(
20 20
             context.getString(R.string.speed),
21 21
             Const.CUSTOMSPEEDAPP,

+ 14
- 4
app/src/main/java/com/xhly/manageapp/utils/StrategyUtils.kt View File

@@ -13,6 +13,7 @@ import com.xhly.corelib.utils.ModelNameUtils
13 13
 import com.xhly.corelib.utils.SharedPreferencesUtils
14 14
 import com.xhly.corelib.utils.hourToCurrentDateLong
15 15
 import com.xhly.manageapp.ManageApplication
16
+import com.xhly.manageapp.bean.app.AppModel
16 17
 import com.xhly.manageapp.bean.school.SchoolDeviceSetBean
17 18
 import com.xhly.manageapp.bean.strategy.AppTimeManageBean
18 19
 import com.xhly.manageapp.bean.strategy.StrategyBean
@@ -325,10 +326,19 @@ object StrategyUtils {
325 326
     public fun clearAppData(context: Context) {
326 327
         try {
327 328
             val spUtils by lazy { SharedPreferencesUtils.getInstance(context) }
328
-            val strings = spUtils.getFromJson(
329
-                Const.APPSTOREKEY,
330
-                ArrayList<String>().javaClass
331
-            ) as ArrayList<String>
329
+            val type = object : TypeToken<List<AppModel>>() {}.type
330
+            val appModelList = spUtils.getFromJsonType(
331
+                Const.APPSTOREDATAKEY,
332
+                ArrayList<AppModel>().javaClass,
333
+                type
334
+            ) as ArrayList<AppModel>
335
+
336
+            val strings= arrayListOf<String>()
337
+            appModelList.forEach {
338
+                if (it.cached==1){
339
+                    strings.add(it.appPackage)
340
+                }
341
+            }
332 342
             ManageApplication.clearAppData(strings)
333 343
         }catch (e:Exception){
334 344
 

Loading…
Cancel
Save