diff --git a/src/main/java/org/cryptomator/ui/common/AutoAnimator.java b/src/main/java/org/cryptomator/ui/common/AutoAnimator.java index 325929e22..b5398339c 100644 --- a/src/main/java/org/cryptomator/ui/common/AutoAnimator.java +++ b/src/main/java/org/cryptomator/ui/common/AutoAnimator.java @@ -11,25 +11,21 @@ import javafx.beans.value.ObservableValue; * Animation which starts and stops automatically based on an observable condition. *

* During creation the consumer can optionally define actions to be executed everytime before the animation starts and after it stops. - * The automatic playback of the animation based on the condition can be stopped by calling {@link #deactivateCondition()}. To reactivate it, {@link #activateCondition()} must be called. */ public class AutoAnimator { - private final T animation; private final ObservableValue condition; private final Runnable beforeStart; private final Runnable afterStop; - - private Subscription sub; + private final Subscription sub; AutoAnimator(T animation, ObservableValue condition, Runnable beforeStart, Runnable afterStop) { this.animation = animation; this.condition = condition; this.beforeStart = beforeStart; this.afterStop = afterStop; - - activateCondition(); + this.sub = EasyBind.subscribe(condition, this::togglePlay); } public void playFromStart() { @@ -42,26 +38,6 @@ public class AutoAnimator { afterStop.run(); } - /** - * Deactivates activation on the condition. - * No-op if condition is already deactivated. - */ - public void deactivateCondition() { - if (sub != null) { - sub.unsubscribe(); - } - } - - /** - * Activates the condition - * No-op if condition is already activated. - */ - public void activateCondition() { - if (sub == null) { - this.sub = EasyBind.subscribe(condition, this::togglePlay); - } - } - private void togglePlay(boolean play) { if (play) { this.playFromStart(); diff --git a/src/main/java/org/cryptomator/ui/controls/FontAwesome5Spinner.java b/src/main/java/org/cryptomator/ui/controls/FontAwesome5Spinner.java index b6b109742..eb28a90a9 100644 --- a/src/main/java/org/cryptomator/ui/controls/FontAwesome5Spinner.java +++ b/src/main/java/org/cryptomator/ui/controls/FontAwesome5Spinner.java @@ -3,9 +3,9 @@ package org.cryptomator.ui.controls; import org.cryptomator.ui.common.Animations; import org.cryptomator.ui.common.AutoAnimator; -import javafx.beans.NamedArg; -import javafx.beans.value.ObservableValue; -import java.util.Optional; +import javafx.beans.property.BooleanProperty; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleBooleanProperty; /** * An animated progress spinner using the {@link FontAwesome5IconView} with the spinner glyph. @@ -14,23 +14,31 @@ import java.util.Optional; */ public class FontAwesome5Spinner extends FontAwesome5IconView { + protected final BooleanProperty spinning = new SimpleBooleanProperty(this, "spinning", true); + private AutoAnimator animator; public FontAwesome5Spinner() { - new FontAwesome5Spinner(Optional.empty()); - } - - public FontAwesome5Spinner(@NamedArg("spinning") ObservableValue spinning) { - new FontAwesome5Spinner(Optional.of(spinning)); - } - - private FontAwesome5Spinner(Optional> animateCondition) { setGlyph(FontAwesome5Icon.SPINNER); var animation = Animations.createDiscrete360Rotation(this); this.animator = AutoAnimator.animate(animation) // .afterStop(() -> setRotate(0)) // - .onCondition(animateCondition.orElse(visibleProperty())) // + .onCondition(spinning.and(visibleProperty())) // .build(); } + /* Getter/Setter */ + + public BooleanProperty spinningProperty() { + return spinning; + } + + public boolean isSpinning() { + return spinning.get(); + } + + public void setSpinning(boolean spinning) { + this.spinning.set(spinning); + } + }