@@ -28,6 +28,7 @@ class ApplicationListActivity : AppCompatActivity(), SwipeRefreshLayout.OnRefres
28
28
private lateinit var blockedPackages: MutableSet <String >
29
29
30
30
private var showSystem = false
31
+ private var showEnabledOnly = false
31
32
private var textFilter = " "
32
33
33
34
override fun onCreate (savedInstanceState : Bundle ? ) {
@@ -81,7 +82,8 @@ class ApplicationListActivity : AppCompatActivity(), SwipeRefreshLayout.OnRefres
81
82
val isSystemApp = appInfo.flags and ApplicationInfo .FLAG_SYSTEM == 1
82
83
83
84
return (textFilter.isEmpty() || appLabel.contains(textFilter, true )) && // Filter by name
84
- (showSystem || ! isSystemApp) && // Only show system if that's enabled
85
+ (showSystem || ! isSystemApp) && // Show system apps, if that's active
86
+ (! showEnabledOnly || isAppEnabled(app)) && // Only show enabled apps, if that's active
85
87
app.packageName != packageName // Never show ourselves
86
88
}
87
89
@@ -90,11 +92,13 @@ class ApplicationListActivity : AppCompatActivity(), SwipeRefreshLayout.OnRefres
90
92
}
91
93
92
94
private fun setAppEnabled (app : PackageInfo , isEnabled : Boolean ) {
93
- if (! isEnabled) {
95
+ val wasChanged = if (! isEnabled) {
94
96
blockedPackages.add(app.packageName)
95
97
} else {
96
98
blockedPackages.remove(app.packageName)
97
99
}
100
+
101
+ if (wasChanged && showEnabledOnly) applyFilters()
98
102
}
99
103
100
104
private suspend fun loadAllApps (): List <PackageInfo > =
@@ -115,6 +119,27 @@ class ApplicationListActivity : AppCompatActivity(), SwipeRefreshLayout.OnRefres
115
119
applyFilters()
116
120
true
117
121
}
122
+ R .id.action_show_enabled -> {
123
+ showEnabledOnly = showEnabledOnly.not ()
124
+ applyFilters()
125
+ true
126
+ }
127
+ R .id.action_toggle_all -> {
128
+ if (blockedPackages.isEmpty()) {
129
+ // If everything is enabled, disable everything
130
+ blockedPackages.addAll(allApps.map { app -> app.packageName })
131
+ } else {
132
+ // Otherwise, re-enable everything
133
+ blockedPackages.removeAll(allApps.map { app -> app.packageName })
134
+ }
135
+
136
+ if (showEnabledOnly) {
137
+ applyFilters()
138
+ } else {
139
+ apps_list_recyclerView.adapter?.notifyDataSetChanged()
140
+ }
141
+ true
142
+ }
118
143
else -> false
119
144
}
120
145
}
@@ -125,6 +150,13 @@ class ApplicationListActivity : AppCompatActivity(), SwipeRefreshLayout.OnRefres
125
150
PopupMenu (this , apps_list_more_menu).apply {
126
151
this .inflate(R .menu.menu_app_list)
127
152
this .menu.findItem(R .id.action_show_system).isChecked = showSystem
153
+ this .menu.findItem(R .id.action_show_enabled).isChecked = showEnabledOnly
154
+ this .menu.findItem(R .id.action_toggle_all).title = getString(
155
+ if (blockedPackages.isEmpty())
156
+ R .string.disable_all
157
+ else
158
+ R .string.enable_all
159
+ )
128
160
this .setOnMenuItemClickListener(this @ApplicationListActivity)
129
161
}.show()
130
162
}
0 commit comments