AppListDialogFragment: Revamp toggle logic
Rather than always toggle all elements, elect to unselect all if any are selected. This allows returning to a clean state in at most two clicks. Suggested-by: Jason A. Donenfeld <Jason@zx2c4.com> Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
33e69db436
commit
6f6602ddd1
@ -31,6 +31,8 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import java9.util.Comparators;
|
||||
import java9.util.stream.Collectors;
|
||||
import java9.util.stream.StreamSupport;
|
||||
|
||||
public class AppListDialogFragment extends DialogFragment {
|
||||
|
||||
@ -109,8 +111,12 @@ public class AppListDialogFragment extends DialogFragment {
|
||||
|
||||
final AlertDialog dialog = alertDialogBuilder.create();
|
||||
dialog.setOnShowListener(d -> dialog.getButton(DialogInterface.BUTTON_NEUTRAL).setOnClickListener(view -> {
|
||||
final List<ApplicationData> selectedItems = StreamSupport.stream(appData)
|
||||
.filter(ApplicationData::isExcludedFromTunnel)
|
||||
.collect(Collectors.toList());
|
||||
final boolean excludeAll = selectedItems.isEmpty();
|
||||
for (final ApplicationData app : appData)
|
||||
app.setExcludedFromTunnel(!app.isExcludedFromTunnel());
|
||||
app.setExcludedFromTunnel(excludeAll);
|
||||
}));
|
||||
return dialog;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user