Skip to content

Commit

Permalink
Merge pull request #1732 from axpoems/filterOffersByPeerReputation
Browse files Browse the repository at this point in the history
Add additional filter in Bisq Easy Offerbook to filter offers by peer reputation
  • Loading branch information
alvasw authored Mar 5, 2024
2 parents e2928b6 + c3e0928 commit bd1f95d
Show file tree
Hide file tree
Showing 30 changed files with 366 additions and 185 deletions.
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 @@ -56,7 +56,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 +132,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 +176,8 @@ public void onDeactivate() {
selectedChannelPin.unbind();
marketSelectorSearchPin.unsubscribe();
selectedMarketFilterPin.unsubscribe();
selectedOffersFilterPin.unsubscribe();
selectedOfferDirectionOrOwnerFilterPin.unsubscribe();
selectedPeerReputationFilterPin.unsubscribe();
marketPriceByCurrencyMapPin.unbind();
selectedMarketSortTypePin.unsubscribe();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@
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);

@Setter
Expand Down
Loading

0 comments on commit bd1f95d

Please sign in to comment.