Bläddra i källkod

1.添加修改密码弹窗。

20241218TB223FC(测试jar包)
wangwanlei 11 månader sedan
förälder
incheckning
a24c9c7a31

+ 11
- 3
app/src/main/java/com/xhly/manageapp/AppAdapter.kt Visa fil

@@ -20,7 +20,7 @@ import java.util.Calendar
20 20
 
21 21
 class AppAdapter(var context: Context, var data: ArrayList<AppInfo>) :
22 22
     RecyclerView.Adapter<AppAdapter.AppViewHolder>() {
23
-
23
+     var changePwdListener:ChangePwdListener?=null
24 24
 
25 25
     override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AppViewHolder {
26 26
         val inflate = ItemAppBinding.inflate(LayoutInflater.from(context), parent, false)
@@ -43,10 +43,16 @@ class AppAdapter(var context: Context, var data: ArrayList<AppInfo>) :
43 43
                 StrategyUtils.clearMemory(context,data)
44 44
                 Toaster.show("加速完成。")
45 45
             }else if (appInfo.packageName.equals(Const.CUSTOMCLEARAPP)){
46
+                //TODO 没有清理内存的方法
46 47
                 Toaster.showLong("清理缓存")
47 48
             }else if (appInfo.packageName.equals(Const.CUSTOMROTATIONAPP)){
48 49
                 Toaster.showLong("旋转木马")
49
-            }else{
50
+                ManageApplication.disallowSetAutoRotation(true)
51
+            }else if (appInfo.packageName.equals(Const.CUSTOMCHANGEPSD)){
52
+                changePwdListener?.let {
53
+                    it.changeCode()
54
+                }
55
+            } else{
50 56
                 try {
51 57
                     var instance = Calendar.getInstance()
52 58
                     instance.set(Calendar.HOUR_OF_DAY, 11)
@@ -68,5 +74,7 @@ class AppAdapter(var context: Context, var data: ArrayList<AppInfo>) :
68 74
     class AppViewHolder(binding: ItemAppBinding) : RecyclerView.ViewHolder(binding.root) {
69 75
         var mBinding = binding
70 76
     }
71
-
77
+   interface ChangePwdListener{
78
+       fun changeCode()
79
+   }
72 80
 }

+ 75
- 1
app/src/main/java/com/xhly/manageapp/ui/main/activity/MainActivity.kt Visa fil

@@ -11,6 +11,7 @@ import android.content.pm.PackageManager
11 11
 import android.graphics.Color
12 12
 import android.graphics.drawable.Drawable
13 13
 import android.provider.Settings
14
+import android.text.Editable
14 15
 import android.view.View
15 16
 import android.widget.Button
16 17
 import android.widget.EditText
@@ -90,6 +91,7 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
90 91
         }
91 92
         adapter = AppAdapter(this, dataList)
92 93
         mBinding.rv.layoutManager = GridLayoutManager(this, 6, GridLayoutManager.VERTICAL, false)
94
+        adapter?.changePwdListener=getChangeCodeListener()
93 95
         mBinding.rv.adapter = adapter
94 96
         updateAppRv()
95 97
         // checkAccessibility(this)
@@ -241,6 +243,77 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
241 243
         }
242 244
     }
243 245
 
246
+    private fun getChangeCodeListener():AppAdapter.ChangePwdListener{
247
+        return object :AppAdapter.ChangePwdListener{
248
+            override fun changeCode() {
249
+                val deviceSetBean = StrategyUtils.getSchoolDeviceSetBean(this@MainActivity)
250
+                var showFlag=true
251
+                if (deviceSetBean!=null&&deviceSetBean.changePwd==0){
252
+                    //学校设置是否禁止修改密码
253
+                    showFlag=false
254
+                }
255
+                if (showFlag){
256
+                    showChangeCodeDialog()
257
+                }
258
+            }
259
+
260
+        }
261
+    }
262
+
263
+    private fun showChangeCodeDialog() {
264
+        CustomDialog.build()
265
+            .setCustomView(object : OnBindView<CustomDialog>(R.layout.layout_changecode_dialog) {
266
+                override fun onBind(dialog: CustomDialog, v: View) {
267
+                    //TODO 修改密码接口没有
268
+                    var titleTv = v.findViewById<TextView>(R.id.dialog_title_tv)
269
+                    val enterTv = v.findViewById<TextView>(R.id.dialog_enter_tv)
270
+                    val cancelTv = v.findViewById<TextView>(R.id.dialog_cancel_tv)
271
+                    val editText = v.findViewById<EditText>(R.id.dialog_et)
272
+                    val oldCodeEt=v.findViewById<EditText>(R.id.dialog_oldcode_et)
273
+                    val newCodeEt=v.findViewById<EditText>(R.id.dialog_newcode_et)
274
+                    enterTv.setOnClickListener {
275
+                        val enterCode = editText.text.toString()
276
+                        val oldCode = oldCodeEt.text.toString()
277
+                        val newCode = newCodeEt.text.toString()
278
+                        if (!getTextFlag(enterCode)||!getTextFlag(oldCode)||!getTextFlag(newCode)){
279
+                            Toast("密码不符合规则")
280
+                            return@setOnClickListener
281
+                        }
282
+                        if (oldCode.equals(newCode)){
283
+                            Toast("新密码不能和旧密码一致。")
284
+                            return@setOnClickListener
285
+                        }
286
+
287
+                        if (!newCode.equals(enterCode)){
288
+                            Toast("两次输入的新密码不一致。")
289
+                            return@setOnClickListener
290
+                        }
291
+
292
+                        dialog.dismiss()
293
+                        try {
294
+                            val userBean = spUtils.getFromJson(
295
+                                Const.USERINFO, UserBean().javaClass
296
+                            ) as UserBean
297
+
298
+                        } catch (e: Exception) {
299
+
300
+                        }
301
+                    }
302
+                    cancelTv.setOnClickListener {
303
+                        dialog.dismiss()
304
+                    }
305
+                }
306
+            }).setCancelable(false).setMaskColor(Color.parseColor("#66000000"))
307
+            .setAlign(CustomDialog.ALIGN.CENTER).show()
308
+    }
309
+
310
+    private fun getTextFlag(code:String?):Boolean{
311
+        try {
312
+            return (!code.isNullOrBlank())&&code.length>=6&&code.length<=16
313
+        }catch (e:Exception){
314
+            return false
315
+        }
316
+    }
244 317
 
245 318
     override fun onResume() {
246 319
         super.onResume()
@@ -604,6 +677,7 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
604 677
             dataList.addAll(appList)
605 678
             if (adapter == null) {
606 679
                 adapter = AppAdapter(this, dataList)
680
+                adapter?.changePwdListener=getChangeCodeListener()
607 681
                 mBinding.rv.adapter = adapter
608 682
             }
609 683
             adapter?.let {
@@ -666,7 +740,7 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
666 740
                     titleTv.text = getString(R.string.exit)
667 741
                     enterTv.setOnClickListener {
668 742
                         val code = editText.text
669
-                        if (!code.isNullOrBlank()) {
743
+                        if ((!code.isNullOrBlank())&&code.length>=6&&code.length<=16) {
670 744
                             dialog.dismiss()
671 745
                             try {
672 746
                                 val userBean = spUtils.getFromJson(

+ 1
- 1
app/src/main/java/com/xhly/manageapp/utils/CustomAppUtils.kt Visa fil

@@ -28,7 +28,7 @@ class CustomAppUtils {
28 28
         ))
29 29
         appList.add(getCusomAppBean(
30 30
             context.getString(R.string.changepsd),
31
-            Const.CUSTOMROTATIONAPP,
31
+            Const.CUSTOMCHANGEPSD,
32 32
             AppCompatResources.getDrawable(context,R.drawable.icon_changepwd)!!
33 33
         ))
34 34
         return appList

+ 188
- 0
app/src/main/res/layout/layout_changecode_dialog.xml Visa fil

@@ -0,0 +1,188 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
+    android:layout_width="355dp"
4
+    android:layout_height="wrap_content"
5
+    android:background="@drawable/shape_whiteradiu_bg"
6
+    android:gravity="center_horizontal"
7
+    android:minHeight="333dp"
8
+    android:orientation="vertical">
9
+
10
+    <TextView
11
+        android:id="@+id/dialog_title_tv"
12
+        android:layout_width="wrap_content"
13
+        android:layout_height="wrap_content"
14
+        android:layout_marginTop="22dp"
15
+        android:text="@string/changepsd"
16
+        android:textColor="#253A70"
17
+        android:textSize="18sp" />
18
+
19
+    <androidx.core.widget.NestedScrollView
20
+        android:layout_width="match_parent"
21
+        android:layout_height="wrap_content">
22
+
23
+        <LinearLayout
24
+            android:layout_width="match_parent"
25
+            android:layout_height="wrap_content"
26
+            android:orientation="vertical">
27
+
28
+            <LinearLayout
29
+                android:layout_width="match_parent"
30
+                android:layout_height="wrap_content"
31
+                android:layout_marginLeft="15dp"
32
+                android:gravity="center"
33
+                android:orientation="horizontal">
34
+
35
+                <TextView
36
+                    android:layout_width="wrap_content"
37
+                    android:layout_height="wrap_content"
38
+                    android:gravity="center_vertical"
39
+                    android:singleLine="true"
40
+                    android:text="@string/oldcode"
41
+                    android:textColor="@color/black"
42
+                    android:textSize="16sp" />
43
+
44
+                <EditText
45
+                    android:id="@+id/dialog_oldcode_et"
46
+                    android:layout_width="match_parent"
47
+                    android:layout_height="wrap_content"
48
+                    android:layout_margin="15dp"
49
+                    android:layout_marginTop="82dp"
50
+                    android:background="@null"
51
+                    android:gravity="center_vertical"
52
+                    android:hint="@string/oldcodetips"
53
+                    android:singleLine="true"
54
+                    android:textColor="@color/black"
55
+                    android:textColorHint="#FFB8C2D9"
56
+                    android:textSize="16sp" />
57
+            </LinearLayout>
58
+
59
+            <ImageView
60
+                android:layout_width="match_parent"
61
+                android:layout_height="1dp"
62
+                android:layout_marginLeft="15dp"
63
+                android:layout_marginRight="15dp"
64
+                android:layout_marginBottom="15dp"
65
+                android:src="#D0DBF4" />
66
+
67
+            <LinearLayout
68
+                android:layout_width="match_parent"
69
+                android:layout_height="wrap_content"
70
+                android:layout_marginLeft="15dp"
71
+                android:gravity="center"
72
+                android:orientation="horizontal">
73
+
74
+                <TextView
75
+                    android:layout_width="wrap_content"
76
+                    android:layout_height="wrap_content"
77
+                    android:gravity="center_vertical"
78
+                    android:singleLine="true"
79
+                    android:text="@string/newcode"
80
+                    android:textColor="@color/black"
81
+                    android:textSize="16sp" />
82
+
83
+                <EditText
84
+                    android:id="@+id/dialog_newcode_et"
85
+                    android:layout_width="match_parent"
86
+                    android:layout_height="wrap_content"
87
+                    android:layout_margin="15dp"
88
+                    android:layout_marginTop="82dp"
89
+                    android:background="@null"
90
+                    android:gravity="center_vertical"
91
+                    android:hint="@string/newcodetips"
92
+                    android:singleLine="true"
93
+                    android:textColor="@color/black"
94
+                    android:textColorHint="#FFB8C2D9"
95
+                    android:textSize="16sp" />
96
+            </LinearLayout>
97
+
98
+            <ImageView
99
+                android:layout_width="match_parent"
100
+                android:layout_height="1dp"
101
+                android:layout_marginLeft="15dp"
102
+                android:layout_marginRight="15dp"
103
+                android:layout_marginBottom="15dp"
104
+                android:src="#D0DBF4" />
105
+
106
+            <LinearLayout
107
+                android:layout_width="match_parent"
108
+                android:layout_height="wrap_content"
109
+                android:layout_marginLeft="15dp"
110
+                android:gravity="center"
111
+                android:orientation="horizontal">
112
+
113
+                <TextView
114
+                    android:layout_width="wrap_content"
115
+                    android:layout_height="wrap_content"
116
+                    android:gravity="center_vertical"
117
+                    android:singleLine="true"
118
+                    android:text="@string/enternewcode"
119
+                    android:textColor="@color/black"
120
+                    android:textSize="16sp" />
121
+
122
+                <EditText
123
+                    android:id="@+id/dialog_et"
124
+                    android:layout_width="match_parent"
125
+                    android:layout_height="wrap_content"
126
+                    android:layout_margin="15dp"
127
+                    android:layout_marginTop="82dp"
128
+                    android:background="@null"
129
+                    android:gravity="center_vertical"
130
+                    android:hint="@string/enternewcodetips"
131
+                    android:singleLine="true"
132
+                    android:textColor="@color/black"
133
+                    android:textColorHint="#FFB8C2D9"
134
+                    android:textSize="16sp" />
135
+            </LinearLayout>
136
+
137
+
138
+            <ImageView
139
+                android:layout_width="match_parent"
140
+                android:layout_height="1dp"
141
+                android:layout_marginLeft="15dp"
142
+                android:layout_marginRight="15dp"
143
+                android:layout_marginBottom="15dp"
144
+                android:src="#D0DBF4" />
145
+
146
+            <TextView
147
+                android:layout_width="match_parent"
148
+                android:layout_height="wrap_content"
149
+                android:layout_marginLeft="15dp"
150
+                android:layout_marginRight="15dp"
151
+                android:layout_marginBottom="15dp"
152
+                android:gravity="center_vertical"
153
+                android:singleLine="true"
154
+                android:text="@string/codetips"
155
+                android:textColor="#F0153F"
156
+                android:textSize="16sp" />
157
+
158
+            <LinearLayout
159
+                android:layout_width="match_parent"
160
+                android:layout_height="wrap_content"
161
+                android:layout_marginBottom="15dp"
162
+                android:gravity="center_horizontal"
163
+                android:orientation="horizontal">
164
+
165
+                <TextView
166
+                    android:id="@+id/dialog_cancel_tv"
167
+                    android:layout_width="147dp"
168
+                    android:layout_height="40dp"
169
+                    android:background="@drawable/shape_tv_noselect_bg"
170
+                    android:gravity="center"
171
+                    android:text="@string/cancel"
172
+                    android:textColor="#339DFF"
173
+                    android:textSize="17sp" />
174
+
175
+                <TextView
176
+                    android:id="@+id/dialog_enter_tv"
177
+                    android:layout_width="147dp"
178
+                    android:layout_height="40dp"
179
+                    android:layout_marginLeft="17dp"
180
+                    android:background="@drawable/icon_login"
181
+                    android:gravity="center"
182
+                    android:text="@string/enter"
183
+                    android:textColor="@color/white"
184
+                    android:textSize="17sp" />
185
+            </LinearLayout>
186
+        </LinearLayout>
187
+    </androidx.core.widget.NestedScrollView>
188
+</LinearLayout>

+ 7
- 0
app/src/main/res/values/strings.xml Visa fil

@@ -21,6 +21,13 @@
21 21
     <string name="speed">一键加速</string>
22 22
     <string name="rotation">自动旋转</string>
23 23
     <string name="changepsd">修改密码</string>
24
+    <string name="oldcode">原密码</string>
25
+    <string name="newcode">新密码</string>
26
+    <string name="enternewcode">确认新密码</string>
27
+    <string name="oldcodetips">请输入原密码</string>
28
+    <string name="newcodetips">请输入新密码</string>
29
+    <string name="enternewcodetips">请输入确认新密码</string>
30
+    <string name="codetips">密码必须是6-16位的英文字母、数字组合</string>
24 31
     <string name="locktips">您的设备已违规或者被管理员限制使用,请联系管理员</string>
25 32
     <string name="durationtips">当前使用时间过长,请休息后再使用。\n</string>
26 33
 </resources>

Laddar…
Avbryt
Spara