Profile: Track connection state

Observability is only enabled for isConnected because it is the only
mutable property.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Samuel Holland 2017-07-31 21:13:01 -05:00
parent 8623437185
commit a1e334efa6

View File

@ -1,9 +1,15 @@
package com.wireguard.config; package com.wireguard.config;
import android.databinding.BaseObservable;
import android.databinding.Bindable;
import android.databinding.Observable;
import android.databinding.ObservableArrayList; import android.databinding.ObservableArrayList;
import android.databinding.ObservableList; import android.databinding.ObservableList;
import com.wireguard.android.BR;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
@ -13,12 +19,14 @@ import java.nio.charset.StandardCharsets;
* Represents a wg-quick profile. * Represents a wg-quick profile.
*/ */
public class Profile { public class Profile extends BaseObservable implements Observable {
private final Interface iface = new Interface(); private final Interface iface = new Interface();
private boolean isConnected;
private final String name; private final String name;
private final ObservableList<Peer> peers = new ObservableArrayList<>(); private final ObservableList<Peer> peers = new ObservableArrayList<>();
public Profile(String name) { public Profile(String name) {
super();
this.name = name; this.name = name;
} }
@ -26,6 +34,11 @@ public class Profile {
return iface; return iface;
} }
@Bindable
public boolean getIsConnected() {
return isConnected;
}
public String getName() { public String getName() {
return name; return name;
} }
@ -55,6 +68,11 @@ public class Profile {
} }
} }
public void setIsConnected(boolean isConnected) {
this.isConnected = isConnected;
notifyPropertyChanged(BR.isConnected);
}
@Override @Override
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder().append(iface.toString()); StringBuilder sb = new StringBuilder().append(iface.toString());