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

Add show my offers filter in offerlist #2702

Merged
merged 4 commits into from
Aug 27, 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 @@ -33,6 +33,7 @@
import bisq.i18n.Res;
import bisq.settings.CookieKey;
import bisq.settings.SettingsService;
import bisq.user.identity.UserIdentityService;
import bisq.user.profile.UserProfile;
import bisq.user.profile.UserProfileService;
import bisq.user.reputation.ReputationService;
Expand All @@ -57,8 +58,9 @@ public class OfferbookListController implements bisq.desktop.common.view.Control
private final UserProfileService userProfileService;
private final MarketPriceService marketPriceService;
private final ReputationService reputationService;
private Pin showBuyOffersPin, showOfferListExpandedSettingsPin, offerMessagesPin;
private Subscription showBuyOffersFromModelPin, activeMarketPaymentsCountPin;
private final UserIdentityService userIdentityService;
private Pin showBuyOffersPin, showOfferListExpandedSettingsPin, offerMessagesPin, showMyOffersOnlyPin, userIdentityPin;
private Subscription showBuyOffersFromModelPin, activeMarketPaymentsCountPin, showMyOffersOnlyFromModelPin;

public OfferbookListController(ServiceProvider serviceProvider,
ChatMessageContainerController chatMessageContainerController) {
Expand All @@ -67,6 +69,7 @@ public OfferbookListController(ServiceProvider serviceProvider,
userProfileService = serviceProvider.getUserService().getUserProfileService();
marketPriceService = serviceProvider.getBondedRolesService().getMarketPriceService();
reputationService = serviceProvider.getUserService().getReputationService();
userIdentityService = serviceProvider.getUserService().getUserIdentityService();
model = new OfferbookListModel();
view = new OfferbookListView(model, this);
}
Expand All @@ -85,6 +88,9 @@ public void onActivate() {
model.getPaymentFilterTitle().set(Res.get("bisqEasy.offerbook.offerList.table.filters.paymentMethods.title", hint));
applyPredicate();
});
showMyOffersOnlyPin = FxBindings.bindBiDir(model.getShowMyOffersOnly()).to(settingsService.getShowMyOffersOnly());
showMyOffersOnlyFromModelPin = EasyBind.subscribe(model.getShowMyOffersOnly(), showMyOffersOnly -> applyPredicate());
userIdentityPin = userIdentityService.getSelectedUserIdentityObservable().addObserver(userIdentity -> UIThread.run(this::applyPredicate));
}

@Override
Expand All @@ -98,6 +104,9 @@ public void onDeactivate() {
if (offerMessagesPin != null) {
offerMessagesPin.unbind();
}
showMyOffersOnlyPin.unbind();
showMyOffersOnlyFromModelPin.unsubscribe();
userIdentityPin.unbind();
}

public void setSelectedChannel(BisqEasyOfferbookChannel channel) {
Expand Down Expand Up @@ -242,7 +251,10 @@ private boolean shouldShowListItem(OfferbookListItem item) {
boolean matchesPaymentFilters = paymentFiltersApplied && item.getFiatPaymentMethods().stream()
.anyMatch(payment -> (payment.isCustomPaymentMethod() && model.getIsCustomPaymentsSelected().get())
|| model.getSelectedMarketPayments().contains(payment));
return matchesDirection && (!paymentFiltersApplied || matchesPaymentFilters);
boolean myOffersOnly = model.getShowMyOffersOnly().get();
UserProfile selectedUserProfile = userIdentityService.getSelectedUserIdentity().getUserProfile();
boolean isMyOffer = item.getUserProfile().equals(selectedUserProfile);
return matchesDirection && (!paymentFiltersApplied || matchesPaymentFilters) && (!myOffersOnly || isMyOffer);
}

private String getCookieSubKey() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class OfferbookListModel implements bisq.desktop.common.view.Model {
private final BooleanProperty isCustomPaymentsSelected = new SimpleBooleanProperty();
private final IntegerProperty activeMarketPaymentsCount = new SimpleIntegerProperty();
private final SimpleObjectProperty<BisqEasyOfferbookChannel> channel = new SimpleObjectProperty<>();
private final BooleanProperty showMyOffersOnly = new SimpleBooleanProperty();

OfferbookListModel() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@
import javafx.geometry.Pos;
import javafx.scene.Cursor;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.control.SeparatorMenuItem;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.Tooltip;
import javafx.scene.control.*;
import javafx.scene.effect.ColorAdjust;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
Expand All @@ -69,19 +65,20 @@ public class OfferbookListView extends bisq.desktop.common.view.View<VBox, Offer
private static final double COLLAPSED_LIST_WIDTH = BisqEasyOfferbookView.COLLAPSED_LIST_WIDTH;
private static final double HEADER_HEIGHT = BaseChatView.HEADER_HEIGHT;
private static final double LIST_CELL_HEIGHT = BisqEasyOfferbookView.LIST_CELL_HEIGHT;
private static final String ACTIVE_PAYMENT_FILTER_CLASS = "active-payment-filter";
private static final String ACTIVE_FILTER_CLASS = "active-filter";

private final Label title;
private final Label title, showMyOffersOnlyLabel;
private final BisqTableView<OfferbookListItem> tableView;
private final BisqTooltip titleTooltip;
private final HBox header;
private final HBox header, showOnlyMyMessagesHBox;
private final ImageView offerListWhiteIcon, offerListGreyIcon, offerListGreenIcon;
private final DropdownMenu offerDirectionFilterMenu, paymentsFilterMenu;
private final ListChangeListener<FiatPaymentMethod> availablePaymentsChangeListener;
private final SetChangeListener<FiatPaymentMethod> selectedPaymentsChangeListener;
private final CheckBox showOnlyMyMessages;
private DropdownBisqMenuItem buyFromOffers, sellToOffers;
private Label offerDirectionFilterLabel, paymentsFilterLabel;
private Subscription showOfferListExpandedPin, showBuyFromOffersPin,
private Subscription showOfferListExpandedPin, showBuyFromOffersPin, showMyOffersOnlyPin,
offerListTableViewSelectionPin, activeMarketPaymentsCountPin, isCustomPaymentsSelectedPin;

OfferbookListView(OfferbookListModel model, OfferbookListController controller) {
Expand All @@ -107,11 +104,16 @@ public class OfferbookListView extends bisq.desktop.common.view.View<VBox, Offer
selectedPaymentsChangeListener = change -> updatePaymentsSelection();
offerDirectionFilterMenu = createAndGetOffersDirectionFilterMenu();
paymentsFilterMenu = createAndGetPaymentsFilterDropdownMenu();
showMyOffersOnlyLabel = new Label(Res.get("bisqEasy.offerbook.offerList.table.filters.showMyOffersOnly"));
showOnlyMyMessages = new CheckBox();
showOnlyMyMessagesHBox = new HBox(5, showOnlyMyMessages, showMyOffersOnlyLabel);
showOnlyMyMessagesHBox.getStyleClass().add("offerbook-subheader-checkbox");
showOnlyMyMessagesHBox.setAlignment(Pos.CENTER);

HBox subheader = new HBox(10);
subheader.setAlignment(Pos.CENTER_LEFT);
subheader.getStyleClass().add("offer-list-subheader");
subheader.getChildren().addAll(offerDirectionFilterMenu, paymentsFilterMenu);
subheader.getChildren().addAll(offerDirectionFilterMenu, paymentsFilterMenu, showOnlyMyMessagesHBox);

tableView = new BisqTableView<>(model.getSortedOfferbookListItems());
tableView.getStyleClass().add("offers-list");
Expand All @@ -128,6 +130,7 @@ public class OfferbookListView extends bisq.desktop.common.view.View<VBox, Offer
@Override
protected void onViewAttached() {
paymentsFilterLabel.textProperty().bind(model.getPaymentFilterTitle());
showOnlyMyMessages.selectedProperty().bindBidirectional(model.getShowMyOffersOnly());

showOfferListExpandedPin = EasyBind.subscribe(model.getShowOfferListExpanded(), showOfferListExpanded -> {
if (showOfferListExpanded != null) {
Expand All @@ -147,7 +150,12 @@ protected void onViewAttached() {
root.getStyleClass().add("chat-container");
title.setText(Res.get("bisqEasy.offerbook.offerList"));
titleTooltip.setText(Res.get("bisqEasy.offerbook.offerList.expandedList.tooltip"));
Transitions.expansionAnimation(root, COLLAPSED_LIST_WIDTH + 20, EXPANDED_OFFER_LIST_WIDTH);
Transitions.expansionAnimation(root, COLLAPSED_LIST_WIDTH + 20, EXPANDED_OFFER_LIST_WIDTH, () -> {
paymentsFilterMenu.setVisible(true);
paymentsFilterMenu.setManaged(true);
showOnlyMyMessagesHBox.setVisible(true);
showOnlyMyMessagesHBox.setManaged(true);
});
title.setOnMouseExited(e -> title.setGraphic(offerListGreenIcon));
} else {
Transitions.expansionAnimation(root, EXPANDED_OFFER_LIST_WIDTH, COLLAPSED_LIST_WIDTH + 20, () -> {
Expand All @@ -163,6 +171,10 @@ protected void onViewAttached() {
titleTooltip.setText(Res.get("bisqEasy.offerbook.offerList.collapsedList.tooltip"));
title.setGraphic(offerListGreyIcon);
title.setOnMouseExited(e -> title.setGraphic(offerListGreyIcon));
paymentsFilterMenu.setVisible(false);
paymentsFilterMenu.setManaged(false);
showOnlyMyMessagesHBox.setVisible(false);
showOnlyMyMessagesHBox.setManaged(false);
});
}
}
Expand All @@ -186,17 +198,27 @@ protected void onViewAttached() {

activeMarketPaymentsCountPin = EasyBind.subscribe(model.getActiveMarketPaymentsCount(), count -> {
if (count.intValue() != 0) {
if (!paymentsFilterLabel.getStyleClass().contains(ACTIVE_PAYMENT_FILTER_CLASS)) {
paymentsFilterLabel.getStyleClass().add(ACTIVE_PAYMENT_FILTER_CLASS);
if (!paymentsFilterLabel.getStyleClass().contains(ACTIVE_FILTER_CLASS)) {
paymentsFilterLabel.getStyleClass().add(ACTIVE_FILTER_CLASS);
}
} else {
paymentsFilterLabel.getStyleClass().remove(ACTIVE_PAYMENT_FILTER_CLASS);
paymentsFilterLabel.getStyleClass().remove(ACTIVE_FILTER_CLASS);
}
});

isCustomPaymentsSelectedPin = EasyBind.subscribe(model.getIsCustomPaymentsSelected(),
isSelected -> updatePaymentsSelection());

showMyOffersOnlyPin = EasyBind.subscribe(model.getShowMyOffersOnly(), showMyOffers -> {
if (showMyOffers) {
if (!showMyOffersOnlyLabel.getStyleClass().contains(ACTIVE_FILTER_CLASS)) {
showMyOffersOnlyLabel.getStyleClass().add(ACTIVE_FILTER_CLASS);
}
} else {
showMyOffersOnlyLabel.getStyleClass().remove(ACTIVE_FILTER_CLASS);
}
});

model.getAvailableMarketPayments().addListener(availablePaymentsChangeListener);
updateMarketPaymentFilters();
model.getSelectedMarketPayments().addListener(selectedPaymentsChangeListener);
Expand All @@ -213,6 +235,7 @@ protected void onViewAttached() {
@Override
protected void onViewDetached() {
paymentsFilterLabel.textProperty().unbind();
showOnlyMyMessages.selectedProperty().unbindBidirectional(model.getShowMyOffersOnly());

showOfferListExpandedPin.unsubscribe();
offerListTableViewSelectionPin.unsubscribe();
Expand Down
19 changes: 18 additions & 1 deletion apps/desktop/desktop/src/main/resources/css/bisq_easy.css
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,23 @@
-fx-padding: 0 25 0 25;
}

.offerbook-subheader-checkbox .check-box {
-fx-scale-x: 0.6;
-fx-scale-y: 0.6;
-fx-cursor: hand;
}

.offerbook-subheader-checkbox .label {
-fx-text-fill: -fx-mid-text-color;
}

.offerbook-subheader-checkbox .check-box > .box {
-fx-background-color: transparent;
-fx-background-radius: 0;
-fx-border-color: -bisq-mid-grey-20;
-fx-border-width: 1;
}

.offerbook-subheader .dropdown-offers-filter-menu {
-fx-padding: 0 10 0 10;
}
Expand Down Expand Up @@ -333,7 +350,7 @@
-fx-padding: 0 5 0 5;
}

.active-payment-filter {
.active-filter {
-fx-text-fill: -fx-light-text-color !important;
}

Expand Down
1 change: 1 addition & 0 deletions i18n/src/main/resources/bisq_easy.properties
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ bisqEasy.offerbook.offerList.table.filters.paymentMethods.title=Payments ({0})
bisqEasy.offerbook.offerList.table.filters.paymentMethods.title.all=All
bisqEasy.offerbook.offerList.table.filters.paymentMethods.customPayments=Custom payments
bisqEasy.offerbook.offerList.table.filters.paymentMethods.clearFilters=Clear filters
bisqEasy.offerbook.offerList.table.filters.showMyOffersOnly=My offers only

bisqEasy.offerbook.offerList.table.columns.price.tooltip.fixPrice=Fixed price: {0}\nPercentage from current market price: {1}
bisqEasy.offerbook.offerList.table.columns.price.tooltip.marketPrice=Market price: {0}
Expand Down
5 changes: 5 additions & 0 deletions settings/src/main/java/bisq/settings/SettingsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public CompletableFuture<Boolean> initialize() {
getShowOfferListExpanded().addObserver(value -> persist());
getShowMarketSelectionListCollapsed().addObserver(value -> persist());
getBackupLocation().addObserver(value -> persist());
getShowMyOffersOnly().addObserver(value -> persist());

isInitialized = true;

Expand Down Expand Up @@ -223,6 +224,10 @@ public Observable<String> getBackupLocation() {
return persistableStore.backupLocation;
}

public Observable<Boolean> getShowMyOffersOnly() {
return persistableStore.showMyOffersOnly;
}


///////////////////////////////////////////////////////////////////////////////////////////////////
// DontShowAgainMap
Expand Down
18 changes: 13 additions & 5 deletions settings/src/main/java/bisq/settings/SettingsStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public final class SettingsStore implements PersistableStore<SettingsStore> {
final Observable<Boolean> showOfferListExpanded = new Observable<>();
final Observable<Boolean> showMarketSelectionListCollapsed = new Observable<>();
final Observable<String> backupLocation = new Observable<>();
final Observable<Boolean> showMyOffersOnly = new Observable<>();

public SettingsStore() {
this(new Cookie(),
Expand All @@ -83,7 +84,8 @@ public SettingsStore() {
false,
false,
false,
PlatformUtils.getHomeDirectory());
PlatformUtils.getHomeDirectory(),
false);
}

public SettingsStore(Cookie cookie,
Expand All @@ -108,7 +110,8 @@ public SettingsStore(Cookie cookie,
boolean showBuyOffers,
boolean showOfferListExpanded,
boolean showMarketSelectionListCollapsed,
String backupLocation) {
String backupLocation,
boolean showMyOffersOnly) {
this.cookie = cookie;
this.dontShowAgainMap.putAll(dontShowAgainMap);
this.useAnimations.set(useAnimations);
Expand All @@ -132,6 +135,7 @@ public SettingsStore(Cookie cookie,
this.showOfferListExpanded.set(showOfferListExpanded);
this.showMarketSelectionListCollapsed.set(showMarketSelectionListCollapsed);
this.backupLocation.set(backupLocation);
this.showMyOffersOnly.set(showMyOffersOnly);
}

@Override
Expand Down Expand Up @@ -159,7 +163,8 @@ public bisq.settings.protobuf.SettingsStore.Builder getBuilder(boolean serialize
.setShowBuyOffers(showBuyOffers.get())
.setShowOfferListExpanded(showOfferListExpanded.get())
.setShowMarketSelectionListCollapsed(showMarketSelectionListCollapsed.get())
.setBackupLocation(backupLocation.get());
.setBackupLocation(backupLocation.get())
.setShowMyOffersOnly(showMyOffersOnly.get());
}

@Override
Expand Down Expand Up @@ -199,7 +204,8 @@ public static SettingsStore fromProto(bisq.settings.protobuf.SettingsStore proto
proto.getShowBuyOffers(),
proto.getShowOfferListExpanded(),
proto.getShowMarketSelectionListCollapsed(),
proto.getBackupLocation());
proto.getBackupLocation(),
proto.getShowMyOffersOnly());
}

@Override
Expand Down Expand Up @@ -237,7 +243,8 @@ public SettingsStore getClone() {
showBuyOffers.get(),
showOfferListExpanded.get(),
showMarketSelectionListCollapsed.get(),
backupLocation.get());
backupLocation.get(),
showMyOffersOnly.get());
}

@Override
Expand Down Expand Up @@ -266,6 +273,7 @@ public void applyPersisted(SettingsStore persisted) {
showOfferListExpanded.set(persisted.showOfferListExpanded.get());
showMarketSelectionListCollapsed.set(persisted.showMarketSelectionListCollapsed.get());
backupLocation.set(persisted.backupLocation.get());
showMyOffersOnly.set(persisted.showMyOffersOnly.get());
} catch (Exception e) {
log.error("Exception at applyPersisted", e);
}
Expand Down
1 change: 1 addition & 0 deletions settings/src/main/proto/settings.proto
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,5 @@ message SettingsStore {
bool showOfferListExpanded = 21;
bool showMarketSelectionListCollapsed = 22;
string backupLocation = 23;
bool showMyOffersOnly = 24;
}
Loading