From 9818a16e510d42fec32aef5a6efcd6d2ae4aa110 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Thu, 29 Jul 2021 18:23:55 +0200 Subject: implement location load indicator in gateway selection cell --- .../bitmaskclient/base/fragments/GatewaySelectionFragment.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java') diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java index d1222cd7..e4d8ca8b 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java @@ -46,6 +46,7 @@ import se.leap.bitmaskclient.base.MainActivity; import se.leap.bitmaskclient.base.models.Location; import se.leap.bitmaskclient.base.utils.PreferenceHelper; import se.leap.bitmaskclient.base.views.IconSwitchEntry; +import se.leap.bitmaskclient.base.views.LocationIndicator; import se.leap.bitmaskclient.eip.EipCommand; import se.leap.bitmaskclient.eip.EipStatus; import se.leap.bitmaskclient.eip.GatewaysManager; @@ -189,7 +190,7 @@ public class GatewaySelectionFragment extends Fragment implements SharedPreferen static class ViewHolder extends RecyclerView.ViewHolder { public AppCompatTextView locationLabel; - public AppCompatTextView qualityLabel; + public LocationIndicator locationIndicator; public AppCompatImageView checkedIcon; public View layout; @@ -197,7 +198,7 @@ public class GatewaySelectionFragment extends Fragment implements SharedPreferen super(v); layout = v; locationLabel = (AppCompatTextView) v.findViewById(R.id.location); - qualityLabel = (AppCompatTextView) v.findViewById(R.id.quality); + locationIndicator = (LocationIndicator) v.findViewById(R.id.quality); checkedIcon = (AppCompatImageView) v.findViewById(R.id.checked_icon); } } @@ -263,7 +264,7 @@ public class GatewaySelectionFragment extends Fragment implements SharedPreferen DrawableCompat.setTint(checkIcon, ContextCompat.getColor(holder.layout.getContext(), R.color.colorSuccess)); holder.checkedIcon.setImageDrawable(checkIcon); holder.checkedIcon.setVisibility(location.selected ? VISIBLE : INVISIBLE); - holder.qualityLabel.setText(getQualityString(location.averageLoad)); + holder.locationIndicator.setLoad(GatewaysManager.Load.getLoadByValue(location.averageLoad)); if (location.selected) { selectedLocation = location; } -- cgit v1.2.3 From 5c4c3cde26fafbd763e4a879dc46ca959b1a7d27 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Fri, 30 Jul 2021 15:46:40 +0200 Subject: draft gateway selection UI according to simlpy secure's proposals --- .../base/fragments/GatewaySelectionFragment.java | 158 ++++++++------------- 1 file changed, 61 insertions(+), 97 deletions(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java') diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java index e4d8ca8b..ee4aea74 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java @@ -19,7 +19,6 @@ package se.leap.bitmaskclient.base.fragments; import android.app.Activity; import android.content.Intent; import android.content.SharedPreferences; -import android.graphics.drawable.Drawable; import android.os.Bundle; import android.util.Log; import android.view.LayoutInflater; @@ -29,23 +28,21 @@ import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.widget.AppCompatButton; -import androidx.appcompat.widget.AppCompatImageView; import androidx.appcompat.widget.AppCompatTextView; -import androidx.core.content.ContextCompat; -import androidx.core.graphics.drawable.DrawableCompat; import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; +import java.lang.ref.WeakReference; import java.util.List; import java.util.Observable; import java.util.Observer; +import de.blinkt.openvpn.core.VpnStatus; import se.leap.bitmaskclient.R; import se.leap.bitmaskclient.base.MainActivity; import se.leap.bitmaskclient.base.models.Location; import se.leap.bitmaskclient.base.utils.PreferenceHelper; -import se.leap.bitmaskclient.base.views.IconSwitchEntry; import se.leap.bitmaskclient.base.views.LocationIndicator; import se.leap.bitmaskclient.eip.EipCommand; import se.leap.bitmaskclient.eip.EipStatus; @@ -55,21 +52,23 @@ import static android.content.Context.MODE_PRIVATE; import static android.view.View.INVISIBLE; import static android.view.View.VISIBLE; import static se.leap.bitmaskclient.base.MainActivity.ACTION_SHOW_VPN_FRAGMENT; -import static se.leap.bitmaskclient.base.models.Constants.PREFERRED_CITY; import static se.leap.bitmaskclient.base.models.Constants.SHARED_PREFERENCES; import static se.leap.bitmaskclient.base.models.Constants.USE_BRIDGES; -import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getPreferredCity; -import static se.leap.bitmaskclient.base.utils.PreferenceHelper.setPreferredCity; -public class GatewaySelectionFragment extends Fragment implements SharedPreferences.OnSharedPreferenceChangeListener, Observer { +interface LocationListSelectionListener { + void onLocationSelected(String name); +} + +public class GatewaySelectionFragment extends Fragment implements SharedPreferences.OnSharedPreferenceChangeListener, Observer, LocationListSelectionListener { private static final String TAG = GatewaySelectionFragment.class.getSimpleName(); private RecyclerView recyclerView; private LocationListAdapter locationListAdapter; - private IconSwitchEntry autoSelectionSwitch; - private AppCompatButton vpnButton; + private AppCompatTextView currentLocationDescription; + private AppCompatTextView currentLocation; + private AppCompatButton autoSelectionButton; private GatewaysManager gatewaysManager; private SharedPreferences preferences; private EipStatus eipStatus; @@ -97,8 +96,8 @@ public class GatewaySelectionFragment extends Fragment implements SharedPreferen public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); initRecyclerView(); - initAutoSelectionSwitch(); - initVpnButton(); + initAutoSelectionButton(); + initCurrentLocationInfoPanel(); eipStatus.addObserver(this); preferences.registerOnSharedPreferenceChangeListener(this); } @@ -113,93 +112,94 @@ public class GatewaySelectionFragment extends Fragment implements SharedPreferen private void initRecyclerView() { - recyclerView = (RecyclerView) getActivity().findViewById(R.id.gatewaySelection_list); + recyclerView = getActivity().findViewById(R.id.gatewaySelection_list); recyclerView.setHasFixedSize(true); LinearLayoutManager layoutManager = new LinearLayoutManager(this.getContext()); recyclerView.setLayoutManager(layoutManager); - locationListAdapter = new LocationListAdapter(gatewaysManager.getGatewayLocations()); + locationListAdapter = new LocationListAdapter(gatewaysManager.getGatewayLocations(), this); recyclerView.setAdapter(locationListAdapter); - recyclerView.setVisibility(getPreferredCity(getContext()) == null ? INVISIBLE : VISIBLE); + recyclerView.setVisibility(VISIBLE); } - private void initAutoSelectionSwitch() { - autoSelectionSwitch = getActivity().findViewById(R.id.automatic_gateway_switch); - autoSelectionSwitch.setSingleLine(false); - autoSelectionSwitch.setSubtitle(getString(R.string.gateway_selection_warning, getString(R.string.app_name))); - autoSelectionSwitch.setChecked(getPreferredCity(getContext()) == null); - autoSelectionSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> { - recyclerView.setVisibility(!isChecked ? VISIBLE : View.GONE); - Log.d(TAG, "autoselection enabled: " + isChecked); - if (isChecked) { - PreferenceHelper.setPreferredCity(getContext(), null); - locationListAdapter.resetSelection(); - } - setVpnButtonState(); + private void initAutoSelectionButton() { + autoSelectionButton = getActivity().findViewById(R.id.automatic_gateway_selection_btn); + autoSelectionButton.setOnClickListener(v -> { + startEipService(null); }); } - private void initVpnButton() { - vpnButton = getActivity().findViewById(R.id.vpn_button); - setVpnButtonState(); - vpnButton.setOnClickListener(v -> { + private void initCurrentLocationInfoPanel() { + currentLocationDescription = getActivity().findViewById(R.id.current_location_description); + currentLocation = getActivity().findViewById(R.id.current_location); + setLocationDescription(EipStatus.getInstance(), PreferenceHelper.getPreferredCity(getContext())); + } + + private void setLocationDescription(EipStatus eipStatus, String preferredCity) { + if (eipStatus.isConnected()) { + currentLocationDescription.setText(preferredCity == null ? + R.string.gateway_selection_automatic_location : + R.string.gateway_selection_manual_location); + currentLocation.setText(VpnStatus.getLastConnectedVpnName()); + currentLocation.setVisibility(VISIBLE); + } else if (preferredCity == null) { + currentLocationDescription.setText(R.string.gateway_selection_automatic_not_connected); + currentLocation.setVisibility(INVISIBLE); + } else { + currentLocationDescription.setText(R.string.gateway_selection_manual_not_connected); + currentLocation.setText(preferredCity); + currentLocation.setVisibility(VISIBLE); + } + } + + protected void startEipService(String preferredCity) { + new Thread(() -> { + PreferenceHelper.setPreferredCity(getContext(), preferredCity); EipCommand.startVPN(getContext(), false); Intent intent = new Intent(getContext(), MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.setAction(ACTION_SHOW_VPN_FRAGMENT); startActivity(intent); - }); - } - - private void setVpnButtonState() { - if (eipStatus.isDisconnected()) { - vpnButton.setText(R.string.vpn_button_turn_on); - } else { - vpnButton.setText(R.string.reconnect); - } - vpnButton.setEnabled( - (locationListAdapter.selectedLocation != null && locationListAdapter.selectedLocation.selected) || - autoSelectionSwitch.isChecked()); + }).start(); } @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if (USE_BRIDGES.equals(key)) { locationListAdapter.updateData(gatewaysManager.getGatewayLocations()); - setVpnButtonState(); - } else if (PREFERRED_CITY.equals(key)) { - setVpnButtonState(); } } + @Override + public void onLocationSelected(String name) { + startEipService(name); + } + @Override public void update(Observable o, Object arg) { if (o instanceof EipStatus) { - eipStatus = (EipStatus) o; Activity activity = getActivity(); if (activity != null) { - activity.runOnUiThread(this::setVpnButtonState); + activity.runOnUiThread(() -> setLocationDescription((EipStatus) o, PreferenceHelper.getPreferredCity(getContext()))); } } - } + static class LocationListAdapter extends RecyclerView.Adapter { private static final String TAG = LocationListAdapter.class.getSimpleName(); private List values; - private Location selectedLocation = null; + private final WeakReference callback; static class ViewHolder extends RecyclerView.ViewHolder { public AppCompatTextView locationLabel; public LocationIndicator locationIndicator; - public AppCompatImageView checkedIcon; public View layout; public ViewHolder(View v) { super(v); layout = v; - locationLabel = (AppCompatTextView) v.findViewById(R.id.location); - locationIndicator = (LocationIndicator) v.findViewById(R.id.quality); - checkedIcon = (AppCompatImageView) v.findViewById(R.id.checked_icon); + locationLabel = v.findViewById(R.id.location); + locationIndicator = v.findViewById(R.id.quality); } } @@ -213,20 +213,14 @@ public class GatewaySelectionFragment extends Fragment implements SharedPreferen notifyItemRemoved(position); } - public void resetSelection() { - if (selectedLocation != null) { - selectedLocation.selected = false; - notifyDataSetChanged(); - } - } - public void updateData(List data) { values = data; notifyDataSetChanged(); } - public LocationListAdapter(List data) { + public LocationListAdapter(List data, LocationListSelectionListener selectionListener) { values = data; + callback = new WeakReference<>(selectionListener); } @NonNull @@ -246,42 +240,12 @@ public class GatewaySelectionFragment extends Fragment implements SharedPreferen holder.locationLabel.setText(location.name); holder.layout.setOnClickListener(v -> { Log.d(TAG, "view at position clicked: " + position); - if (selectedLocation == null) { - selectedLocation = location; - selectedLocation.selected = true; - } else if (selectedLocation.name.equals(location.name)){ - selectedLocation.selected = !selectedLocation.selected; - } else { - selectedLocation.selected = false; - selectedLocation = location; - selectedLocation.selected = true; + LocationListSelectionListener listener = callback.get(); + if (listener != null) { + listener.onLocationSelected(location.name); } - setPreferredCity(holder.layout.getContext(), selectedLocation.selected ? selectedLocation.name : null); - holder.checkedIcon.setVisibility(selectedLocation.selected ? VISIBLE : INVISIBLE); - notifyDataSetChanged(); }); - Drawable checkIcon = DrawableCompat.wrap(holder.layout.getContext().getResources().getDrawable(R.drawable.ic_check_bold)).mutate(); - DrawableCompat.setTint(checkIcon, ContextCompat.getColor(holder.layout.getContext(), R.color.colorSuccess)); - holder.checkedIcon.setImageDrawable(checkIcon); - holder.checkedIcon.setVisibility(location.selected ? VISIBLE : INVISIBLE); holder.locationIndicator.setLoad(GatewaysManager.Load.getLoadByValue(location.averageLoad)); - if (location.selected) { - selectedLocation = location; - } - } - - public String getQualityString(double quality) { - if (quality == 0) { - return ""; - } else if (quality < 0.25) { - return "BAD"; - } else if (quality < 0.6) { - return "AVERAGE"; - } else if (quality < 0.8){ - return "GOOD"; - } else { - return "EXCELLENT"; - } } -- cgit v1.2.3 From 84d604de74d46c9d29d8d8ae20467c0320d2ffb3 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Fri, 30 Jul 2021 18:22:12 +0200 Subject: show bridges icon in gateway selector for locations supporting them --- .../base/fragments/GatewaySelectionFragment.java | 25 ++++++---------------- 1 file changed, 6 insertions(+), 19 deletions(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java') diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java index ee4aea74..450cba4d 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java @@ -18,7 +18,6 @@ package se.leap.bitmaskclient.base.fragments; import android.app.Activity; import android.content.Intent; -import android.content.SharedPreferences; import android.os.Bundle; import android.util.Log; import android.view.LayoutInflater; @@ -28,6 +27,7 @@ import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.widget.AppCompatButton; +import androidx.appcompat.widget.AppCompatImageView; import androidx.appcompat.widget.AppCompatTextView; import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.LinearLayoutManager; @@ -39,6 +39,7 @@ import java.util.Observable; import java.util.Observer; import de.blinkt.openvpn.core.VpnStatus; +import de.blinkt.openvpn.core.connection.Connection; import se.leap.bitmaskclient.R; import se.leap.bitmaskclient.base.MainActivity; import se.leap.bitmaskclient.base.models.Location; @@ -48,18 +49,15 @@ import se.leap.bitmaskclient.eip.EipCommand; import se.leap.bitmaskclient.eip.EipStatus; import se.leap.bitmaskclient.eip.GatewaysManager; -import static android.content.Context.MODE_PRIVATE; import static android.view.View.INVISIBLE; import static android.view.View.VISIBLE; import static se.leap.bitmaskclient.base.MainActivity.ACTION_SHOW_VPN_FRAGMENT; -import static se.leap.bitmaskclient.base.models.Constants.SHARED_PREFERENCES; -import static se.leap.bitmaskclient.base.models.Constants.USE_BRIDGES; interface LocationListSelectionListener { void onLocationSelected(String name); } -public class GatewaySelectionFragment extends Fragment implements SharedPreferences.OnSharedPreferenceChangeListener, Observer, LocationListSelectionListener { +public class GatewaySelectionFragment extends Fragment implements Observer, LocationListSelectionListener { private static final String TAG = GatewaySelectionFragment.class.getSimpleName(); @@ -70,7 +68,6 @@ public class GatewaySelectionFragment extends Fragment implements SharedPreferen private AppCompatTextView currentLocation; private AppCompatButton autoSelectionButton; private GatewaysManager gatewaysManager; - private SharedPreferences preferences; private EipStatus eipStatus; public GatewaySelectionFragment() { @@ -81,7 +78,6 @@ public class GatewaySelectionFragment extends Fragment implements SharedPreferen public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); gatewaysManager = new GatewaysManager(getContext()); - preferences = getContext().getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE); eipStatus = EipStatus.getInstance(); } @@ -98,19 +94,14 @@ public class GatewaySelectionFragment extends Fragment implements SharedPreferen initRecyclerView(); initAutoSelectionButton(); initCurrentLocationInfoPanel(); - eipStatus.addObserver(this); - preferences.registerOnSharedPreferenceChangeListener(this); } @Override public void onDestroyView() { super.onDestroyView(); - preferences.unregisterOnSharedPreferenceChangeListener(this); eipStatus.deleteObserver(this); } - - private void initRecyclerView() { recyclerView = getActivity().findViewById(R.id.gatewaySelection_list); recyclerView.setHasFixedSize(true); @@ -162,13 +153,6 @@ public class GatewaySelectionFragment extends Fragment implements SharedPreferen }).start(); } - @Override - public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { - if (USE_BRIDGES.equals(key)) { - locationListAdapter.updateData(gatewaysManager.getGatewayLocations()); - } - } - @Override public void onLocationSelected(String name) { startEipService(name); @@ -193,6 +177,7 @@ public class GatewaySelectionFragment extends Fragment implements SharedPreferen static class ViewHolder extends RecyclerView.ViewHolder { public AppCompatTextView locationLabel; public LocationIndicator locationIndicator; + public AppCompatImageView bridgeView; public View layout; public ViewHolder(View v) { @@ -200,6 +185,7 @@ public class GatewaySelectionFragment extends Fragment implements SharedPreferen layout = v; locationLabel = v.findViewById(R.id.location); locationIndicator = v.findViewById(R.id.quality); + bridgeView = v.findViewById(R.id.bridge_image); } } @@ -246,6 +232,7 @@ public class GatewaySelectionFragment extends Fragment implements SharedPreferen } }); holder.locationIndicator.setLoad(GatewaysManager.Load.getLoadByValue(location.averageLoad)); + holder.bridgeView.setVisibility(location.supportedTransports.contains(Connection.TransportType.OBFS4) ? VISIBLE : View.GONE); } -- cgit v1.2.3 From d8b11c392a492ef05b1a454c298f5244a694553b Mon Sep 17 00:00:00 2001 From: cyBerta Date: Fri, 30 Jul 2021 20:38:23 +0200 Subject: ask user to change location or disable bridges if manually selected location doesn't support bridges --- .../base/fragments/GatewaySelectionFragment.java | 32 ++++++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java') diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java index 450cba4d..2dcb0ec9 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java @@ -45,16 +45,21 @@ import se.leap.bitmaskclient.base.MainActivity; import se.leap.bitmaskclient.base.models.Location; import se.leap.bitmaskclient.base.utils.PreferenceHelper; import se.leap.bitmaskclient.base.views.LocationIndicator; +import se.leap.bitmaskclient.eip.EIP; import se.leap.bitmaskclient.eip.EipCommand; import se.leap.bitmaskclient.eip.EipStatus; import se.leap.bitmaskclient.eip.GatewaysManager; import static android.view.View.INVISIBLE; import static android.view.View.VISIBLE; +import static de.blinkt.openvpn.core.connection.Connection.TransportType.OBFS4; +import static de.blinkt.openvpn.core.connection.Connection.TransportType.OPENVPN; +import static se.leap.bitmaskclient.base.MainActivity.ACTION_SHOW_DIALOG_FRAGMENT; import static se.leap.bitmaskclient.base.MainActivity.ACTION_SHOW_VPN_FRAGMENT; +import static se.leap.bitmaskclient.base.models.Constants.LOCATION; interface LocationListSelectionListener { - void onLocationSelected(String name); + void onLocationSelected(Location location); } public class GatewaySelectionFragment extends Fragment implements Observer, LocationListSelectionListener { @@ -154,8 +159,24 @@ public class GatewaySelectionFragment extends Fragment implements Observer, Loca } @Override - public void onLocationSelected(String name) { - startEipService(name); + public void onLocationSelected(Location location) { + String name = location.name; + Connection.TransportType selectedTransport = PreferenceHelper.getUsePluggableTransports(getContext()) ? OBFS4 : OPENVPN; + if (location.supportedTransports.contains(selectedTransport)) { + startEipService(name); + } else { + askToChangeTransport(name); + } + } + + private void askToChangeTransport(String name) { + Intent intent = new Intent(getContext(), MainActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); + intent.setAction(ACTION_SHOW_DIALOG_FRAGMENT); + intent.putExtra(EIP.ERRORID, EIP.EIPErrors.TRANSPORT_NOT_SUPPORTED.toString()); + intent.putExtra(EIP.ERRORS, getString(R.string.warning_bridges_not_supported, name)); + intent.putExtra(LOCATION, name); + startActivity(intent); } @Override @@ -168,7 +189,6 @@ public class GatewaySelectionFragment extends Fragment implements Observer, Loca } } - static class LocationListAdapter extends RecyclerView.Adapter { private static final String TAG = LocationListAdapter.class.getSimpleName(); private List values; @@ -228,11 +248,11 @@ public class GatewaySelectionFragment extends Fragment implements Observer, Loca Log.d(TAG, "view at position clicked: " + position); LocationListSelectionListener listener = callback.get(); if (listener != null) { - listener.onLocationSelected(location.name); + listener.onLocationSelected(location); } }); holder.locationIndicator.setLoad(GatewaysManager.Load.getLoadByValue(location.averageLoad)); - holder.bridgeView.setVisibility(location.supportedTransports.contains(Connection.TransportType.OBFS4) ? VISIBLE : View.GONE); + holder.bridgeView.setVisibility(location.supportedTransports.contains(OBFS4) ? VISIBLE : View.GONE); } -- cgit v1.2.3 From 7b9a2f0a807fb6e5782888f444efb1142da1f20b Mon Sep 17 00:00:00 2001 From: cyBerta Date: Sat, 31 Jul 2021 18:48:06 +0200 Subject: add missing eip status observer registration in GatewaySelectionFragment --- .../se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java | 1 + 1 file changed, 1 insertion(+) (limited to 'app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java') diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java index 2dcb0ec9..c0b9d2d4 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java @@ -84,6 +84,7 @@ public class GatewaySelectionFragment extends Fragment implements Observer, Loca super.onCreate(savedInstanceState); gatewaysManager = new GatewaysManager(getContext()); eipStatus = EipStatus.getInstance(); + eipStatus.addObserver(this); } @Override -- cgit v1.2.3 From f3e23d06d8bee4c4212e606621b92a50dd7034ae Mon Sep 17 00:00:00 2001 From: cyBerta Date: Sun, 14 Nov 2021 20:02:16 +0100 Subject: fix preference renaming --- .../se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java') diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java index c0b9d2d4..4a431dff 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java @@ -162,7 +162,7 @@ public class GatewaySelectionFragment extends Fragment implements Observer, Loca @Override public void onLocationSelected(Location location) { String name = location.name; - Connection.TransportType selectedTransport = PreferenceHelper.getUsePluggableTransports(getContext()) ? OBFS4 : OPENVPN; + Connection.TransportType selectedTransport = PreferenceHelper.getUseBridges(getContext()) ? OBFS4 : OPENVPN; if (location.supportedTransports.contains(selectedTransport)) { startEipService(name); } else { -- cgit v1.2.3 From e4cd4773651ef4080a2e8853c5e348e24153467d Mon Sep 17 00:00:00 2001 From: cyBerta Date: Sat, 20 Nov 2021 16:35:30 +0100 Subject: implement a selection indicator for location list --- .../base/fragments/GatewaySelectionFragment.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java') diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java index 4a431dff..c98abd74 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java @@ -29,6 +29,7 @@ import androidx.annotation.Nullable; import androidx.appcompat.widget.AppCompatButton; import androidx.appcompat.widget.AppCompatImageView; import androidx.appcompat.widget.AppCompatTextView; +import androidx.core.view.LayoutInflaterCompat; import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -50,6 +51,7 @@ import se.leap.bitmaskclient.eip.EipCommand; import se.leap.bitmaskclient.eip.EipStatus; import se.leap.bitmaskclient.eip.GatewaysManager; +import static android.view.View.GONE; import static android.view.View.INVISIBLE; import static android.view.View.VISIBLE; import static de.blinkt.openvpn.core.connection.Connection.TransportType.OBFS4; @@ -199,6 +201,7 @@ public class GatewaySelectionFragment extends Fragment implements Observer, Loca public AppCompatTextView locationLabel; public LocationIndicator locationIndicator; public AppCompatImageView bridgeView; + public AppCompatImageView selectedView; public View layout; public ViewHolder(View v) { @@ -207,6 +210,7 @@ public class GatewaySelectionFragment extends Fragment implements Observer, Loca locationLabel = v.findViewById(R.id.location); locationIndicator = v.findViewById(R.id.quality); bridgeView = v.findViewById(R.id.bridge_image); + selectedView = v.findViewById(R.id.selected); } } @@ -249,11 +253,17 @@ public class GatewaySelectionFragment extends Fragment implements Observer, Loca Log.d(TAG, "view at position clicked: " + position); LocationListSelectionListener listener = callback.get(); if (listener != null) { + for (Location l : values) { + l.selected = false; + } + location.selected = !location.selected; + notifyDataSetChanged(); listener.onLocationSelected(location); } }); holder.locationIndicator.setLoad(GatewaysManager.Load.getLoadByValue(location.averageLoad)); - holder.bridgeView.setVisibility(location.supportedTransports.contains(OBFS4) ? VISIBLE : View.GONE); + holder.bridgeView.setVisibility(location.supportedTransports.contains(OBFS4) ? VISIBLE : GONE); + holder.selectedView.setVisibility(location.selected ? VISIBLE : INVISIBLE); } -- cgit v1.2.3 From a6cd31ae8624f830454adc627ac3a6be323a5333 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Sun, 21 Nov 2021 19:36:46 +0100 Subject: implement new gateway selection UI, using same UX principles as for desktop --- .../base/fragments/GatewaySelectionFragment.java | 120 +++++++++------------ 1 file changed, 50 insertions(+), 70 deletions(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java') diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java index c98abd74..12aedb12 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java @@ -17,6 +17,7 @@ package se.leap.bitmaskclient.base.fragments; import android.app.Activity; +import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.util.Log; @@ -26,10 +27,6 @@ import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.widget.AppCompatButton; -import androidx.appcompat.widget.AppCompatImageView; -import androidx.appcompat.widget.AppCompatTextView; -import androidx.core.view.LayoutInflaterCompat; import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -45,14 +42,12 @@ import se.leap.bitmaskclient.R; import se.leap.bitmaskclient.base.MainActivity; import se.leap.bitmaskclient.base.models.Location; import se.leap.bitmaskclient.base.utils.PreferenceHelper; -import se.leap.bitmaskclient.base.views.LocationIndicator; +import se.leap.bitmaskclient.base.views.SelectLocationEntry; import se.leap.bitmaskclient.eip.EIP; import se.leap.bitmaskclient.eip.EipCommand; import se.leap.bitmaskclient.eip.EipStatus; import se.leap.bitmaskclient.eip.GatewaysManager; -import static android.view.View.GONE; -import static android.view.View.INVISIBLE; import static android.view.View.VISIBLE; import static de.blinkt.openvpn.core.connection.Connection.TransportType.OBFS4; import static de.blinkt.openvpn.core.connection.Connection.TransportType.OPENVPN; @@ -61,7 +56,7 @@ import static se.leap.bitmaskclient.base.MainActivity.ACTION_SHOW_VPN_FRAGMENT; import static se.leap.bitmaskclient.base.models.Constants.LOCATION; interface LocationListSelectionListener { - void onLocationSelected(Location location); + void onLocationManuallySelected(Location location); } public class GatewaySelectionFragment extends Fragment implements Observer, LocationListSelectionListener { @@ -71,9 +66,7 @@ public class GatewaySelectionFragment extends Fragment implements Observer, Loca private RecyclerView recyclerView; private LocationListAdapter locationListAdapter; - private AppCompatTextView currentLocationDescription; - private AppCompatTextView currentLocation; - private AppCompatButton autoSelectionButton; + private SelectLocationEntry recommendedLocation; private GatewaysManager gatewaysManager; private EipStatus eipStatus; @@ -100,8 +93,7 @@ public class GatewaySelectionFragment extends Fragment implements Observer, Loca public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); initRecyclerView(); - initAutoSelectionButton(); - initCurrentLocationInfoPanel(); + initRecommendedLocationEntry(); } @Override @@ -120,40 +112,40 @@ public class GatewaySelectionFragment extends Fragment implements Observer, Loca recyclerView.setVisibility(VISIBLE); } - private void initAutoSelectionButton() { - autoSelectionButton = getActivity().findViewById(R.id.automatic_gateway_selection_btn); - autoSelectionButton.setOnClickListener(v -> { + private void initRecommendedLocationEntry() { + recommendedLocation = getActivity().findViewById(R.id.recommended_location); + recommendedLocation.setTitle(getString(R.string.gateway_selection_automatic_location)); + recommendedLocation.showDivider(true); + recommendedLocation.setOnClickListener(v -> { + recommendedLocation.setSelected(true); + locationListAdapter.unselectAll(); startEipService(null); }); + updateRecommendedLocation(); } - private void initCurrentLocationInfoPanel() { - currentLocationDescription = getActivity().findViewById(R.id.current_location_description); - currentLocation = getActivity().findViewById(R.id.current_location); - setLocationDescription(EipStatus.getInstance(), PreferenceHelper.getPreferredCity(getContext())); - } - - private void setLocationDescription(EipStatus eipStatus, String preferredCity) { - if (eipStatus.isConnected()) { - currentLocationDescription.setText(preferredCity == null ? - R.string.gateway_selection_automatic_location : - R.string.gateway_selection_manual_location); - currentLocation.setText(VpnStatus.getLastConnectedVpnName()); - currentLocation.setVisibility(VISIBLE); - } else if (preferredCity == null) { - currentLocationDescription.setText(R.string.gateway_selection_automatic_not_connected); - currentLocation.setVisibility(INVISIBLE); - } else { - currentLocationDescription.setText(R.string.gateway_selection_manual_not_connected); - currentLocation.setText(preferredCity); - currentLocation.setVisibility(VISIBLE); + private void updateRecommendedLocation() { + Location location = new Location(); + boolean isManualSelection = PreferenceHelper.getPreferredCity(getContext()) != null; + if (!isManualSelection && eipStatus.isConnected()) { + try { + location = gatewaysManager.getLocation(VpnStatus.getCurrentlyConnectingVpnName()).clone(); + } catch (NullPointerException | CloneNotSupportedException e) { + e.printStackTrace(); + } } + location.selected = !isManualSelection; + recommendedLocation.setLocation(location); } protected void startEipService(String preferredCity) { new Thread(() -> { - PreferenceHelper.setPreferredCity(getContext(), preferredCity); - EipCommand.startVPN(getContext(), false); + Context context = getContext(); + if (context == null) { + return; + } + PreferenceHelper.setPreferredCity(context, preferredCity); + EipCommand.startVPN(context, false); Intent intent = new Intent(getContext(), MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.setAction(ACTION_SHOW_VPN_FRAGMENT); @@ -162,7 +154,8 @@ public class GatewaySelectionFragment extends Fragment implements Observer, Loca } @Override - public void onLocationSelected(Location location) { + public void onLocationManuallySelected(Location location) { + recommendedLocation.setSelected(false); String name = location.name; Connection.TransportType selectedTransport = PreferenceHelper.getUseBridges(getContext()) ? OBFS4 : OPENVPN; if (location.supportedTransports.contains(selectedTransport)) { @@ -185,32 +178,25 @@ public class GatewaySelectionFragment extends Fragment implements Observer, Loca @Override public void update(Observable o, Object arg) { if (o instanceof EipStatus) { + eipStatus = (EipStatus) o; Activity activity = getActivity(); if (activity != null) { - activity.runOnUiThread(() -> setLocationDescription((EipStatus) o, PreferenceHelper.getPreferredCity(getContext()))); + activity.runOnUiThread(this::updateRecommendedLocation); } } } static class LocationListAdapter extends RecyclerView.Adapter { private static final String TAG = LocationListAdapter.class.getSimpleName(); - private List values; + private final List values; private final WeakReference callback; static class ViewHolder extends RecyclerView.ViewHolder { - public AppCompatTextView locationLabel; - public LocationIndicator locationIndicator; - public AppCompatImageView bridgeView; - public AppCompatImageView selectedView; - public View layout; + public SelectLocationEntry entry; - public ViewHolder(View v) { + public ViewHolder(SelectLocationEntry v) { super(v); - layout = v; - locationLabel = v.findViewById(R.id.location); - locationIndicator = v.findViewById(R.id.quality); - bridgeView = v.findViewById(R.id.bridge_image); - selectedView = v.findViewById(R.id.selected); + entry = v; } } @@ -224,8 +210,10 @@ public class GatewaySelectionFragment extends Fragment implements Observer, Loca notifyItemRemoved(position); } - public void updateData(List data) { - values = data; + public void unselectAll() { + for (Location l : values) { + l.selected = false; + } notifyDataSetChanged(); } @@ -238,35 +226,27 @@ public class GatewaySelectionFragment extends Fragment implements Observer, Loca @Override public LocationListAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { - LayoutInflater inflater = LayoutInflater.from( - parent.getContext()); - View v = inflater.inflate(R.layout.v_select_text_list_item, parent, false); - return new ViewHolder(v); + SelectLocationEntry entry = new SelectLocationEntry(parent.getContext()); + return new ViewHolder(entry); } // Replace the contents of a view (invoked by the layout manager) @Override public void onBindViewHolder(ViewHolder holder, final int position) { final Location location = values.get(position); - holder.locationLabel.setText(location.name); - holder.layout.setOnClickListener(v -> { - Log.d(TAG, "view at position clicked: " + position); + holder.entry.setLocation(location); + holder.entry.setOnClickListener(v -> { + Log.d(TAG, "onClick view at position clicked: " + position); LocationListSelectionListener listener = callback.get(); if (listener != null) { - for (Location l : values) { - l.selected = false; - } - location.selected = !location.selected; + unselectAll(); + location.selected = true; + listener.onLocationManuallySelected(location); notifyDataSetChanged(); - listener.onLocationSelected(location); } }); - holder.locationIndicator.setLoad(GatewaysManager.Load.getLoadByValue(location.averageLoad)); - holder.bridgeView.setVisibility(location.supportedTransports.contains(OBFS4) ? VISIBLE : GONE); - holder.selectedView.setVisibility(location.selected ? VISIBLE : INVISIBLE); } - @Override public int getItemCount() { return values.size(); -- cgit v1.2.3 From 9bf787465a3ae22c76249317496c8927b22ffdb4 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Tue, 23 Nov 2021 12:32:07 +0100 Subject: calculate and show gateway load related to transport --- .../base/fragments/GatewaySelectionFragment.java | 44 ++++++++++++++++++---- 1 file changed, 36 insertions(+), 8 deletions(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java') diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java index 12aedb12..51ebe359 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java @@ -19,6 +19,7 @@ package se.leap.bitmaskclient.base.fragments; import android.app.Activity; import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.os.Bundle; import android.util.Log; import android.view.LayoutInflater; @@ -48,18 +49,21 @@ import se.leap.bitmaskclient.eip.EipCommand; import se.leap.bitmaskclient.eip.EipStatus; import se.leap.bitmaskclient.eip.GatewaysManager; +import static android.content.Context.MODE_PRIVATE; import static android.view.View.VISIBLE; import static de.blinkt.openvpn.core.connection.Connection.TransportType.OBFS4; import static de.blinkt.openvpn.core.connection.Connection.TransportType.OPENVPN; import static se.leap.bitmaskclient.base.MainActivity.ACTION_SHOW_DIALOG_FRAGMENT; import static se.leap.bitmaskclient.base.MainActivity.ACTION_SHOW_VPN_FRAGMENT; import static se.leap.bitmaskclient.base.models.Constants.LOCATION; +import static se.leap.bitmaskclient.base.models.Constants.SHARED_PREFERENCES; +import static se.leap.bitmaskclient.base.models.Constants.USE_BRIDGES; interface LocationListSelectionListener { void onLocationManuallySelected(Location location); } -public class GatewaySelectionFragment extends Fragment implements Observer, LocationListSelectionListener { +public class GatewaySelectionFragment extends Fragment implements Observer, LocationListSelectionListener, SharedPreferences.OnSharedPreferenceChangeListener { private static final String TAG = GatewaySelectionFragment.class.getSimpleName(); @@ -69,6 +73,8 @@ public class GatewaySelectionFragment extends Fragment implements Observer, Loca private SelectLocationEntry recommendedLocation; private GatewaysManager gatewaysManager; private EipStatus eipStatus; + private SharedPreferences preferences; + private Connection.TransportType selectedTransport; public GatewaySelectionFragment() { // Required empty public constructor @@ -80,6 +86,9 @@ public class GatewaySelectionFragment extends Fragment implements Observer, Loca gatewaysManager = new GatewaysManager(getContext()); eipStatus = EipStatus.getInstance(); eipStatus.addObserver(this); + preferences = getContext().getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE); + selectedTransport = PreferenceHelper.getUseBridges(preferences) ? OBFS4 : OPENVPN; + preferences.registerOnSharedPreferenceChangeListener(this); } @Override @@ -100,6 +109,7 @@ public class GatewaySelectionFragment extends Fragment implements Observer, Loca public void onDestroyView() { super.onDestroyView(); eipStatus.deleteObserver(this); + preferences.unregisterOnSharedPreferenceChangeListener(this); } private void initRecyclerView() { @@ -107,7 +117,7 @@ public class GatewaySelectionFragment extends Fragment implements Observer, Loca recyclerView.setHasFixedSize(true); LinearLayoutManager layoutManager = new LinearLayoutManager(this.getContext()); recyclerView.setLayoutManager(layoutManager); - locationListAdapter = new LocationListAdapter(gatewaysManager.getGatewayLocations(), this); + locationListAdapter = new LocationListAdapter(gatewaysManager.getGatewayLocations(), this, selectedTransport); recyclerView.setAdapter(locationListAdapter); recyclerView.setVisibility(VISIBLE); } @@ -135,7 +145,10 @@ public class GatewaySelectionFragment extends Fragment implements Observer, Loca } } location.selected = !isManualSelection; - recommendedLocation.setLocation(location); + if (!isManualSelection) { + locationListAdapter.unselectAll(); + } + recommendedLocation.setLocation(location, selectedTransport); } protected void startEipService(String preferredCity) { @@ -156,11 +169,11 @@ public class GatewaySelectionFragment extends Fragment implements Observer, Loca @Override public void onLocationManuallySelected(Location location) { recommendedLocation.setSelected(false); - String name = location.name; - Connection.TransportType selectedTransport = PreferenceHelper.getUseBridges(getContext()) ? OBFS4 : OPENVPN; - if (location.supportedTransports.contains(selectedTransport)) { + String name = location.getName(); + if (location.supportsTransport(selectedTransport)) { startEipService(name); } else { + locationListAdapter.unselectAll(); askToChangeTransport(name); } } @@ -186,8 +199,17 @@ public class GatewaySelectionFragment extends Fragment implements Observer, Loca } } + @Override + public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { + if (key.equals(USE_BRIDGES)) { + selectedTransport = PreferenceHelper.getUseBridges(sharedPreferences) ? OBFS4 : OPENVPN; + locationListAdapter.updateTransport(selectedTransport); + } + } + static class LocationListAdapter extends RecyclerView.Adapter { private static final String TAG = LocationListAdapter.class.getSimpleName(); + private Connection.TransportType transport; private final List values; private final WeakReference callback; @@ -210,6 +232,11 @@ public class GatewaySelectionFragment extends Fragment implements Observer, Loca notifyItemRemoved(position); } + public void updateTransport(Connection.TransportType transportType) { + transport = transportType; + notifyDataSetChanged(); + } + public void unselectAll() { for (Location l : values) { l.selected = false; @@ -217,9 +244,10 @@ public class GatewaySelectionFragment extends Fragment implements Observer, Loca notifyDataSetChanged(); } - public LocationListAdapter(List data, LocationListSelectionListener selectionListener) { + public LocationListAdapter(List data, LocationListSelectionListener selectionListener, Connection.TransportType selectedTransport) { values = data; callback = new WeakReference<>(selectionListener); + transport = selectedTransport; } @NonNull @@ -234,7 +262,7 @@ public class GatewaySelectionFragment extends Fragment implements Observer, Loca @Override public void onBindViewHolder(ViewHolder holder, final int position) { final Location location = values.get(position); - holder.entry.setLocation(location); + holder.entry.setLocation(location, transport); holder.entry.setOnClickListener(v -> { Log.d(TAG, "onClick view at position clicked: " + position); LocationListSelectionListener listener = callback.get(); -- cgit v1.2.3 From f29ee8ac7378408e070be1130c9cadc8e947ddb3 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Tue, 23 Nov 2021 14:51:33 +0100 Subject: sort locations by transport --- .../bitmaskclient/base/fragments/GatewaySelectionFragment.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java') diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java index 51ebe359..e3845164 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java @@ -117,7 +117,7 @@ public class GatewaySelectionFragment extends Fragment implements Observer, Loca recyclerView.setHasFixedSize(true); LinearLayoutManager layoutManager = new LinearLayoutManager(this.getContext()); recyclerView.setLayoutManager(layoutManager); - locationListAdapter = new LocationListAdapter(gatewaysManager.getGatewayLocations(), this, selectedTransport); + locationListAdapter = new LocationListAdapter(gatewaysManager.getSortedGatewayLocations(selectedTransport), this, selectedTransport); recyclerView.setAdapter(locationListAdapter); recyclerView.setVisibility(VISIBLE); } @@ -203,14 +203,15 @@ public class GatewaySelectionFragment extends Fragment implements Observer, Loca public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if (key.equals(USE_BRIDGES)) { selectedTransport = PreferenceHelper.getUseBridges(sharedPreferences) ? OBFS4 : OPENVPN; - locationListAdapter.updateTransport(selectedTransport); + gatewaysManager.updateTransport(selectedTransport); + locationListAdapter.updateTransport(selectedTransport, gatewaysManager); } } static class LocationListAdapter extends RecyclerView.Adapter { private static final String TAG = LocationListAdapter.class.getSimpleName(); private Connection.TransportType transport; - private final List values; + private List values; private final WeakReference callback; static class ViewHolder extends RecyclerView.ViewHolder { @@ -232,8 +233,9 @@ public class GatewaySelectionFragment extends Fragment implements Observer, Loca notifyItemRemoved(position); } - public void updateTransport(Connection.TransportType transportType) { + public void updateTransport(Connection.TransportType transportType, GatewaysManager gatewaysManager) { transport = transportType; + values = gatewaysManager.getSortedGatewayLocations(transportType); notifyDataSetChanged(); } -- cgit v1.2.3