diff options
author | Samuel Holland <samuel@sholland.org> | 2018-01-10 00:03:03 -0600 |
---|---|---|
committer | Samuel Holland <samuel@sholland.org> | 2018-01-10 00:03:03 -0600 |
commit | 7b9c1a536ceb1527edda8be90cefc1f830dbbf81 (patch) | |
tree | 0239985dff63d68f282023abd03034a3a11296e1 /app/src/main/java/com/wireguard/android/model/Tunnel.java | |
parent | 951afaa9b29637d1abb3b6a60f9fdeb6bc27bb1c (diff) |
model: Use ConfigStore.rename() to avoid recreating tunnels
Rename all of the functions to be in line with setConfig/setState
Signed-off-by: Samuel Holland <samuel@sholland.org>
Diffstat (limited to 'app/src/main/java/com/wireguard/android/model/Tunnel.java')
-rw-r--r-- | app/src/main/java/com/wireguard/android/model/Tunnel.java | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/app/src/main/java/com/wireguard/android/model/Tunnel.java b/app/src/main/java/com/wireguard/android/model/Tunnel.java index 024f27a6..09efc70c 100644 --- a/app/src/main/java/com/wireguard/android/model/Tunnel.java +++ b/app/src/main/java/com/wireguard/android/model/Tunnel.java @@ -24,8 +24,8 @@ public class Tunnel extends BaseObservable implements Keyed<String> { private static final Pattern NAME_PATTERN = Pattern.compile("[a-zA-Z0-9_=+.-]{1,15}"); private final TunnelManager manager; - private final String name; private Config config; + private String name; private State state; private Statistics statistics; @@ -63,6 +63,7 @@ public class Tunnel extends BaseObservable implements Keyed<String> { return name; } + @Bindable public String getName() { return name; } @@ -97,6 +98,12 @@ public class Tunnel extends BaseObservable implements Keyed<String> { return config; } + public String onNameChanged(final String name) { + this.name = name; + notifyPropertyChanged(BR.name); + return name; + } + State onStateChanged(final State state) { if (state != State.UP) onStatisticsChanged(null); @@ -111,18 +118,18 @@ public class Tunnel extends BaseObservable implements Keyed<String> { return statistics; } - public CompletionStage<Tunnel> rename(@NonNull final String name) { - if (!name.equals(this.name)) - return manager.rename(this, name); - return CompletableFuture.completedFuture(this); - } - public CompletionStage<Config> setConfig(@NonNull final Config config) { if (!config.equals(this.config)) return manager.setTunnelConfig(this, config); return CompletableFuture.completedFuture(this.config); } + public CompletionStage<String> setName(@NonNull final String name) { + if (!name.equals(this.name)) + return manager.setTunnelName(this, name); + return CompletableFuture.completedFuture(this.name); + } + public CompletionStage<State> setState(@NonNull final State state) { if (state != this.state) return manager.setTunnelState(this, state); |