aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/app/src/main/java/com/wireguard/config/Peer.java
diff options
context:
space:
mode:
authorSamuel Holland <samuel@sholland.org>2017-08-13 07:24:03 -0500
committerSamuel Holland <samuel@sholland.org>2017-08-13 07:24:03 -0500
commit20d314e800891df6d44ce5012739ba4d9c2a5e00 (patch)
treeeb765a1b961fefdaa7ddc3cfae9cb83a09e0c031 /app/src/main/java/com/wireguard/config/Peer.java
parentProfile: Add function to copy config from another profile (diff)
downloadwireguard-android-20d314e800891df6d44ce5012739ba4d9c2a5e00.tar.xz
wireguard-android-20d314e800891df6d44ce5012739ba4d9c2a5e00.zip
Major renaming and refactoring in activity and service
Apparently "configuration" is the proper term, not "profile".
Diffstat (limited to 'app/src/main/java/com/wireguard/config/Peer.java')
-rw-r--r--app/src/main/java/com/wireguard/config/Peer.java29
1 files changed, 27 insertions, 2 deletions
diff --git a/app/src/main/java/com/wireguard/config/Peer.java b/app/src/main/java/com/wireguard/config/Peer.java
index 64977a16..5a8c6789 100644
--- a/app/src/main/java/com/wireguard/config/Peer.java
+++ b/app/src/main/java/com/wireguard/config/Peer.java
@@ -10,12 +10,27 @@ import com.android.databinding.library.baseAdapters.BR;
* Represents the configuration for a WireGuard peer (a [Peer] block).
*/
-public class Peer extends BaseObservable implements Observable {
+public class Peer extends BaseObservable implements Copyable<Peer>, Observable {
private String allowedIPs;
private String endpoint;
private String persistentKeepalive;
private String publicKey;
+ @Override
+ public Peer copy() {
+ final Peer copy = new Peer();
+ copy.copyFrom(this);
+ return copy;
+ }
+
+ @Override
+ public void copyFrom(final Peer source) {
+ allowedIPs = source.allowedIPs;
+ endpoint = source.endpoint;
+ persistentKeepalive = source.persistentKeepalive;
+ publicKey = source.publicKey;
+ }
+
@Bindable
public String getAllowedIPs() {
return allowedIPs;
@@ -36,7 +51,7 @@ public class Peer extends BaseObservable implements Observable {
return publicKey;
}
- public void parseFrom(String line) {
+ public void parseFrom(final String line) {
final Attribute key = Attribute.match(line);
if (key == Attribute.ALLOWED_IPS)
allowedIPs = key.parseFrom(line);
@@ -46,24 +61,34 @@ public class Peer extends BaseObservable implements Observable {
persistentKeepalive = key.parseFrom(line);
else if (key == Attribute.PUBLIC_KEY)
publicKey = key.parseFrom(line);
+ else
+ throw new IllegalArgumentException(line);
}
public void setAllowedIPs(String allowedIPs) {
+ if (allowedIPs != null && allowedIPs.isEmpty())
+ allowedIPs = null;
this.allowedIPs = allowedIPs;
notifyPropertyChanged(BR.allowedIPs);
}
public void setEndpoint(String endpoint) {
+ if (endpoint != null && endpoint.isEmpty())
+ endpoint = null;
this.endpoint = endpoint;
notifyPropertyChanged(BR.endpoint);
}
public void setPersistentKeepalive(String persistentKeepalive) {
+ if (persistentKeepalive != null && persistentKeepalive.isEmpty())
+ persistentKeepalive = null;
this.persistentKeepalive = persistentKeepalive;
notifyPropertyChanged(BR.persistentKeepalive);
}
public void setPublicKey(String publicKey) {
+ if (publicKey != null && publicKey.isEmpty())
+ publicKey = null;
this.publicKey = publicKey;
notifyPropertyChanged(BR.publicKey);
}