Refactor auto-closing of sell BTC offer view

This commit is contained in:
Christoph Atteneder 2021-10-06 11:23:33 +02:00
parent d2baabc180
commit ee30cd9739
No known key found for this signature in database
GPG key ID: CD5DC1C529CDFD3B
2 changed files with 13 additions and 8 deletions

View file

@ -168,7 +168,7 @@ public abstract class MutableOfferView<M extends MutableOfferViewModel<?>> exten
private ChangeListener<String> tradeCurrencyCodeListener, errorMessageListener,
marketPriceMarginListener, volumeListener, buyerSecurityDepositInBTCListener;
private ChangeListener<Number> marketPriceAvailableListener;
private Navigation.Listener navigationWithCloseListener;
private Navigation.Listener closeViewListener;
private EventHandler<ActionEvent> currencyComboBoxSelectionHandler, paymentAccountsComboBoxSelectionHandler;
private OfferView.CloseHandler closeHandler;
@ -914,10 +914,8 @@ public abstract class MutableOfferView<M extends MutableOfferViewModel<?>> exten
}
});
navigationWithCloseListener = (path, data) -> {
log.warn("*** target path={}, data={}, dir={}", path, data, model.getDataModel().getDirection());
if ("closeOfferView".equals(data)) {
log.warn("*** WILL CLOSE");
closeViewListener = (path, data) -> {
if (OfferViewUtil.isCloseView((String) data)) {
close();
}
};
@ -978,7 +976,7 @@ public abstract class MutableOfferView<M extends MutableOfferViewModel<?>> exten
paymentAccountsComboBox.setOnAction(paymentAccountsComboBoxSelectionHandler);
currencyComboBox.setOnAction(currencyComboBoxSelectionHandler);
navigation.addListener(navigationWithCloseListener);
navigation.addListener(closeViewListener);
}
private void removeListeners() {
@ -1015,7 +1013,7 @@ public abstract class MutableOfferView<M extends MutableOfferViewModel<?>> exten
paymentAccountsComboBox.setOnAction(null);
currencyComboBox.setOnAction(null);
navigation.removeListener(navigationWithCloseListener);
navigation.removeListener(closeViewListener);
}

View file

@ -46,6 +46,9 @@ import java.util.concurrent.TimeUnit;
// Shared utils for Views
public class OfferViewUtil {
public static final String CLOSE_VIEW = "closeView";
public static Label createPopOverLabel(String text) {
final Label label = new Label(text);
label.setPrefWidth(300);
@ -101,7 +104,7 @@ public class OfferViewUtil {
preferences.setSellScreenCurrencyCode("BSQ");
navigation.navigateToWithData(
// FIXME: replace "closeOfferView" with a more unique object?
directionClosure.getDirection() == OfferPayload.Direction.SELL ? "closeOfferView" : null,
directionClosure.getDirection() == OfferPayload.Direction.SELL ? CLOSE_VIEW : null,
MainView.class, SellOfferView.class, OfferBookView.class);
}).show());
@ -112,4 +115,8 @@ public class OfferViewUtil {
return new Tuple2<>(buyBsqButton, buyBsqButtonVBox);
}
public static boolean isCloseView(String data) {
return CLOSE_VIEW.equals(data);
}
}