diff options
author | Harsh Shandilya <me@msfjarvis.dev> | 2020-02-23 15:04:05 +0530 |
---|---|---|
committer | Harsh Shandilya <me@msfjarvis.dev> | 2020-02-23 15:07:39 +0530 |
commit | 88c85b54da589f2dbd69b13df832e9b8358df250 (patch) | |
tree | 2928121e6a9101d178be38eb800ede870018a469 /app/src/main/java | |
parent | 7e59bdf8afe4a432ed21a92f3e5ee8aec8a44a38 (diff) |
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>
Diffstat (limited to 'app/src/main/java')
-rw-r--r-- | app/src/main/java/com/wireguard/android/fragment/AppListDialogFragment.java | 8 |
1 files changed, 7 insertions, 1 deletions
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<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; } |