Skip to content

Commit fd06f02

Browse files
Automatically Add target apps to scope on module enable (ThePedroo#9)
1 parent 219d2df commit fd06f02

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

app/src/main/java/org/lsposed/manager/adapters/ScopeAdapter.java

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,20 @@ public void onSwitchChanged(Switch view, boolean isChecked) {
135135
view.setChecked(!isChecked);
136136
enabled = !isChecked;
137137
}
138+
139+
if(enabled) {
140+
if (!checkedList.isEmpty()) {
141+
new BlurBehindDialogBuilder(activity, R.style.ThemeOverlay_MaterialAlertDialog_Centered_FullWidthButtons)
142+
.setMessage(R.string.use_recommended_message)
143+
.setPositiveButton(android.R.string.ok, (dialog, which) -> checkRecommended())
144+
.setNegativeButton(android.R.string.cancel, null)
145+
.show();
146+
} else {
147+
checkRecommended();
148+
}
149+
}
150+
151+
// If failed to enable module and checkedList is not empty, revert the change
138152
var tmpChkList = new HashSet<>(checkedList);
139153
if (isChecked && !tmpChkList.isEmpty() && !ConfigManager.setModuleScope(module.packageName, module.legacy, tmpChkList)) {
140154
view.setChecked(false);
@@ -230,10 +244,18 @@ private void checkRecommended() {
230244
fragment.showHint(R.string.module_is_not_activated_yet, false);
231245
return;
232246
}
247+
248+
var tmpChkList = new HashSet<>(checkedList);
249+
tmpChkList.removeIf(i -> i.userId == module.userId);
250+
var tmpDenyList = new HashSet<>(denyList);
251+
// Filter recommended list to exclude deny list items
252+
for (ApplicationWithEquals app : recommendedList) {
253+
if (!tmpDenyList.contains(app.packageName)) {
254+
tmpChkList.add(app);
255+
}
256+
}
257+
233258
fragment.runAsync(() -> {
234-
var tmpChkList = new HashSet<>(checkedList);
235-
tmpChkList.removeIf(i -> i.userId == module.userId);
236-
tmpChkList.addAll(recommendedList);
237259
ConfigManager.setModuleScope(module.packageName, module.legacy, tmpChkList);
238260
checkedList = tmpChkList;
239261
fragment.runOnUiThread(this::notifyDataSetChanged);

0 commit comments

Comments
 (0)