|
@@ -11,6 +11,7 @@ import android.widget.Toast
|
11
|
11
|
import androidx.appcompat.content.res.AppCompatResources
|
12
|
12
|
import androidx.recyclerview.widget.RecyclerView
|
13
|
13
|
import com.hjq.toast.Toaster
|
|
14
|
+import com.xhly.corelib.Const
|
14
|
15
|
import com.xhly.corelib.bean.AppInfo
|
15
|
16
|
import com.xhly.corelib.utils.LogShow
|
16
|
17
|
import com.xhly.manageapp.databinding.ItemAppBinding
|
|
@@ -27,42 +28,24 @@ class AppAdapter(var context: Context, var data: ArrayList<AppInfo>) :
|
27
|
28
|
}
|
28
|
29
|
|
29
|
30
|
override fun getItemCount(): Int {
|
30
|
|
- return data.size+2
|
|
31
|
+ return data.size
|
31
|
32
|
}
|
32
|
33
|
|
33
|
34
|
|
34
|
|
- override fun onBindViewHolder(holder: AppViewHolder, position: Int) {
|
35
|
|
- if (position==data.size){
|
36
|
|
- AppCompatResources.getDrawable(context,R.drawable.icon_speed)
|
37
|
|
- ?.let { holder.mBinding.itemCv.setImageDrawable(it) }
|
38
|
|
- holder.mBinding.itemCv.setText(context.getString(R.string.speed))
|
39
|
|
- holder.mBinding.itemCv.setOnClickListener {
|
40
|
|
- try {
|
41
|
|
- val service : ActivityManager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
|
42
|
|
- val runningAppProcesses = service.runningAppProcesses
|
43
|
|
- runningAppProcesses.forEach {process->
|
44
|
|
- LogShow("当前运行应用名称"+process.processName+"|||"+process?.importanceReasonComponent?.packageName)
|
45
|
|
- data.filter { it.packageName.equals(process.processName) }.forEach {
|
46
|
|
- ManageApplication.killApplicationProcess(it.packageName)
|
47
|
|
- }
|
48
|
|
- }
|
49
|
|
- Toaster.show("加速完成。")
|
50
|
|
- }catch (e:Exception){
|
51
|
35
|
|
52
|
|
- }
|
53
|
|
- }
|
54
|
|
- }else if (position==data.size+1){
|
55
|
|
- AppCompatResources.getDrawable(context,R.drawable.icon_clear)
|
56
|
|
- ?.let { holder.mBinding.itemCv.setImageDrawable(it) }
|
57
|
|
- holder.mBinding.itemCv.setText(context.getString(R.string.clear))
|
58
|
|
- holder.mBinding.itemCv.setOnClickListener {
|
59
|
36
|
|
60
|
|
- }
|
61
|
|
- }else{
|
62
|
|
- val appInfo = data[position]
|
63
|
|
- holder.mBinding.itemCv.setImageDrawable(appInfo.ico)
|
64
|
|
- holder.mBinding.itemCv.setText(appInfo.name)
|
65
|
|
- holder.mBinding.itemCv.setOnClickListener {
|
|
37
|
+ override fun onBindViewHolder(holder: AppViewHolder, position: Int) {
|
|
38
|
+ val appInfo = data[position]
|
|
39
|
+ holder.mBinding.itemCv.setImageDrawable(appInfo.ico)
|
|
40
|
+ holder.mBinding.itemCv.setText(appInfo.name)
|
|
41
|
+ holder.mBinding.itemCv.setOnClickListener {
|
|
42
|
+ if (appInfo.packageName.equals(Const.CUSTOMSPEEDAPP)){
|
|
43
|
+ clearMemory()
|
|
44
|
+ }else if (appInfo.packageName.equals(Const.CUSTOMCLEARAPP)){
|
|
45
|
+ Toaster.showLong("清理缓存")
|
|
46
|
+ }else if (appInfo.packageName.equals(Const.CUSTOMROTATIONAPP)){
|
|
47
|
+ Toaster.showLong("旋转木马")
|
|
48
|
+ }else{
|
66
|
49
|
try {
|
67
|
50
|
var instance = Calendar.getInstance()
|
68
|
51
|
instance.set(Calendar.HOUR_OF_DAY, 11)
|
|
@@ -76,11 +59,26 @@ class AppAdapter(var context: Context, var data: ArrayList<AppInfo>) :
|
76
|
59
|
}
|
77
|
60
|
}catch (e:Exception){
|
78
|
61
|
LogShow("应用跳转问题是"+e.toString())
|
79
|
|
- }
|
|
62
|
+ }
|
80
|
63
|
}
|
81
|
64
|
}
|
82
|
65
|
}
|
83
|
66
|
|
|
67
|
+ private fun clearMemory() {
|
|
68
|
+ try {
|
|
69
|
+ val service : ActivityManager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
|
|
70
|
+ val runningAppProcesses = service.runningAppProcesses
|
|
71
|
+ runningAppProcesses.forEach {process->
|
|
72
|
+ LogShow("当前运行应用名称"+process.processName+"|||"+process?.importanceReasonComponent?.packageName)
|
|
73
|
+ data.filter { it.packageName.equals(process.processName) }.forEach {
|
|
74
|
+ ManageApplication.killApplicationProcess(it.packageName)
|
|
75
|
+ }
|
|
76
|
+ }
|
|
77
|
+ Toaster.show("加速完成。")
|
|
78
|
+ }catch (e:Exception){
|
|
79
|
+
|
|
80
|
+ }
|
|
81
|
+ }
|
84
|
82
|
|
85
|
83
|
class AppViewHolder(binding: ItemAppBinding) : RecyclerView.ViewHolder(binding.root) {
|
86
|
84
|
var mBinding = binding
|