summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMikael Magnusson <mikma@users.sourceforge.net>2023-01-28 18:25:15 +0100
committerMikael Magnusson <mikma@users.sourceforge.net>2023-01-28 18:25:15 +0100
commit80b1e303477b32ff432b7cda04017fa240692a23 (patch)
tree591bb4750e50cc380c8834a873a1a6ff4b7e7abc
parent44cdfed71ab85ada5bf8b14f666c48ce6742d506 (diff)
WIP peer status observablepeer-status-observable
-rw-r--r--build.gradle1
-rw-r--r--tunnel/build.gradle1
-rw-r--r--tunnel/src/main/java/com/wireguard/config/InetEndpoint.java8
-rw-r--r--ui/src/main/res/layout/tunnel_detail_peer.xml6
4 files changed, 13 insertions, 3 deletions
diff --git a/build.gradle b/build.gradle
index b9f54f9c..9f72bb30 100644
--- a/build.gradle
+++ b/build.gradle
@@ -9,6 +9,7 @@ buildscript {
coordinatorLayoutVersion = '1.2.0'
coreKtxVersion = '1.8.0'
coroutinesVersion = '1.6.4'
+ databindingVersion = '7.0.3'
datastoreVersion = '1.0.0'
desugarVersion = '1.1.5'
fragmentVersion = '1.5.1'
diff --git a/tunnel/build.gradle b/tunnel/build.gradle
index d8aa2497..f9bdeb15 100644
--- a/tunnel/build.gradle
+++ b/tunnel/build.gradle
@@ -68,6 +68,7 @@ android {
dependencies {
implementation "androidx.annotation:annotation:$annotationsVersion"
implementation "androidx.collection:collection:$collectionVersion"
+ implementation "androidx.databinding:databinding-runtime:$databindingVersion"
implementation "io.grpc:grpc-okhttp:$grpcVersion"
implementation "io.grpc:grpc-protobuf-lite:$grpcVersion"
implementation "io.grpc:grpc-stub:$grpcVersion"
diff --git a/tunnel/src/main/java/com/wireguard/config/InetEndpoint.java b/tunnel/src/main/java/com/wireguard/config/InetEndpoint.java
index 66855f11..801e2a42 100644
--- a/tunnel/src/main/java/com/wireguard/config/InetEndpoint.java
+++ b/tunnel/src/main/java/com/wireguard/config/InetEndpoint.java
@@ -18,6 +18,7 @@ import java.util.Optional;
import java.util.regex.Pattern;
import androidx.annotation.Nullable;
+import androidx.databinding.BaseObservable;
/**
@@ -26,7 +27,7 @@ import androidx.annotation.Nullable;
* Instances of this class are externally immutable.
*/
@NonNullForAll
-public final class InetEndpoint {
+public final class InetEndpoint extends BaseObservable {
private static final Pattern BARE_IPV6 = Pattern.compile("^[^\\[\\]]*:[^\\[\\]]*");
private static final Pattern FORBIDDEN_CHARACTERS = Pattern.compile("[/?#]");
@@ -105,8 +106,10 @@ public final class InetEndpoint {
}
resolved = new InetEndpoint(address.getHostAddress(), true, port);
lastResolution = Instant.now();
+ notifyChange();
} catch (final UnknownHostException e) {
resolved = null;
+ notifyChange();
}
}
return Optional.ofNullable(resolved);
@@ -121,6 +124,7 @@ public final class InetEndpoint {
@Override
public String toString() {
final boolean isBareIpv6 = isResolved && BARE_IPV6.matcher(host).matches();
- return (isBareIpv6 ? '[' + host + ']' : host) + ':' + port;
+ String ep = (isBareIpv6 ? '[' + host + ']' : host) + ':' + port;
+ return (isResolved || resolved == null) ? ep : ep + " (" + resolved.host + ')';
}
}
diff --git a/ui/src/main/res/layout/tunnel_detail_peer.xml b/ui/src/main/res/layout/tunnel_detail_peer.xml
index f295bb13..e5796afd 100644
--- a/ui/src/main/res/layout/tunnel_detail_peer.xml
+++ b/ui/src/main/res/layout/tunnel_detail_peer.xml
@@ -10,6 +10,10 @@
<variable
name="item"
type="com.wireguard.config.Peer" />
+
+ <variable
+ name="endpoint"
+ type="com.wireguard.config.InetEndpoint" />
</data>
<com.google.android.material.card.MaterialCardView
@@ -134,7 +138,7 @@
android:nextFocusDown="@id/persistent_keepalive_text"
android:nextFocusForward="@id/persistent_keepalive_text"
android:onClick="@{ClipboardUtils::copyTextView}"
- android:text="@{item.endpoint}"
+ android:text="@{endpoint}"
android:visibility="@{!item.endpoint.isPresent() ? android.view.View.GONE : android.view.View.VISIBLE}"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/endpoint_label"