From a1e334efa647d6f4aa2c5a818f92be9376219c73 Mon Sep 17 00:00:00 2001 From: Samuel Holland Date: Mon, 31 Jul 2017 21:13:01 -0500 Subject: [PATCH] Profile: Track connection state Observability is only enabled for isConnected because it is the only mutable property. Signed-off-by: Jason A. Donenfeld --- .../java/com/wireguard/config/Profile.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/wireguard/config/Profile.java b/app/src/main/java/com/wireguard/config/Profile.java index 1670050c..e6506c45 100644 --- a/app/src/main/java/com/wireguard/config/Profile.java +++ b/app/src/main/java/com/wireguard/config/Profile.java @@ -1,9 +1,15 @@ package com.wireguard.config; +import android.databinding.BaseObservable; +import android.databinding.Bindable; +import android.databinding.Observable; import android.databinding.ObservableArrayList; import android.databinding.ObservableList; +import com.wireguard.android.BR; + import java.io.BufferedReader; +import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -13,12 +19,14 @@ import java.nio.charset.StandardCharsets; * Represents a wg-quick profile. */ -public class Profile { +public class Profile extends BaseObservable implements Observable { private final Interface iface = new Interface(); + private boolean isConnected; private final String name; private final ObservableList peers = new ObservableArrayList<>(); public Profile(String name) { + super(); this.name = name; } @@ -26,6 +34,11 @@ public class Profile { return iface; } + @Bindable + public boolean getIsConnected() { + return isConnected; + } + public String getName() { return name; } @@ -55,6 +68,11 @@ public class Profile { } } + public void setIsConnected(boolean isConnected) { + this.isConnected = isConnected; + notifyPropertyChanged(BR.isConnected); + } + @Override public String toString() { StringBuilder sb = new StringBuilder().append(iface.toString());