mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-24 12:46:45 +00:00
improve server connection and wallet loading pulse animation efficiency
This commit is contained in:
parent
9bca911b0b
commit
e4189711bd
3 changed files with 40 additions and 24 deletions
|
@ -1729,21 +1729,17 @@ public class AppController implements Initializable {
|
||||||
private void serverToggleStartAnimation() {
|
private void serverToggleStartAnimation() {
|
||||||
Node thumbArea = serverToggle.lookup(".thumb-area");
|
Node thumbArea = serverToggle.lookup(".thumb-area");
|
||||||
if(thumbArea != null) {
|
if(thumbArea != null) {
|
||||||
FadeTransition fadeTransition = new FadeTransition(Duration.millis(600), thumbArea);
|
Timeline timeline = AnimationUtil.getPulse(thumbArea, Duration.millis(600), 1.0, 0.4, 20);
|
||||||
fadeTransition.setFromValue(1.0);
|
timeline.play();
|
||||||
fadeTransition.setToValue(0.4);
|
serverToggle.setUserData(new AnimationUtil.AnimatedNode(thumbArea, timeline));
|
||||||
fadeTransition.setAutoReverse(true);
|
|
||||||
fadeTransition.setCycleCount(Animation.INDEFINITE);
|
|
||||||
fadeTransition.play();
|
|
||||||
serverToggle.setUserData(fadeTransition);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void serverToggleStopAnimation() {
|
private void serverToggleStopAnimation() {
|
||||||
if(serverToggle.getUserData() != null) {
|
if(serverToggle.getUserData() != null) {
|
||||||
FadeTransition fadeTransition = (FadeTransition)serverToggle.getUserData();
|
AnimationUtil.AnimatedNode animatedNode = (AnimationUtil.AnimatedNode)serverToggle.getUserData();
|
||||||
fadeTransition.stop();
|
animatedNode.timeline().stop();
|
||||||
fadeTransition.getNode().setOpacity(1.0);
|
animatedNode.node().setOpacity(1.0);
|
||||||
serverToggle.setUserData(null);
|
serverToggle.setUserData(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1759,13 +1755,9 @@ public class AppController implements Initializable {
|
||||||
private void tabLabelStartAnimation(Tab tab) {
|
private void tabLabelStartAnimation(Tab tab) {
|
||||||
Label tabLabel = (Label) tab.getGraphic();
|
Label tabLabel = (Label) tab.getGraphic();
|
||||||
if(tabLabel.getUserData() == null) {
|
if(tabLabel.getUserData() == null) {
|
||||||
FadeTransition fadeTransition = new FadeTransition(Duration.millis(1000), tabLabel.getGraphic());
|
Timeline timeline = AnimationUtil.getPulse(tabLabel.getGraphic(), Duration.millis(1000), tabLabel.getGraphic().getOpacity(), 0.1, 20);
|
||||||
fadeTransition.setFromValue(tabLabel.getGraphic().getOpacity());
|
timeline.play();
|
||||||
fadeTransition.setToValue(0.1);
|
tabLabel.setUserData(timeline);
|
||||||
fadeTransition.setAutoReverse(true);
|
|
||||||
fadeTransition.setCycleCount(Animation.INDEFINITE);
|
|
||||||
fadeTransition.play();
|
|
||||||
tabLabel.setUserData(fadeTransition);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1795,8 +1787,8 @@ public class AppController implements Initializable {
|
||||||
private void tabLabelStopAnimation(Tab tab) {
|
private void tabLabelStopAnimation(Tab tab) {
|
||||||
Label tabLabel = (Label) tab.getGraphic();
|
Label tabLabel = (Label) tab.getGraphic();
|
||||||
if(tabLabel.getUserData() != null) {
|
if(tabLabel.getUserData() != null) {
|
||||||
FadeTransition fadeTransition = (FadeTransition)tabLabel.getUserData();
|
Animation animation = (Animation)tabLabel.getUserData();
|
||||||
fadeTransition.stop();
|
animation.stop();
|
||||||
tabLabel.setUserData(null);
|
tabLabel.setUserData(null);
|
||||||
tabLabel.getGraphic().setOpacity(tab.isSelected() ? TAB_LABEL_GRAPHIC_OPACITY_ACTIVE : TAB_LABEL_GRAPHIC_OPACITY_INACTIVE);
|
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<BlockTransaction> blockTransactions = new ArrayList<>(event.getBlockTransactions());
|
List<BlockTransaction> blockTransactions = new ArrayList<>(event.getBlockTransactions());
|
||||||
List<BlockTransaction> whirlpoolTransactions = event.getUnspentWhirlpoolMixTransactions();
|
List<BlockTransaction> whirlpoolTransactions = event.getUnspentConfirmingWhirlpoolMixTransactions();
|
||||||
blockTransactions.removeAll(whirlpoolTransactions);
|
blockTransactions.removeAll(whirlpoolTransactions);
|
||||||
|
|
||||||
if(!whirlpoolTransactions.isEmpty()) {
|
if(!whirlpoolTransactions.isEmpty()) {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.sparrowwallet.sparrow.control;
|
package com.sparrowwallet.sparrow.control;
|
||||||
|
|
||||||
|
import javafx.animation.Animation;
|
||||||
import javafx.animation.KeyFrame;
|
import javafx.animation.KeyFrame;
|
||||||
import javafx.animation.Timeline;
|
import javafx.animation.Timeline;
|
||||||
import javafx.scene.Node;
|
import javafx.scene.Node;
|
||||||
|
@ -10,11 +11,34 @@ public class AnimationUtil {
|
||||||
Timeline fadeTimeline = new Timeline();
|
Timeline fadeTimeline = new Timeline();
|
||||||
Duration incrementDuration = duration.divide(numIncrements);
|
Duration incrementDuration = duration.divide(numIncrements);
|
||||||
for(int i = 0; i < numIncrements; i++) {
|
for(int i = 0; i < numIncrements; i++) {
|
||||||
double normalized = ((double)numIncrements - i - 1) / numIncrements;
|
double percent = ((double)numIncrements - i - 1) / numIncrements;
|
||||||
double opacity = normalized * fromValue;
|
double opacity = percent * fromValue;
|
||||||
fadeTimeline.getKeyFrames().add(new KeyFrame(incrementDuration.multiply(i+1), event -> node.setOpacity(opacity)));
|
fadeTimeline.getKeyFrames().add(new KeyFrame(incrementDuration.multiply(i+1), event -> node.setOpacity(opacity)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return fadeTimeline;
|
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) {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,11 +62,11 @@ public class NewWalletTransactionsEvent {
|
||||||
return String.format(Locale.ENGLISH, "%,d", value) + " sats";
|
return String.format(Locale.ENGLISH, "%,d", value) + " sats";
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<BlockTransaction> getUnspentWhirlpoolMixTransactions() {
|
public List<BlockTransaction> getUnspentConfirmingWhirlpoolMixTransactions() {
|
||||||
List<BlockTransaction> mixTransactions = new ArrayList<>();
|
List<BlockTransaction> mixTransactions = new ArrayList<>();
|
||||||
if(wallet.isWhirlpoolMixWallet()) {
|
if(wallet.isWhirlpoolMixWallet()) {
|
||||||
return transactionEntries.stream()
|
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());
|
.map(TransactionEntry::getBlockTransaction).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue