summaryrefslogtreecommitdiffhomepage
path: root/app/src/main/java/com/wireguard/android/fragment
diff options
context:
space:
mode:
authorEric Kuck <eric@bluelinelabs.com>2018-07-25 19:30:34 -0500
committerJason A. Donenfeld <Jason@zx2c4.com>2018-07-26 05:17:43 +0200
commit9652fe99df68db5c483ea8e170f6e09f06a5e0d1 (patch)
treed88fa5ef4fa4e53d605e6bce9d788960a80642de /app/src/main/java/com/wireguard/android/fragment
parent62d8beff9693080225fe550d82f105ba3cde5df2 (diff)
TunnelDetailFragment now restores state correctly after process death
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src/main/java/com/wireguard/android/fragment')
-rw-r--r--app/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java36
1 files changed, 20 insertions, 16 deletions
diff --git a/app/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java b/app/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java
index e2291f9c..7258f0a0 100644
--- a/app/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java
+++ b/app/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java
@@ -313,7 +313,7 @@ public class TunnelListFragment extends BaseFragment {
}
binding.setFragment(this);
- binding.setTunnels(Application.getTunnelManager().getTunnels());
+ Application.getTunnelManager().getTunnels().thenAccept(binding::setTunnels);
binding.setRowConfigurationHandler((ObservableKeyedRecyclerViewAdapter.RowConfigurationHandler<TunnelListItemBinding, Tunnel>) (binding, tunnel, position) -> {
binding.setFragment(this);
binding.getRoot().setOnClickListener(clicked -> {
@@ -341,25 +341,29 @@ public class TunnelListFragment extends BaseFragment {
public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_action_delete:
- final Collection<Tunnel> tunnelsToDelete = new ArrayList<>();
- for (final Integer position : checkedItems) {
- tunnelsToDelete.add(Application.getTunnelManager().getTunnels().get(position));
- }
-
- final CompletableFuture[] futures = StreamSupport.stream(tunnelsToDelete)
- .map(Tunnel::delete)
- .toArray(CompletableFuture[]::new);
- CompletableFuture.allOf(futures)
- .thenApply(x -> futures.length)
- .whenComplete(TunnelListFragment.this::onTunnelDeletionFinished);
-
+ final Iterable<Integer> copyCheckedItems = new HashSet<>(checkedItems);
+ Application.getTunnelManager().getTunnels().thenAccept(tunnels -> {
+ final Collection<Tunnel> tunnelsToDelete = new ArrayList<>();
+ for (final Integer position : copyCheckedItems)
+ tunnelsToDelete.add(tunnels.get(position));
+
+ final CompletableFuture[] futures = StreamSupport.stream(tunnelsToDelete)
+ .map(Tunnel::delete)
+ .toArray(CompletableFuture[]::new);
+ CompletableFuture.allOf(futures)
+ .thenApply(x -> futures.length)
+ .whenComplete(TunnelListFragment.this::onTunnelDeletionFinished);
+
+ });
checkedItems.clear();
mode.finish();
return true;
case R.id.menu_action_select_all:
- for (int i = 0; i < Application.getTunnelManager().getTunnels().size(); ++i) {
- setItemChecked(i, true);
- }
+ Application.getTunnelManager().getTunnels().thenAccept(tunnels -> {
+ for (int i = 0; i < tunnels.size(); ++i) {
+ setItemChecked(i, true);
+ }
+ });
return true;
default:
return false;