use of org.fxmisc.easybind.Subscription in project bitsquare by bitsquare.
the class MainViewModel method onDisputesChangeListener.
private void onDisputesChangeListener(List<? extends Dispute> addedList, @Nullable List<? extends Dispute> removedList) {
if (removedList != null) {
removedList.stream().forEach(dispute -> {
String id = dispute.getId();
if (disputeIsClosedSubscriptionsMap.containsKey(id)) {
disputeIsClosedSubscriptionsMap.get(id).unsubscribe();
disputeIsClosedSubscriptionsMap.remove(id);
}
});
}
addedList.stream().forEach(dispute -> {
String id = dispute.getId();
Subscription disputeStateSubscription = EasyBind.subscribe(dispute.isClosedProperty(), isClosed -> {
UserThread.execute(() -> {
int openDisputes = disputeManager.getDisputesAsObservableList().stream().filter(e -> !e.isClosed()).collect(Collectors.toList()).size();
if (openDisputes > 0)
numOpenDisputesAsString.set(String.valueOf(openDisputes));
if (openDisputes > 9)
numOpenDisputesAsString.set("★");
showOpenDisputesNotification.set(openDisputes > 0);
});
});
disputeIsClosedSubscriptionsMap.put(id, disputeStateSubscription);
});
}
use of org.fxmisc.easybind.Subscription in project bitsquare by bitsquare.
the class NotificationCenter method onAllServicesAndViewsInitialized.
public void onAllServicesAndViewsInitialized() {
tradeManager.getTrades().addListener((ListChangeListener<Trade>) change -> {
change.next();
if (change.wasRemoved()) {
change.getRemoved().stream().forEach(trade -> {
String tradeId = trade.getId();
if (disputeStateSubscriptionsMap.containsKey(tradeId)) {
disputeStateSubscriptionsMap.get(tradeId).unsubscribe();
disputeStateSubscriptionsMap.remove(tradeId);
}
if (tradeStateSubscriptionsMap.containsKey(tradeId)) {
tradeStateSubscriptionsMap.get(tradeId).unsubscribe();
tradeStateSubscriptionsMap.remove(tradeId);
}
});
}
if (change.wasAdded()) {
change.getAddedSubList().stream().forEach(trade -> {
String tradeId = trade.getId();
if (disputeStateSubscriptionsMap.containsKey(tradeId)) {
log.debug("We have already an entry in disputeStateSubscriptionsMap.");
} else {
Subscription disputeStateSubscription = EasyBind.subscribe(trade.disputeStateProperty(), disputeState -> onDisputeStateChanged(trade, disputeState));
disputeStateSubscriptionsMap.put(tradeId, disputeStateSubscription);
}
if (tradeStateSubscriptionsMap.containsKey(tradeId)) {
log.debug("We have already an entry in tradeStateSubscriptionsMap.");
} else {
Subscription tradeStateSubscription = EasyBind.subscribe(trade.stateProperty(), tradeState -> onTradeStateChanged(trade, tradeState));
tradeStateSubscriptionsMap.put(tradeId, tradeStateSubscription);
}
});
}
});
tradeManager.getTrades().stream().forEach(trade -> {
String tradeId = trade.getId();
Subscription disputeStateSubscription = EasyBind.subscribe(trade.disputeStateProperty(), disputeState -> onDisputeStateChanged(trade, disputeState));
disputeStateSubscriptionsMap.put(tradeId, disputeStateSubscription);
Subscription tradeStateSubscription = EasyBind.subscribe(trade.stateProperty(), tradeState -> onTradeStateChanged(trade, tradeState));
tradeStateSubscriptionsMap.put(tradeId, tradeStateSubscription);
});
}
use of org.fxmisc.easybind.Subscription in project bisq-desktop by bisq-network.
the class MainViewModel method onDisputesChangeListener.
private void onDisputesChangeListener(List<? extends Dispute> addedList, @Nullable List<? extends Dispute> removedList) {
if (removedList != null) {
removedList.stream().forEach(dispute -> {
String id = dispute.getId();
if (disputeIsClosedSubscriptionsMap.containsKey(id)) {
disputeIsClosedSubscriptionsMap.get(id).unsubscribe();
disputeIsClosedSubscriptionsMap.remove(id);
}
});
}
addedList.stream().forEach(dispute -> {
String id = dispute.getId();
Subscription disputeStateSubscription = EasyBind.subscribe(dispute.isClosedProperty(), isClosed -> {
// We get event before list gets updated, so we execute on next frame
UserThread.execute(() -> {
int openDisputes = disputeManager.getDisputesAsObservableList().stream().filter(e -> !e.isClosed()).collect(Collectors.toList()).size();
if (openDisputes > 0)
numOpenDisputesAsString.set(String.valueOf(openDisputes));
if (openDisputes > 9)
numOpenDisputesAsString.set("★");
showOpenDisputesNotification.set(openDisputes > 0);
});
});
disputeIsClosedSubscriptionsMap.put(id, disputeStateSubscription);
});
}
use of org.fxmisc.easybind.Subscription in project bisq-desktop by bisq-network.
the class NotificationCenter method onAllServicesAndViewsInitialized.
public void onAllServicesAndViewsInitialized() {
tradeManager.getTradableList().addListener((ListChangeListener<Trade>) change -> {
change.next();
if (change.wasRemoved()) {
change.getRemoved().stream().forEach(trade -> {
String tradeId = trade.getId();
if (disputeStateSubscriptionsMap.containsKey(tradeId)) {
disputeStateSubscriptionsMap.get(tradeId).unsubscribe();
disputeStateSubscriptionsMap.remove(tradeId);
}
if (tradePhaseSubscriptionsMap.containsKey(tradeId)) {
tradePhaseSubscriptionsMap.get(tradeId).unsubscribe();
tradePhaseSubscriptionsMap.remove(tradeId);
}
});
}
if (change.wasAdded()) {
change.getAddedSubList().stream().forEach(trade -> {
String tradeId = trade.getId();
if (disputeStateSubscriptionsMap.containsKey(tradeId)) {
log.debug("We have already an entry in disputeStateSubscriptionsMap.");
} else {
Subscription disputeStateSubscription = EasyBind.subscribe(trade.disputeStateProperty(), disputeState -> onDisputeStateChanged(trade, disputeState));
disputeStateSubscriptionsMap.put(tradeId, disputeStateSubscription);
}
if (tradePhaseSubscriptionsMap.containsKey(tradeId)) {
log.debug("We have already an entry in tradePhaseSubscriptionsMap.");
} else {
Subscription tradePhaseSubscription = EasyBind.subscribe(trade.statePhaseProperty(), phase -> onTradePhaseChanged(trade, phase));
tradePhaseSubscriptionsMap.put(tradeId, tradePhaseSubscription);
}
});
}
});
tradeManager.getTradableList().stream().forEach(trade -> {
String tradeId = trade.getId();
Subscription disputeStateSubscription = EasyBind.subscribe(trade.disputeStateProperty(), disputeState -> onDisputeStateChanged(trade, disputeState));
disputeStateSubscriptionsMap.put(tradeId, disputeStateSubscription);
Subscription tradePhaseSubscription = EasyBind.subscribe(trade.statePhaseProperty(), phase -> onTradePhaseChanged(trade, phase));
tradePhaseSubscriptionsMap.put(tradeId, tradePhaseSubscription);
});
}
use of org.fxmisc.easybind.Subscription in project bisq-api by mrosseel.
the class MainViewModelHeadless method onDisputesChangeListener.
private void onDisputesChangeListener(List<? extends Dispute> addedList, @Nullable List<? extends Dispute> removedList) {
if (removedList != null) {
removedList.stream().forEach(dispute -> {
String id = dispute.getId();
if (disputeIsClosedSubscriptionsMap.containsKey(id)) {
disputeIsClosedSubscriptionsMap.get(id).unsubscribe();
disputeIsClosedSubscriptionsMap.remove(id);
}
});
}
addedList.stream().forEach(dispute -> {
String id = dispute.getId();
Subscription disputeStateSubscription = EasyBind.subscribe(dispute.isClosedProperty(), isClosed -> {
// We get event before list gets updated, so we execute on next frame
UserThread.execute(() -> {
int openDisputes = disputeManager.getDisputesAsObservableList().stream().filter(e -> !e.isClosed()).collect(Collectors.toList()).size();
if (openDisputes > 0)
numOpenDisputesAsString.set(String.valueOf(openDisputes));
if (openDisputes > 9)
numOpenDisputesAsString.set("★");
showOpenDisputesNotification.set(openDisputes > 0);
});
});
disputeIsClosedSubscriptionsMap.put(id, disputeStateSubscription);
});
}
Aggregations