Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update offerbook according to new revision #1734

Merged
merged 15 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package bisq.desktop.components.controls;

import bisq.desktop.common.utils.ImageUtil;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.WeakChangeListener;
import javafx.collections.ObservableList;
import javafx.geometry.Bounds;
Expand All @@ -36,6 +37,7 @@ public class DropdownMenu extends HBox {
private final ImageView defaultIcon, activeIcon;
private final ContextMenu contextMenu = new ContextMenu();
private ImageView buttonIcon;
private ChangeListener<Number> widthPropertyChangeListener;
private boolean isFirstRun = false;

public DropdownMenu(String defaultIconId, String activeIconId, boolean useIconOnly) {
Expand Down Expand Up @@ -129,7 +131,7 @@ private void attachListeners() {
updateIcon(defaultIcon);
});

contextMenu.widthProperty().addListener(new WeakChangeListener<Number>((observable, oldValue, newValue) -> {
widthPropertyChangeListener = (observable, oldValue, newValue) -> {
if (newValue.doubleValue() > INITIAL_WIDTH && !isFirstRun) {
isFirstRun = true;
// Once the contextMenu has calculated the width on the first render time we update the items
Expand All @@ -141,7 +143,8 @@ private void attachListeners() {
}
}
}
}));
};
contextMenu.widthProperty().addListener(new WeakChangeListener<>(widthPropertyChangeListener));
}

private void updateIcon(ImageView newIcon) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,15 @@
import javafx.scene.control.Label;

public class DropdownTitleMenuItem extends CustomMenuItem {
private final Label label;

public DropdownTitleMenuItem(String text) {
Label label = new Label(text);
label = new Label(text);
setContent(label);
getStyleClass().add("dropdown-title-menu-item");
}

public String getLabelText() {
return label.getText();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import bisq.desktop.main.content.chat.ChatController;
import bisq.desktop.main.content.components.MarketImageComposition;
import bisq.offer.bisq_easy.BisqEasyOffer;
import bisq.presentation.formatters.PriceFormatter;
import bisq.settings.CookieKey;
import bisq.settings.SettingsService;
import javafx.scene.layout.StackPane;
Expand All @@ -56,7 +57,8 @@ public final class BisqEasyOfferbookController extends ChatController<BisqEasyOf
private final BisqEasyOfferbookChannelService bisqEasyOfferbookChannelService;
private final BisqEasyOfferbookModel bisqEasyOfferbookModel;
private Pin offerOnlySettingsPin, bisqEasyPrivateTradeChatChannelsPin, selectedChannelPin, marketPriceByCurrencyMapPin;
private Subscription marketSelectorSearchPin, selectedMarketFilterPin, selectedOffersFilterPin, selectedMarketSortTypePin;
private Subscription marketSelectorSearchPin, selectedMarketFilterPin, selectedOfferDirectionOrOwnerFilterPin,
selectedPeerReputationFilterPin, selectedMarketSortTypePin;

public BisqEasyOfferbookController(ServiceProvider serviceProvider) {
super(serviceProvider, ChatChannelDomain.BISQ_EASY_OFFERBOOK, NavigationTarget.BISQ_EASY_OFFERBOOK);
Expand Down Expand Up @@ -131,13 +133,23 @@ public void onActivate() {
});
});

selectedOffersFilterPin = EasyBind.subscribe(model.getSelectedOffersFilter(), filter -> {
selectedOfferDirectionOrOwnerFilterPin = EasyBind.subscribe(model.getSelectedOfferDirectionOrOwnerFilter(), filter -> {
if (filter == null) {
// By default, show all offers
model.getSelectedOffersFilter().set(Filters.Offers.ALL);
chatMessagesComponent.setBisqEasyOffersFilerPredicate(model.getSelectedOffersFilter().get().getPredicate());
// By default, show all offers (any direction or owner)
model.getSelectedOfferDirectionOrOwnerFilter().set(Filters.OfferDirectionOrOwner.ALL);
chatMessagesComponent.setBisqEasyOfferDirectionOrOwnerFilterPredicate(model.getSelectedOfferDirectionOrOwnerFilter().get().getPredicate());
} else {
chatMessagesComponent.setBisqEasyOffersFilerPredicate(filter.getPredicate());
chatMessagesComponent.setBisqEasyOfferDirectionOrOwnerFilterPredicate(filter.getPredicate());
}
});

selectedPeerReputationFilterPin = EasyBind.subscribe(model.getSelectedPeerReputationFilter(), filter -> {
if (filter == null) {
// By default, show all offers (with any reputation)
model.getSelectedPeerReputationFilter().set(Filters.PeerReputation.ALL);
chatMessagesComponent.setBisqEasyPeerReputationFilterPredicate(model.getSelectedPeerReputationFilter().get().getPredicate());
} else {
chatMessagesComponent.setBisqEasyPeerReputationFilterPredicate(filter.getPredicate());
}
});

Expand Down Expand Up @@ -165,7 +177,8 @@ public void onDeactivate() {
selectedChannelPin.unbind();
marketSelectorSearchPin.unsubscribe();
selectedMarketFilterPin.unsubscribe();
selectedOffersFilterPin.unsubscribe();
selectedOfferDirectionOrOwnerFilterPin.unsubscribe();
selectedPeerReputationFilterPin.unsubscribe();
marketPriceByCurrencyMapPin.unbind();
selectedMarketSortTypePin.unsubscribe();

Expand Down Expand Up @@ -194,15 +207,20 @@ protected void selectedChannelChanged(ChatChannel<? extends ChatMessage> chatCha
model.getSearchText().set("");
resetSelectedChildTarget();

String description = ((BisqEasyOfferbookChannel) chatChannel).getDescription();
String oneLineDescription = description.replace("\n", " ");
model.getChannelDescription().set(oneLineDescription);
String description = channel.getDescription();
String channelTitle = description.replace("\n", " ").replaceAll("\\s*\\([^)]*\\)", "");
model.getChannelTitle().set(channelTitle);

Market market = ((BisqEasyOfferbookChannel) chatChannel).getMarket();
String marketSpecs = channel.getDisplayString();
model.getChannelDescription().set(marketSpecs);

Market market = channel.getMarket();
StackPane marketsImage = MarketImageComposition.imageBoxForMarkets(
market.getBaseCurrencyCode().toLowerCase(),
market.getQuoteCurrencyCode().toLowerCase());
model.getChannelIconNode().set(marketsImage);

updateMarketPrice();
}
});
}
Expand Down Expand Up @@ -234,6 +252,16 @@ void onSortMarkets(MarketSortType marketSortType) {
model.getSortedMarketChannelItems().setComparator(marketSortType.getComparator());
}

private void updateMarketPrice() {
Market selectedMarket = getModel().getSelectedMarketChannelItem().get().getMarket();
if (selectedMarket != null) {
marketPriceService
.findMarketPrice(selectedMarket)
.ifPresent(marketPrice ->
model.getMarketPrice().set(PriceFormatter.format(marketPrice.getPriceQuote(), true)));
}
}

private void updateFilteredMarketChannelItems() {
model.getFilteredMarketChannelItems().setPredicate(item ->
model.getMarketFilterPredicate().test(item) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,17 @@
public final class BisqEasyOfferbookModel extends ChatModel {
private final BooleanProperty offerOnly = new SimpleBooleanProperty();
private final BooleanProperty isTradeChannelVisible = new SimpleBooleanProperty();
private final BooleanProperty showFilterOverlay = new SimpleBooleanProperty();
private final BooleanProperty showFilterOverlay = new SimpleBooleanProperty(); // TODO: remove this
private final ObservableList<MarketChannelItem> marketChannelItems = FXCollections.observableArrayList();
private final FilteredList<MarketChannelItem> filteredMarketChannelItems = new FilteredList<>(marketChannelItems);
private final SortedList<MarketChannelItem> sortedMarketChannelItems = new SortedList<>(filteredMarketChannelItems);
private final ObjectProperty<MarketChannelItem> selectedMarketChannelItem = new SimpleObjectProperty<>();
private final StringProperty marketSelectorSearchText = new SimpleStringProperty();
private final ObjectProperty<Filters.Markets> selectedMarketsFilter = new SimpleObjectProperty<>();
private final ObjectProperty<Filters.Offers> selectedOffersFilter = new SimpleObjectProperty<>();
private final ObjectProperty<Filters.OfferDirectionOrOwner> selectedOfferDirectionOrOwnerFilter = new SimpleObjectProperty<>();
private final ObjectProperty<Filters.PeerReputation> selectedPeerReputationFilter = new SimpleObjectProperty<>();
private final ObjectProperty<MarketSortType> selectedMarketSortType = new SimpleObjectProperty<>(MarketSortType.NUM_OFFERS);
private final StringProperty marketPrice = new SimpleStringProperty();

@Setter
private Predicate<MarketChannelItem> marketPricePredicate = marketChannelItem -> true;
Expand Down
Loading
Loading