diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-07-30 15:26:33 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-07-30 16:28:03 +0200 |
commit | 75dfa0643be6967b2c99f5a42f179003d41bde3f (patch) | |
tree | 7d3a759a2db83692906a230db6824a1babd8cd85 /app/src/main/java/com/wireguard/android/fragment | |
parent | d5cde431589ee4de8d3d1c019e65f4b9e609a301 (diff) |
Show different color for multiselection
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.java | 29 |
1 files changed, 9 insertions, 20 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 f8b03b25..f9634eba 100644 --- a/app/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java +++ b/app/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java @@ -41,6 +41,7 @@ import com.wireguard.android.model.Tunnel; import com.wireguard.android.util.ExceptionLoggers; import com.wireguard.android.util.ObservableSortedKeyedList; import com.wireguard.android.widget.MonkeyedSnackbar; +import com.wireguard.android.widget.MultiselectableRelativeLayout; import com.wireguard.android.widget.fab.FloatingActionsMenuRecyclerViewScrollListener; import com.wireguard.config.Config; @@ -263,30 +264,20 @@ public class TunnelListFragment extends BaseFragment { super.onPause(); } + private MultiselectableRelativeLayout viewForTunnel(final Tunnel tunnel, final List tunnels) { + return (MultiselectableRelativeLayout)binding.tunnelList.findViewHolderForAdapterPosition(tunnels.indexOf(tunnel)).itemView; + } + @Override public void onSelectedTunnelChanged(@Nullable final Tunnel oldTunnel, @Nullable final Tunnel newTunnel) { if (binding == null) return; Application.getTunnelManager().getTunnels().thenAccept(tunnels -> { if (newTunnel != null) - binding.tunnelList.findViewHolderForAdapterPosition(tunnels.indexOf(newTunnel)).itemView.setActivated(true); + viewForTunnel(newTunnel, tunnels).setSingleSelected(true); if (oldTunnel != null) - binding.tunnelList.findViewHolderForAdapterPosition(tunnels.indexOf(oldTunnel)).itemView.setActivated(false); - + viewForTunnel(oldTunnel, tunnels).setSingleSelected(false); }); - - /* Alternative 1: results in sluggish change: - - if (binding.tunnelList.getAdapter() == null) - return; - - - * Alternative 2: results in overly quick change: - - binding.tunnelList.getAdapter().notifyDataSetChanged(); - - * Hence, we go with the above. - */ } private void onTunnelDeletionFinished(final Integer count, @Nullable final Throwable throwable) { @@ -373,10 +364,9 @@ public class TunnelListFragment extends BaseFragment { }); if (actionMode != null) - binding.getRoot().setActivated(actionModeListener.checkedItems.contains(position)); + ((MultiselectableRelativeLayout)binding.getRoot()).setMultiSelected(actionModeListener.checkedItems.contains(position)); else - binding.getRoot().setActivated(getSelectedTunnel() == tunnel); - + ((MultiselectableRelativeLayout)binding.getRoot()).setSingleSelected(getSelectedTunnel() == tunnel); }); } @@ -433,7 +423,6 @@ public class TunnelListFragment extends BaseFragment { public void onDestroyActionMode(final ActionMode mode) { actionMode = null; resources = null; - checkedItems.clear(); binding.tunnelList.getAdapter().notifyDataSetChanged(); } |