Skip to content

Commit

Permalink
Fix issue with percentage price not sticking
Browse files Browse the repository at this point in the history
  • Loading branch information
axpoems committed Dec 18, 2024
1 parent eb8147c commit 3a7c88a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ public PriceInputBox(String description) {
this(description, null);
}

void initialize() {
public void initialize() {
textInputControl.lengthProperty().addListener(textInputLengthListener);
}

void dispose() {
public void dispose() {
textInputControl.lengthProperty().removeListener(textInputLengthListener);
}

Expand All @@ -102,14 +102,6 @@ protected double getBgHeight() {
return AMOUNT_BOX_HEIGHT;
}

@Override
protected void doLayout() {
super.doLayout();

setMinWidth(AMOUNT_BOX_WIDTH);
setMaxWidth(AMOUNT_BOX_WIDTH);
}

private static String getFontStyleBasedOnTextLength(int charCount) {
if (charCount < 9) {
return INPUT_TEXT_9_STYLE_CLASS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public TradeWizardPriceView(TradeWizardPriceModel model, TradeWizardPriceControl
percentageInput = new PriceInputBox(Res.get("bisqEasy.price.percentage.inputBoxText"));
percentageInput.setValidator(new PercentageValidator());
percentageInput.textInputSymbolTextProperty().set("%");
fieldsBox = new VBox(20);
fieldsBox = new VBox(20, priceInput.getRoot(), percentageInput);
fieldsBox.setAlignment(Pos.TOP_CENTER);
fieldsBox.setMinWidth(340);
fieldsBox.setPrefWidth(340);
Expand Down Expand Up @@ -108,13 +108,13 @@ protected void onViewAttached() {
percentageInput.textProperty().bindBidirectional(model.getPercentageInput());
percentageInput.conversionPriceTextProperty().bind(model.getPriceAsString());
percentageInput.conversionPriceSymbolTextProperty().set(model.getMarket().getMarketCodes());
percentageInput.initialize();
feedbackSentence.textProperty().bind(model.getFeedbackSentence());
feedbackBox.visibleProperty().bind(model.getShouldShowFeedback());
feedbackBox.managedProperty().bind(model.getShouldShowFeedback());

percentageFocussedPin = EasyBind.subscribe(percentageInput.textInputFocusedProperty(), controller::onPercentageFocussed);

// FIXME: The very first time this component is used when starting the app requestFocus() is not applied.
useFixPricePin = EasyBind.subscribe(model.getUseFixPrice(), useFixPrice ->
UIScheduler.run(this::updateFieldsBox).after(100));

Expand Down Expand Up @@ -149,6 +149,7 @@ protected void onViewAttached() {
protected void onViewDetached() {
percentageInput.textProperty().unbindBidirectional(model.getPercentageInput());
percentageInput.conversionPriceTextProperty().unbind();
percentageInput.dispose();
feedbackSentence.textProperty().unbind();
feedbackBox.visibleProperty().unbind();
feedbackBox.managedProperty().unbind();
Expand All @@ -174,15 +175,21 @@ private void updateFieldsBox() {
percentagePrice.getStyleClass().remove(SELECTED_PRICE_MODEL_STYLE_CLASS);
if (model.getUseFixPrice().get()) {
fixedPrice.getStyleClass().add(SELECTED_PRICE_MODEL_STYLE_CLASS);
fieldsBox.getChildren().setAll(priceInput.getRoot());
priceInput.getRoot().visibleProperty().set(true);
priceInput.getRoot().managedProperty().set(true);
percentageInput.visibleProperty().set(false);
percentageInput.managedProperty().set(false);
percentageInput.deselect();
percentageInput.setEditable(false);
percentageInput.resetValidation();
priceInput.setEditable(true);
priceInput.requestFocus();
} else {
percentagePrice.getStyleClass().add(SELECTED_PRICE_MODEL_STYLE_CLASS);
fieldsBox.getChildren().setAll(percentageInput);
priceInput.getRoot().visibleProperty().set(false);
priceInput.getRoot().managedProperty().set(false);
percentageInput.visibleProperty().set(true);
percentageInput.managedProperty().set(true);
priceInput.deselect();
priceInput.setEditable(false);
priceInput.resetValidation();
Expand Down

0 comments on commit 3a7c88a

Please sign in to comment.