Explorar el Código

1.处理学校设置得设置设置例如图标隐藏。

master
wangwanlei hace 10 meses
padre
commit
033e44f2ef

+ 33
- 6
app/src/main/java/com/xhly/manageapp/ui/main/activity/MainActivity.kt Ver fichero

@@ -39,6 +39,7 @@ import com.xhly.manageapp.bean.EventLog
39 39
 import com.xhly.manageapp.bean.SocketMsgBean
40 40
 import com.xhly.manageapp.bean.UpdateBean
41 41
 import com.xhly.manageapp.bean.log.LogdOperateBean
42
+import com.xhly.manageapp.bean.school.SchoolDeviceSetBean
42 43
 import com.xhly.manageapp.bean.strategy.StrategyBean
43 44
 import com.xhly.manageapp.bean.user.UserBean
44 45
 import com.xhly.manageapp.broadcastreceiver.AppInstallReceiver
@@ -49,6 +50,7 @@ import com.xhly.manageapp.ui.ManageActivity
49 50
 import com.xhly.manageapp.ui.login.activity.LoginActivity
50 51
 import com.xhly.manageapp.ui.main.viewmodel.MainViewModel
51 52
 import com.xhly.manageapp.utils.AppDownLoadUtils
53
+import com.xhly.manageapp.utils.CustomAppUtils
52 54
 import com.xhly.manageapp.utils.PadInfoUtils
53 55
 import com.xhly.manageapp.utils.StrategyUtils
54 56
 import com.xhly.manageapp.workmanager.TimingWorker
@@ -73,11 +75,10 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
73 75
         } else {
74 76
             userBean = json as UserBean
75 77
         }
76
-        val getAppList1 = AppUtils.GetAppList(this)
77
-        dataList.addAll(getAppList1)
78 78
         adapter = AppAdapter(this, dataList)
79 79
         mBinding.rv.layoutManager = GridLayoutManager(this, 6, GridLayoutManager.VERTICAL, false)
80 80
         mBinding.rv.adapter = adapter
81
+        updateAppRv()
81 82
         // checkAccessibility(this)
82 83
         mBinding.btn.setOnClickListener {
83 84
             startIntentActivity(ManageActivity().javaClass)
@@ -145,7 +146,14 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
145 146
             }
146 147
         }
147 148
         viewModel.updateInfoData.observe(this) {
148
-            //TODO 需要编写更新代码
149
+            //成功则保存不在提交
150
+            if (it){
151
+                spUtils.setParam(Const.PADUPDATETIMEKEY,System.currentTimeMillis())
152
+            }
153
+        }
154
+        viewModel.schoolSetData.observe(this){
155
+            spUtils.saveJson(Const.SCHOOLSETDEVICE,it)
156
+            updateAppRv()
149 157
         }
150 158
         startWorkManager()
151 159
     }
@@ -174,6 +182,9 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
174 182
             //屏蔽返回
175 183
             /*    viewModel.getAppList()
176 184
                 viewModel.getForceAppList()*/
185
+            userBean?.let {
186
+                viewModel.postDevicesetDetail(it.schoolid)
187
+            }
177 188
         }
178 189
     }
179 190
 
@@ -182,7 +193,9 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
182 193
         super.onResume()
183 194
         viewModel.updateStrategy()
184 195
         viewModel.uploadAppStrategy()
185
-        viewModel.postDevicesetDetail("1")
196
+        userBean?.let {
197
+            viewModel.postDevicesetDetail(it.schoolid)
198
+        }
186 199
         useTimeStrategy()
187 200
         updatePadInfo()
188 201
         updateMcApp()
@@ -196,7 +209,7 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
196 209
     }
197 210
 
198 211
     private fun updateMcApp() {
199
-        //每天请求一次app更新接口
212
+        //每天请求一次app更新接口,这个接口是用于提交版本信息统计
200 213
         try {
201 214
             var userBean = spUtils.getFromJson(Const.USERINFO, UserBean().javaClass) as UserBean
202 215
             //存储pad更新请求时间,如果为同一天则不在上传,不然继续上传
@@ -461,8 +474,22 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
461 474
 
462 475
     private fun updateAppRv() {
463 476
         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
+            }
464 487
             dataList.clear()
465
-            val appList = AppUtils.GetAppList(this)
488
+            var appList = AppUtils.GetAppList(this)
489
+            appList.addAll(CustomAppUtils().getCustomAppList(this))
490
+            if (schoolDeviceSetBean!=null){
491
+                appList=StrategyUtils.setSchoolSetDevice(schoolDeviceSetBean,appList)
492
+            }
466 493
             dataList.addAll(appList)
467 494
             if (adapter == null) {
468 495
                 adapter = AppAdapter(this, dataList)

+ 5
- 2
app/src/main/java/com/xhly/manageapp/ui/main/viewmodel/MainViewModel.kt Ver fichero

@@ -9,6 +9,7 @@ import com.xhly.manageapp.bean.ListAppBean
9 9
 import com.xhly.manageapp.bean.UpdateBean
10 10
 import com.xhly.manageapp.bean.log.LogdOperateBean
11 11
 import com.xhly.manageapp.bean.log.PadInfoBean
12
+import com.xhly.manageapp.bean.school.SchoolDeviceSetBean
12 13
 import com.xhly.manageapp.bean.strategy.AppTimeManageBean
13 14
 import com.xhly.manageapp.bean.strategy.StrategyBean
14 15
 import com.xhly.manageapp.network.app.AppService
@@ -36,6 +37,8 @@ class MainViewModel : CommonBaseViewModel() {
36 37
     val updateInfoData: LiveData<Boolean> = updateInfo
37 38
     private val loginOut = MutableLiveData<Boolean>()
38 39
     val loginOutData: LiveData<Boolean> = loginOut
40
+    private val schoolSet=MutableLiveData<SchoolDeviceSetBean>()
41
+    val schoolSetData:LiveData<SchoolDeviceSetBean> =schoolSet
39 42
 
40 43
     fun getAppList() {
41 44
         launchUI {
@@ -138,13 +141,13 @@ class MainViewModel : CommonBaseViewModel() {
138 141
     /**
139 142
      * 获得设备设置管理
140 143
      */
141
-    fun postDevicesetDetail(schoolid: String) {
144
+    fun postDevicesetDetail(schoolid:Long) {
142 145
         launchUI {
143 146
             val map = HashMap<String, Any>()
144 147
             map["schoolid"] = schoolid
145 148
             val result = strategyService.postDevicesetDetail(map)
146 149
             if (result.code == 0) {
147
-
150
+               schoolSet.value=result.obj
148 151
             } else {
149 152
                 netMessage.value = result.msg
150 153
             }

+ 39
- 0
app/src/main/java/com/xhly/manageapp/utils/CustomAppUtils.kt Ver fichero

@@ -0,0 +1,39 @@
1
+package com.xhly.manageapp.utils
2
+
3
+import android.content.Context
4
+import android.graphics.drawable.Drawable
5
+import androidx.appcompat.content.res.AppCompatResources
6
+import com.xhly.corelib.Const
7
+import com.xhly.corelib.bean.AppInfo
8
+import com.xhly.manageapp.R
9
+
10
+//用来创建一键加速,清除缓存,和自动旋转的appbean类
11
+class CustomAppUtils {
12
+    public fun getCustomAppList(context: Context): ArrayList<AppInfo> {
13
+        val appList= arrayListOf<AppInfo>()
14
+        appList.add(getCusomAppBean(
15
+            context.getString(R.string.speed),
16
+            Const.CUSTOMSPEEDAPP,
17
+           AppCompatResources.getDrawable(context,R.drawable.icon_speed)!!
18
+        ))
19
+        appList.add(getCusomAppBean(
20
+            context.getString(R.string.clear),
21
+            Const.CUSTOMCLEARAPP,
22
+            AppCompatResources.getDrawable(context,R.drawable.icon_clear)!!
23
+        ))
24
+        appList.add(getCusomAppBean(
25
+            context.getString(R.string.rotation),
26
+            Const.CUSTOMROTATIONAPP,
27
+            AppCompatResources.getDrawable(context,R.drawable.icon_speed)!!
28
+        ))
29
+        return appList
30
+    }
31
+
32
+    private fun getCusomAppBean(name: String, pkg: String, icon: Drawable):AppInfo{
33
+        val appInfo = AppInfo()
34
+        appInfo.name = name
35
+        appInfo.packageName = pkg
36
+        appInfo.ico = icon
37
+        return appInfo
38
+    }
39
+}

+ 63
- 15
app/src/main/java/com/xhly/manageapp/utils/StrategyUtils.kt Ver fichero

@@ -3,10 +3,13 @@ package com.xhly.manageapp.utils
3 3
 import android.content.Context
4 4
 import com.google.gson.reflect.TypeToken
5 5
 import com.xhly.corelib.Const
6
+import com.xhly.corelib.bean.AppInfo
6 7
 import com.xhly.corelib.utils.LogShow
8
+import com.xhly.corelib.utils.ModelNameUtils
7 9
 import com.xhly.corelib.utils.SharedPreferencesUtils
8 10
 import com.xhly.corelib.utils.hourToCurrentDateLong
9 11
 import com.xhly.manageapp.ManageApplication
12
+import com.xhly.manageapp.bean.school.SchoolDeviceSetBean
10 13
 import com.xhly.manageapp.bean.strategy.AppTimeManageBean
11 14
 import com.xhly.manageapp.bean.strategy.StrategyBean
12 15
 import java.util.Calendar
@@ -29,21 +32,21 @@ object StrategyUtils {
29 32
             ManageApplication.enableWifiWhiteList(false)
30 33
         }
31 34
         //是否开启应用策略,不使用,通过app列表接口获取。
32
-  /*      if (strategyBean.hasapp == 1) {
33
-            //TODO 应用策略可能需要应用下载安装以及卸载
34
-            //开启
35
-            strategyBean.padApps?.let { appArray ->
36
-                val list = arrayListOf<String>()
37
-                appArray.forEach {
38
-                    list.add(it.appPackage)
39
-                }
40
-                ManageApplication.addInstallPackageWhiteList(list)
41
-            }
42
-        } else {
43
-            //不开启应用策略
44
-            val installPackageWhiteList = ManageApplication.getInstallPackageWhiteList()
45
-            ManageApplication.removeInstallPackageWhiteList(installPackageWhiteList)
46
-        }*/
35
+        /*      if (strategyBean.hasapp == 1) {
36
+                  //TODO 应用策略可能需要应用下载安装以及卸载
37
+                  //开启
38
+                  strategyBean.padApps?.let { appArray ->
39
+                      val list = arrayListOf<String>()
40
+                      appArray.forEach {
41
+                          list.add(it.appPackage)
42
+                      }
43
+                      ManageApplication.addInstallPackageWhiteList(list)
44
+                  }
45
+              } else {
46
+                  //不开启应用策略
47
+                  val installPackageWhiteList = ManageApplication.getInstallPackageWhiteList()
48
+                  ManageApplication.removeInstallPackageWhiteList(installPackageWhiteList)
49
+              }*/
47 50
 
48 51
         //是否开启时间策略,这个策略在生命周期中调用getPadTimeStrategy(strategyBean)
49 52
 
@@ -214,4 +217,49 @@ object StrategyUtils {
214 217
             return true
215 218
         }
216 219
     }
220
+
221
+    /**
222
+     * 处理学校设置的设备设置管理,设计隐藏的隐藏图标,
223
+     */
224
+    public fun setSchoolSetDevice(schoolDeviceSetBean: SchoolDeviceSetBean, appList: List<AppInfo>):ArrayList<AppInfo> {
225
+        val dataList = arrayListOf<AppInfo>()
226
+        appList.forEach { appinfo ->
227
+            if (ModelNameUtils.IS_LianxX505f()){
228
+                //启用电话短信:1是0否
229
+                if (schoolDeviceSetBean.simcard == 0 && (appinfo.packageName.equals(Const.ANDROIDPHONE) || appinfo.packageName.equals(Const.ANDROIDMMS))) {
230
+                    return@forEach
231
+                }
232
+                //日历:1是0否
233
+                if (schoolDeviceSetBean.calendar == 0 && appinfo.packageName.equals(Const.ANDROIDCALENDAR)) {
234
+                    return@forEach
235
+                }
236
+                //闹钟:1是0否
237
+                if (schoolDeviceSetBean.alarmClock == 0 && appinfo.packageName.equals(Const.ANDROIDDESKCLOCK)) {
238
+                    return@forEach
239
+                }
240
+                //相机:1是0否
241
+                if (schoolDeviceSetBean.camera == 0 && appinfo.packageName.equals(Const.ANDROIDCAMERA)) {
242
+                    return@forEach
243
+                }
244
+                //相册:1是0否
245
+                if (schoolDeviceSetBean.gallery == 0 && appinfo.packageName.equals(Const.ANDROIDGALLERY)) {
246
+                    return@forEach
247
+                }
248
+            }
249
+            //一键加速:1是0否
250
+            if (schoolDeviceSetBean.accelerate==0&&appinfo.packageName.equals(Const.CUSTOMSPEEDAPP)){
251
+                return@forEach
252
+            }
253
+            //清理缓存:1是0否
254
+            if (schoolDeviceSetBean.cleanup==0&&appinfo.packageName.equals(Const.CUSTOMCLEARAPP)){
255
+                return@forEach
256
+            }
257
+            //自动旋转:1是0否
258
+            if (schoolDeviceSetBean.rotateSetting==0&&appinfo.packageName.equals(Const.CUSTOMROTATIONAPP)){
259
+                return@forEach
260
+            }
261
+            dataList.add(appinfo)
262
+        }
263
+        return dataList
264
+    }
217 265
 }

+ 1
- 0
app/src/main/res/values/strings.xml Ver fichero

@@ -19,5 +19,6 @@
19 19
     <string name="close">关闭</string>
20 20
     <string name="clear">清除缓存</string>
21 21
     <string name="speed">一键加速</string>
22
+    <string name="rotation">自动旋转</string>
22 23
     <string name="locktips">您的设备已违规或者被管理员限制使用,请联系管理员</string>
23 24
 </resources>

+ 48
- 0
corelib/src/main/java/com/xhly/corelib/Const.kt Ver fichero

@@ -101,6 +101,9 @@ object Const {
101 101
     //存储用户信息
102 102
     const val USERINFO = "USERINFO"
103 103
 
104
+    //存储学校设置的设备设置
105
+    const val SCHOOLSETDEVICE="SCHOOLSETDEVICE"
106
+
104 107
     //记录设备策略名称
105 108
     const val DEVICETYPE1 = "摄像头"
106 109
     const val DEVICETYPE2 = "蓝牙"
@@ -112,4 +115,49 @@ object Const {
112 115
     const val DEVICETYPE8 = "WiFi高级选项"
113 116
     const val DEVICETYPE9 = "SD卡"
114 117
     const val DEVICETYPE10 = "OTG"
118
+
119
+    //记录系统应用名称
120
+    /**
121
+     * 电话包名
122
+     */
123
+    const val ANDROIDPHONE="com.android.contacts"
124
+    /**
125
+     * 短信包名
126
+     */
127
+    const val ANDROIDMMS="com.android.mms"
128
+    /**
129
+     * 日历
130
+     */
131
+    const val ANDROIDCALENDAR="com.android.calendar"
132
+    /**
133
+     * 录音机
134
+     */
135
+    const val ANDROIDRECORDER="com.android.soundrecorder"
136
+    /**
137
+     *时钟
138
+     */
139
+    const val ANDROIDDESKCLOCK="com.android.deskclock"
140
+    /**
141
+     * 联想相机相机
142
+     */
143
+    const val ANDROIDCAMERA="com.dtab.camera"
144
+    /**
145
+     * 联想相册
146
+     */
147
+    const val ANDROIDGALLERY="com.android.gallery3d"
148
+
149
+    /**
150
+     *标记自定义的一键清理名称
151
+     */
152
+    const val CUSTOMSPEEDAPP="CUSTOMSPEEDAPP"
153
+
154
+    /**
155
+     *标记自定义的清除缓存名称
156
+     */
157
+    const val CUSTOMCLEARAPP="CUSTOMCLEARAPP"
158
+
159
+    /**
160
+     *标记自定义的自动旋转名称
161
+     */
162
+    const val CUSTOMROTATIONAPP="CUSTOMROTATIONAPP"
115 163
 }

Loading…
Cancelar
Guardar