From d366b98aafdb0b211ed7b3870354477ffc250462 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 +++++--------------- .../leap/bitmaskclient/base/models/Location.java | 27 ++++++++++++++++++++-- 2 files changed, 31 insertions(+), 21 deletions(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/base') 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); } diff --git a/app/src/main/java/se/leap/bitmaskclient/base/models/Location.java b/app/src/main/java/se/leap/bitmaskclient/base/models/Location.java index 8e032d18..3ec7d38c 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/models/Location.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/models/Location.java @@ -1,16 +1,37 @@ +/** + * Copyright (c) 2021 LEAP Encryption Access Project and contributers + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package se.leap.bitmaskclient.base.models; import androidx.annotation.NonNull; +import java.util.HashSet; +import de.blinkt.openvpn.core.connection.Connection; public class Location { @NonNull public String name; + @NonNull public HashSet supportedTransports; public double averageLoad; public int numberOfGateways; - public Location(@NonNull String name, double averageLoad, int numberOfGateways) { + public Location(@NonNull String name, double averageLoad, int numberOfGateways, @NonNull HashSet supportedTransports) { this.name = name; this.averageLoad = averageLoad; this.numberOfGateways = numberOfGateways; + this.supportedTransports = supportedTransports; } @Override @@ -22,7 +43,8 @@ public class Location { if (Double.compare(location.averageLoad, averageLoad) != 0) return false; if (numberOfGateways != location.numberOfGateways) return false; - return name.equals(location.name); + if (!name.equals(location.name)) return false; + return supportedTransports.equals(location.supportedTransports); } @Override @@ -30,6 +52,7 @@ public class Location { int result; long temp; result = name.hashCode(); + result = 31 * result + supportedTransports.hashCode(); temp = Double.doubleToLongBits(averageLoad); result = 31 * result + (int) (temp ^ (temp >>> 32)); result = 31 * result + numberOfGateways; -- cgit v1.2.3