diff options
-rw-r--r-- | app/src/main/java/com/wireguard/android/model/Tunnel.java | 9 | ||||
-rw-r--r-- | app/src/main/java/com/wireguard/android/model/TunnelManager.java | 30 |
2 files changed, 23 insertions, 16 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 9bb7406c..e61ea095 100644 --- a/app/src/main/java/com/wireguard/android/model/Tunnel.java +++ b/app/src/main/java/com/wireguard/android/model/Tunnel.java @@ -95,24 +95,21 @@ public class Tunnel extends BaseObservable implements Keyed<String> { return CompletableFuture.completedFuture(statistics); } - Config onConfigChanged(final Config config) { + void onConfigChanged(final Config config) { this.config = config; notifyPropertyChanged(BR.config); - return config; } - State onStateChanged(final State state) { + void onStateChanged(final State state) { if (state != State.UP) onStatisticsChanged(null); this.state = state; notifyPropertyChanged(BR.state); - return state; } - Statistics onStatisticsChanged(final Statistics statistics) { + void onStatisticsChanged(final Statistics statistics) { this.statistics = statistics; notifyPropertyChanged(BR.statistics); - return statistics; } public CompletionStage<Config> setConfig(@NonNull final Config config) { diff --git a/app/src/main/java/com/wireguard/android/model/TunnelManager.java b/app/src/main/java/com/wireguard/android/model/TunnelManager.java index e802c152..beed16fe 100644 --- a/app/src/main/java/com/wireguard/android/model/TunnelManager.java +++ b/app/src/main/java/com/wireguard/android/model/TunnelManager.java @@ -85,18 +85,24 @@ public final class TunnelManager { } CompletionStage<Config> getTunnelConfig(final Tunnel tunnel) { - return asyncWorker.supplyAsync(() -> configStore.load(tunnel.getName())) - .thenApply(tunnel::onConfigChanged); + final CompletionStage<Config> completion = + asyncWorker.supplyAsync(() -> configStore.load(tunnel.getName())); + completion.thenAccept(tunnel::onConfigChanged); + return completion; } CompletionStage<State> getTunnelState(final Tunnel tunnel) { - return asyncWorker.supplyAsync(() -> backend.getState(tunnel)) - .thenApply(tunnel::onStateChanged); + final CompletionStage<State> completion = + asyncWorker.supplyAsync(() -> backend.getState(tunnel)); + completion.thenAccept(tunnel::onStateChanged); + return completion; } CompletionStage<Statistics> getTunnelStatistics(final Tunnel tunnel) { - return asyncWorker.supplyAsync(() -> backend.getStatistics(tunnel)) - .thenApply(tunnel::onStatisticsChanged); + final CompletionStage<Statistics> completion = + asyncWorker.supplyAsync(() -> backend.getStatistics(tunnel)); + completion.thenAccept(tunnel::onStatisticsChanged); + return completion; } public ObservableKeyedList<String, Tunnel> getTunnels() { @@ -136,14 +142,18 @@ public final class TunnelManager { } CompletionStage<Config> setTunnelConfig(final Tunnel tunnel, final Config config) { - return asyncWorker.supplyAsync(() -> { + final CompletionStage<Config> completion = asyncWorker.supplyAsync(() -> { final Config appliedConfig = backend.applyConfig(tunnel, config); return configStore.save(tunnel.getName(), appliedConfig); - }).thenApply(tunnel::onConfigChanged); + }); + completion.thenAccept(tunnel::onConfigChanged); + return completion; } CompletionStage<State> setTunnelState(final Tunnel tunnel, final State state) { - return asyncWorker.supplyAsync(() -> backend.setState(tunnel, state)) - .thenApply(tunnel::onStateChanged); + final CompletionStage<State> completion = + asyncWorker.supplyAsync(() -> backend.setState(tunnel, state)); + completion.thenAccept(tunnel::onStateChanged); + return completion; } } |