diff --git a/src/main/java/com/sparrowwallet/sparrow/AppController.java b/src/main/java/com/sparrowwallet/sparrow/AppController.java index 5b6b1e1e..17337f91 100644 --- a/src/main/java/com/sparrowwallet/sparrow/AppController.java +++ b/src/main/java/com/sparrowwallet/sparrow/AppController.java @@ -1729,21 +1729,17 @@ public class AppController implements Initializable { private void serverToggleStartAnimation() { Node thumbArea = serverToggle.lookup(".thumb-area"); if(thumbArea != null) { - FadeTransition fadeTransition = new FadeTransition(Duration.millis(600), thumbArea); - fadeTransition.setFromValue(1.0); - fadeTransition.setToValue(0.4); - fadeTransition.setAutoReverse(true); - fadeTransition.setCycleCount(Animation.INDEFINITE); - fadeTransition.play(); - serverToggle.setUserData(fadeTransition); + Timeline timeline = AnimationUtil.getPulse(thumbArea, Duration.millis(600), 1.0, 0.4, 20); + timeline.play(); + serverToggle.setUserData(new AnimationUtil.AnimatedNode(thumbArea, timeline)); } } private void serverToggleStopAnimation() { if(serverToggle.getUserData() != null) { - FadeTransition fadeTransition = (FadeTransition)serverToggle.getUserData(); - fadeTransition.stop(); - fadeTransition.getNode().setOpacity(1.0); + AnimationUtil.AnimatedNode animatedNode = (AnimationUtil.AnimatedNode)serverToggle.getUserData(); + animatedNode.timeline().stop(); + animatedNode.node().setOpacity(1.0); serverToggle.setUserData(null); } } @@ -1759,13 +1755,9 @@ public class AppController implements Initializable { private void tabLabelStartAnimation(Tab tab) { Label tabLabel = (Label) tab.getGraphic(); if(tabLabel.getUserData() == null) { - FadeTransition fadeTransition = new FadeTransition(Duration.millis(1000), tabLabel.getGraphic()); - fadeTransition.setFromValue(tabLabel.getGraphic().getOpacity()); - fadeTransition.setToValue(0.1); - fadeTransition.setAutoReverse(true); - fadeTransition.setCycleCount(Animation.INDEFINITE); - fadeTransition.play(); - tabLabel.setUserData(fadeTransition); + Timeline timeline = AnimationUtil.getPulse(tabLabel.getGraphic(), Duration.millis(1000), tabLabel.getGraphic().getOpacity(), 0.1, 20); + timeline.play(); + tabLabel.setUserData(timeline); } } @@ -1795,8 +1787,8 @@ public class AppController implements Initializable { private void tabLabelStopAnimation(Tab tab) { Label tabLabel = (Label) tab.getGraphic(); if(tabLabel.getUserData() != null) { - FadeTransition fadeTransition = (FadeTransition)tabLabel.getUserData(); - fadeTransition.stop(); + Animation animation = (Animation)tabLabel.getUserData(); + animation.stop(); tabLabel.setUserData(null); tabLabel.getGraphic().setOpacity(tab.isSelected() ? TAB_LABEL_GRAPHIC_OPACITY_ACTIVE : TAB_LABEL_GRAPHIC_OPACITY_INACTIVE); } @@ -1929,7 +1921,7 @@ public class AppController implements Initializable { } List blockTransactions = new ArrayList<>(event.getBlockTransactions()); - List whirlpoolTransactions = event.getUnspentWhirlpoolMixTransactions(); + List whirlpoolTransactions = event.getUnspentConfirmingWhirlpoolMixTransactions(); blockTransactions.removeAll(whirlpoolTransactions); if(!whirlpoolTransactions.isEmpty()) { diff --git a/src/main/java/com/sparrowwallet/sparrow/control/AnimationUtil.java b/src/main/java/com/sparrowwallet/sparrow/control/AnimationUtil.java index c7ea2092..43d74e0e 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/AnimationUtil.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/AnimationUtil.java @@ -1,5 +1,6 @@ package com.sparrowwallet.sparrow.control; +import javafx.animation.Animation; import javafx.animation.KeyFrame; import javafx.animation.Timeline; import javafx.scene.Node; @@ -10,11 +11,34 @@ public class AnimationUtil { Timeline fadeTimeline = new Timeline(); Duration incrementDuration = duration.divide(numIncrements); for(int i = 0; i < numIncrements; i++) { - double normalized = ((double)numIncrements - i - 1) / numIncrements; - double opacity = normalized * fromValue; + double percent = ((double)numIncrements - i - 1) / numIncrements; + double opacity = percent * fromValue; fadeTimeline.getKeyFrames().add(new KeyFrame(incrementDuration.multiply(i+1), event -> node.setOpacity(opacity))); } return fadeTimeline; } + + public static Timeline getPulse(Node node, Duration duration, double fromValue, double toValue, int numIncrements) { + Timeline pulseTimeline = getFade(node, duration, fromValue, toValue, numIncrements); + + pulseTimeline.setCycleCount(Animation.INDEFINITE); + pulseTimeline.setAutoReverse(true); + + return pulseTimeline; + } + + public static Timeline getFade(Node node, Duration duration, double fromValue, double toValue, int numIncrements) { + Timeline fadeTimeline = new Timeline(); + Duration incrementDuration = duration.divide(numIncrements); + for(int i = 0; i < numIncrements; i++) { + double percent = ((double) numIncrements - i - 1) / numIncrements; //From 99% to 0% + double opacity = (percent * (fromValue - toValue)) + toValue; + fadeTimeline.getKeyFrames().add(new KeyFrame(incrementDuration.multiply(i+1), event -> node.setOpacity(opacity))); + } + + return fadeTimeline; + } + + public record AnimatedNode (Node node, Timeline timeline) {} } diff --git a/src/main/java/com/sparrowwallet/sparrow/event/NewWalletTransactionsEvent.java b/src/main/java/com/sparrowwallet/sparrow/event/NewWalletTransactionsEvent.java index 6df59372..cdca1c2f 100644 --- a/src/main/java/com/sparrowwallet/sparrow/event/NewWalletTransactionsEvent.java +++ b/src/main/java/com/sparrowwallet/sparrow/event/NewWalletTransactionsEvent.java @@ -62,11 +62,11 @@ public class NewWalletTransactionsEvent { return String.format(Locale.ENGLISH, "%,d", value) + " sats"; } - public List getUnspentWhirlpoolMixTransactions() { + public List getUnspentConfirmingWhirlpoolMixTransactions() { List mixTransactions = new ArrayList<>(); if(wallet.isWhirlpoolMixWallet()) { return transactionEntries.stream() - .filter(txEntry -> txEntry.getValue() == 0 && !allOutputsSpent(txEntry)) + .filter(txEntry -> txEntry.getValue() == 0 && txEntry.isConfirming() && !allOutputsSpent(txEntry)) .map(TransactionEntry::getBlockTransaction).collect(Collectors.toList()); }