summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2021-11-20 16:35:30 +0100
committercyBerta <cyberta@riseup.net>2021-11-20 16:35:56 +0100
commite4cd4773651ef4080a2e8853c5e348e24153467d (patch)
treeca829fc1b8cc64a22ed90f9bc8e4b512eba2129f
parentd536ef7bd7199deefab859faed3e85f9d7316b4f (diff)
implement a selection indicator for location list
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java12
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/models/Location.java4
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java11
-rw-r--r--app/src/main/res/layout/v_select_text_list_item.xml29
4 files changed, 45 insertions, 11 deletions
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);
}
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 3ec7d38c..3eb82f22 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
@@ -26,12 +26,14 @@ public class Location {
@NonNull public HashSet<Connection.TransportType> supportedTransports;
public double averageLoad;
public int numberOfGateways;
+ public boolean selected;
- public Location(@NonNull String name, double averageLoad, int numberOfGateways, @NonNull HashSet<Connection.TransportType> supportedTransports) {
+ public Location(@NonNull String name, double averageLoad, int numberOfGateways, @NonNull HashSet<Connection.TransportType> supportedTransports, boolean selected) {
this.name = name;
this.averageLoad = averageLoad;
this.numberOfGateways = numberOfGateways;
this.supportedTransports = supportedTransports;
+ this.selected = selected;
}
@Override
diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java
index dbb2a914..8e3e20df 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java
@@ -43,6 +43,7 @@ import de.blinkt.openvpn.core.connection.Connection;
import se.leap.bitmaskclient.base.models.Location;
import se.leap.bitmaskclient.base.models.Provider;
import se.leap.bitmaskclient.base.models.ProviderObservable;
+import se.leap.bitmaskclient.base.utils.PreferenceHelper;
import static de.blinkt.openvpn.core.connection.Connection.TransportType.OBFS4;
import static de.blinkt.openvpn.core.connection.Connection.TransportType.OPENVPN;
@@ -138,6 +139,7 @@ public class GatewaysManager {
HashMap<String, Integer> locationNames = new HashMap<>();
ArrayList<Location> locations = new ArrayList<>();
ArrayList<Gateway> gateways = getSortedGateways();
+ String preferredCity = PreferenceHelper.getPreferredCity(context);
for (Gateway gateway : gateways) {
String name = gateway.getName();
if (name == null) {
@@ -145,19 +147,20 @@ public class GatewaysManager {
continue;
}
- if (!locationNames.containsKey(gateway.getName())) {
- locationNames.put(gateway.getName(), locations.size());
+ if (!locationNames.containsKey(name)) {
+ locationNames.put(name, locations.size());
// fake values for now
Random rand = new Random();
double averageLoad = rand.nextDouble(); //location.averageLoad;
- Log.d(TAG, "getGatewayLocations - new averageLoad (" + gateway.getName() + " - " + gateway.getHost()+ "): " + averageLoad);
+ Log.d(TAG, "getGatewayLocations - new averageLoad (" + name + " - " + gateway.getHost()+ "): " + averageLoad);
Location location = new Location(
gateway.getName(),
averageLoad
/*gateway.getFullness()*/,
1,
- gateway.getSupportedTransports()
+ gateway.getSupportedTransports(),
+ name.equals(preferredCity)
);
locations.add(location);
} else {
diff --git a/app/src/main/res/layout/v_select_text_list_item.xml b/app/src/main/res/layout/v_select_text_list_item.xml
index 663b5b4d..b0cfac34 100644
--- a/app/src/main/res/layout/v_select_text_list_item.xml
+++ b/app/src/main/res/layout/v_select_text_list_item.xml
@@ -1,26 +1,45 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/item_container"
android:layout_height="?android:attr/listPreferredItemHeightSmall"
android:layout_width="match_parent"
android:orientation="horizontal"
- xmlns:tools="http://schemas.android.com/tools">
+ android:clickable="true"
+ android:focusable="true"
+ android:background="?attr/selectableItemBackground">
<!-- views are composed right to left -->
+ <androidx.appcompat.widget.AppCompatImageView
+ android:id="@+id/selected"
+ android:layout_width="40dp"
+ android:layout_height="match_parent"
+ android:layout_alignParentRight="true"
+ android:layout_alignParentEnd="true"
+ android:src="@drawable/ic_check_bold"
+ android:tint="@color/green200"
+ android:visibility="invisible"
+ android:paddingTop="10dp"
+ android:paddingBottom="10dp"
+ android:paddingRight="10dp"
+ android:paddingEnd="10dp"
+ tools:visibility="visible"
+ />
<se.leap.bitmaskclient.base.views.LocationIndicator
android:id="@+id/quality"
- android:layout_width="56dp"
+ android:layout_width="30dp"
android:layout_height="match_parent"
- android:layout_alignParentEnd="true"
- android:layout_alignParentRight="true"
+ android:layout_toLeftOf="@id/selected"
+ android:layout_toStartOf="@id/selected"
android:layout_margin="10dp"
tools:visibility="visible"
/>
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/bridge_image"
- android:layout_width="56dp"
+ android:layout_width="wrap_content"
android:layout_height="match_parent"
+ android:scaleType="fitXY"
android:layout_toStartOf="@id/quality"
android:layout_toLeftOf="@id/quality"
android:src="@drawable/ic_bridge_36"