From 6f6602ddd1ef74c474900be4aa8a3b2dff923bea Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Sun, 23 Feb 2020 15:04:05 +0530 Subject: 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 Signed-off-by: Harsh Shandilya --- .../com/wireguard/android/fragment/AppListDialogFragment.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'app/src/main/java/com/wireguard/android') diff --git a/app/src/main/java/com/wireguard/android/fragment/AppListDialogFragment.java b/app/src/main/java/com/wireguard/android/fragment/AppListDialogFragment.java index fc01e86f..43178665 100644 --- a/app/src/main/java/com/wireguard/android/fragment/AppListDialogFragment.java +++ b/app/src/main/java/com/wireguard/android/fragment/AppListDialogFragment.java @@ -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 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; } -- cgit v1.2.3