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 --- app/src/main/java/se/leap/bitmaskclient/base/models/Location.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/base/models/Location.java') 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 ae7818ba..8e032d18 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 @@ -6,13 +6,11 @@ public class Location { @NonNull public String name; public double averageLoad; public int numberOfGateways; - public boolean selected; - public Location(@NonNull String name, double averageLoad, int numberOfGateways, boolean selected) { + public Location(@NonNull String name, double averageLoad, int numberOfGateways) { this.name = name; this.averageLoad = averageLoad; this.numberOfGateways = numberOfGateways; - this.selected = selected; } @Override @@ -24,7 +22,6 @@ public class Location { if (Double.compare(location.averageLoad, averageLoad) != 0) return false; if (numberOfGateways != location.numberOfGateways) return false; - if (selected != location.selected) return false; return name.equals(location.name); } @@ -36,7 +33,6 @@ public class Location { temp = Double.doubleToLongBits(averageLoad); result = 31 * result + (int) (temp ^ (temp >>> 32)); result = 31 * result + numberOfGateways; - result = 31 * result + (selected ? 1 : 0); return result; } } -- 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 --- .../leap/bitmaskclient/base/models/Location.java | 27 ++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/base/models/Location.java') 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 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 --- app/src/main/java/se/leap/bitmaskclient/base/models/Location.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/base/models/Location.java') 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 supportedTransports; public double averageLoad; public int numberOfGateways; + public boolean selected; - public Location(@NonNull String name, double averageLoad, int numberOfGateways, @NonNull HashSet supportedTransports) { + public Location(@NonNull String name, double averageLoad, int numberOfGateways, @NonNull HashSet supportedTransports, boolean selected) { this.name = name; this.averageLoad = averageLoad; this.numberOfGateways = numberOfGateways; this.supportedTransports = supportedTransports; + this.selected = selected; } @Override -- 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 --- .../leap/bitmaskclient/base/models/Location.java | 25 +++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/base/models/Location.java') 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 3eb82f22..599a358a 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 @@ -18,16 +18,20 @@ 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 class Location implements Cloneable { + @NonNull public String name = ""; + @NonNull public HashSet supportedTransports = new HashSet<>(); public double averageLoad; public int numberOfGateways; public boolean selected; + public Location() {} + public Location(@NonNull String name, double averageLoad, int numberOfGateways, @NonNull HashSet supportedTransports, boolean selected) { this.name = name; this.averageLoad = averageLoad; @@ -36,6 +40,10 @@ public class Location { this.selected = selected; } + public boolean hasLocationInfo() { + return numberOfGateways != 0 && supportedTransports.size() != 0 && !name.isEmpty(); + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -60,4 +68,15 @@ public class Location { result = 31 * result + numberOfGateways; return result; } + + @Override + public Location clone() throws CloneNotSupportedException { + Location copy = (Location) super.clone(); + copy.name = this.name; + copy.supportedTransports = (HashSet) this.supportedTransports.clone(); + copy.numberOfGateways = this.numberOfGateways; + copy.averageLoad = this.averageLoad; + return copy; + } + } -- 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 --- .../leap/bitmaskclient/base/models/Location.java | 68 +++++++++++++++------- 1 file changed, 47 insertions(+), 21 deletions(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/base/models/Location.java') 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 599a358a..e0ce9e8b 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 @@ -19,29 +19,62 @@ package se.leap.bitmaskclient.base.models; import androidx.annotation.NonNull; +import java.util.HashMap; import java.util.HashSet; import de.blinkt.openvpn.core.connection.Connection; public class Location implements Cloneable { - @NonNull public String name = ""; - @NonNull public HashSet supportedTransports = new HashSet<>(); - public double averageLoad; - public int numberOfGateways; + @NonNull private String name = ""; + @NonNull private HashMap averageLoad = new HashMap<>(); + @NonNull private HashMap numberOfGateways = new HashMap<>(); public boolean selected; public Location() {} - public Location(@NonNull String name, double averageLoad, int numberOfGateways, @NonNull HashSet supportedTransports, boolean selected) { + public Location(@NonNull String name, + @NonNull HashMap averageLoad, + @NonNull HashMap numberOfGateways, + boolean selected) { this.name = name; this.averageLoad = averageLoad; this.numberOfGateways = numberOfGateways; - this.supportedTransports = supportedTransports; this.selected = selected; } public boolean hasLocationInfo() { - return numberOfGateways != 0 && supportedTransports.size() != 0 && !name.isEmpty(); + return !numberOfGateways.isEmpty() && !averageLoad.isEmpty() && !name.isEmpty(); + } + + public boolean supportsTransport(Connection.TransportType transportType) { + return numberOfGateways.containsKey(transportType); + } + + public void setAverageLoad(Connection.TransportType transportType, double load) { + averageLoad.put(transportType, load); + } + + public double getAverageLoad(Connection.TransportType transportType) { + if (averageLoad.containsKey(transportType)) { + return averageLoad.get(transportType); + } + return 0; + } + + public void setNumberOfGateways(Connection.TransportType transportType, int numbers) { + numberOfGateways.put(transportType, numbers); + } + + public int getNumberOfGateways(Connection.TransportType transportType) { + if (numberOfGateways.containsKey(transportType)) { + return numberOfGateways.get(transportType); + } + return 0; + } + + @NonNull + public String getName() { + return name; } @Override @@ -51,21 +84,16 @@ public class Location implements Cloneable { Location location = (Location) o; - if (Double.compare(location.averageLoad, averageLoad) != 0) return false; - if (numberOfGateways != location.numberOfGateways) return false; if (!name.equals(location.name)) return false; - return supportedTransports.equals(location.supportedTransports); + if (!averageLoad.equals(location.averageLoad)) return false; + return numberOfGateways.equals(location.numberOfGateways); } @Override public int hashCode() { - 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; + int result = name.hashCode(); + result = 31 * result + averageLoad.hashCode(); + result = 31 * result + numberOfGateways.hashCode(); return result; } @@ -73,10 +101,8 @@ public class Location implements Cloneable { public Location clone() throws CloneNotSupportedException { Location copy = (Location) super.clone(); copy.name = this.name; - copy.supportedTransports = (HashSet) this.supportedTransports.clone(); - copy.numberOfGateways = this.numberOfGateways; - copy.averageLoad = this.averageLoad; + copy.numberOfGateways = (HashMap) this.numberOfGateways.clone(); + copy.averageLoad = (HashMap) this.averageLoad.clone(); return copy; } - } -- 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 --- .../leap/bitmaskclient/base/models/Location.java | 43 ++++++++++++++++------ 1 file changed, 32 insertions(+), 11 deletions(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/base/models/Location.java') 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 e0ce9e8b..064f25c0 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 @@ -19,22 +19,25 @@ package se.leap.bitmaskclient.base.models; import androidx.annotation.NonNull; +import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; +import java.util.function.ToDoubleFunction; import de.blinkt.openvpn.core.connection.Connection; +import de.blinkt.openvpn.core.connection.Connection.TransportType; public class Location implements Cloneable { @NonNull private String name = ""; - @NonNull private HashMap averageLoad = new HashMap<>(); - @NonNull private HashMap numberOfGateways = new HashMap<>(); + @NonNull private HashMap averageLoad = new HashMap<>(); + @NonNull private HashMap numberOfGateways = new HashMap<>(); public boolean selected; public Location() {} public Location(@NonNull String name, - @NonNull HashMap averageLoad, - @NonNull HashMap numberOfGateways, + @NonNull HashMap averageLoad, + @NonNull HashMap numberOfGateways, boolean selected) { this.name = name; this.averageLoad = averageLoad; @@ -46,26 +49,26 @@ public class Location implements Cloneable { return !numberOfGateways.isEmpty() && !averageLoad.isEmpty() && !name.isEmpty(); } - public boolean supportsTransport(Connection.TransportType transportType) { + public boolean supportsTransport(TransportType transportType) { return numberOfGateways.containsKey(transportType); } - public void setAverageLoad(Connection.TransportType transportType, double load) { + public void setAverageLoad(TransportType transportType, double load) { averageLoad.put(transportType, load); } - public double getAverageLoad(Connection.TransportType transportType) { + public double getAverageLoad(TransportType transportType) { if (averageLoad.containsKey(transportType)) { return averageLoad.get(transportType); } return 0; } - public void setNumberOfGateways(Connection.TransportType transportType, int numbers) { + public void setNumberOfGateways(TransportType transportType, int numbers) { numberOfGateways.put(transportType, numbers); } - public int getNumberOfGateways(Connection.TransportType transportType) { + public int getNumberOfGateways(TransportType transportType) { if (numberOfGateways.containsKey(transportType)) { return numberOfGateways.get(transportType); } @@ -101,8 +104,26 @@ public class Location implements Cloneable { public Location clone() throws CloneNotSupportedException { Location copy = (Location) super.clone(); copy.name = this.name; - copy.numberOfGateways = (HashMap) this.numberOfGateways.clone(); - copy.averageLoad = (HashMap) this.averageLoad.clone(); + copy.numberOfGateways = (HashMap) this.numberOfGateways.clone(); + copy.averageLoad = (HashMap) this.averageLoad.clone(); return copy; } + + public static class SortByAverageLoad implements Comparator { + TransportType transportType; + public SortByAverageLoad(TransportType transportType) { + this.transportType = transportType; + } + + @Override + public int compare(Location location1, Location location2) { + if (location1.supportsTransport(transportType) && location2.supportsTransport(transportType)) { + return (int) (location1.getAverageLoad(transportType) * 100) - (int) (location2.getAverageLoad(transportType) * 100); + } else if (location1.supportsTransport(transportType) && !location2.supportsTransport(transportType)) { + return -1; + } else { + return 1; + } + } + } } -- cgit v1.2.3