From 76d85b1940246f03e17a1cffc5399172efe866b4 Mon Sep 17 00:00:00 2001 From: Android-X13 <76814540+Android-X13@users.noreply.github.com> Date: Sat, 3 Sep 2022 19:12:49 +0300 Subject: [PATCH 1/4] Refresh all avatars upon setting a tag --- .../bisq/desktop/components/PeerInfoIcon.java | 39 +++++++++------- .../components/PeerInfoIconDispute.java | 4 -- .../main/offer/offerbook/OfferBookView.java | 44 +++++++++++++------ .../main/support/dispute/DisputeView.java | 2 - 4 files changed, 55 insertions(+), 34 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/components/PeerInfoIcon.java b/desktop/src/main/java/bisq/desktop/components/PeerInfoIcon.java index dc494e3049..9a7b7e101c 100644 --- a/desktop/src/main/java/bisq/desktop/components/PeerInfoIcon.java +++ b/desktop/src/main/java/bisq/desktop/components/PeerInfoIcon.java @@ -55,6 +55,10 @@ import javax.annotation.Nullable; @Slf4j public class PeerInfoIcon extends Group { public interface notify { + /** + * Callback from one avatar letting us know that the user updated the tag text. + * We need to update all avatars, as some could be sharing the same tag. + */ void avatarTagUpdated(); } @@ -184,7 +188,7 @@ public class PeerInfoIcon extends Group { .position(localToScene(new Point2D(0, 0))) .onSave(newTag -> { preferences.setTagForPeer(fullAddress, newTag); - updatePeerInfoIcon(); + refreshTag(); if (callback != null) { callback.avatarTagUpdated(); } @@ -205,20 +209,6 @@ public class PeerInfoIcon extends Group { } protected void updatePeerInfoIcon() { - String tag; - Map peerTagMap = preferences.getPeerTagMap(); - if (peerTagMap.containsKey(fullAddress)) { - tag = peerTagMap.get(fullAddress); - final String text = !tag.isEmpty() ? Res.get("peerInfoIcon.tooltip", tooltipText, tag) : tooltipText; - Tooltip.install(this, new Tooltip(text)); - } else { - tag = ""; - Tooltip.install(this, new Tooltip(tooltipText)); - } - - if (!tag.isEmpty()) - tagLabel.setText(tag.substring(0, 1)); - if (numTrades > 0) { numTradesLabel.setText(numTrades > 99 ? "*" : String.valueOf(numTrades)); @@ -232,6 +222,25 @@ public class PeerInfoIcon extends Group { numTradesPane.setVisible(numTrades > 0); + refreshTag(); + } + + public void refreshTag() { + String tag; + Map peerTagMap = preferences.getPeerTagMap(); + if (peerTagMap.containsKey(fullAddress)) { + tag = peerTagMap.get(fullAddress); + final String text = !tag.isEmpty() ? Res.get("peerInfoIcon.tooltip", tooltipText, tag) : tooltipText; + Tooltip.install(this, new Tooltip(text)); + } else { + tag = ""; + Tooltip.install(this, new Tooltip(tooltipText)); + } + + if (!tag.isEmpty()) { + tagLabel.setText(tag.substring(0, 1)); + } + tagPane.setVisible(!tag.isEmpty()); } } diff --git a/desktop/src/main/java/bisq/desktop/components/PeerInfoIconDispute.java b/desktop/src/main/java/bisq/desktop/components/PeerInfoIconDispute.java index 178d9750ed..aa18599008 100644 --- a/desktop/src/main/java/bisq/desktop/components/PeerInfoIconDispute.java +++ b/desktop/src/main/java/bisq/desktop/components/PeerInfoIconDispute.java @@ -42,8 +42,4 @@ public class PeerInfoIconDispute extends PeerInfoIcon { addMouseListener(numTrades, null, null, null, preferences, false, false, accountAge, 0L, null, null, null); } - - public void refreshTag() { - updatePeerInfoIcon(); - } } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java index f3a1d9dc84..d4b47cd75e 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java @@ -28,6 +28,7 @@ import bisq.desktop.components.AutocompleteComboBox; import bisq.desktop.components.ColoredDecimalPlacesWithZerosText; import bisq.desktop.components.HyperlinkWithIcon; import bisq.desktop.components.InfoAutoTooltipLabel; +import bisq.desktop.components.PeerInfoIcon; import bisq.desktop.components.PeerInfoIconTrading; import bisq.desktop.components.TitledGroupBg; import bisq.desktop.main.MainView; @@ -112,6 +113,7 @@ import javafx.util.Callback; import javafx.util.StringConverter; import java.util.Comparator; +import java.util.HashMap; import java.util.Map; import java.util.Optional; @@ -119,7 +121,7 @@ import org.jetbrains.annotations.NotNull; import static bisq.desktop.util.FormBuilder.addTitledGroupBg; -abstract public class OfferBookView extends ActivatableViewAndModel { +abstract public class OfferBookView extends ActivatableViewAndModel implements PeerInfoIcon.notify { private final Navigation navigation; private final OfferDetailsWindow offerDetailsWindow; @@ -152,6 +154,7 @@ abstract public class OfferBookView avatarMap = new HashMap<>(); /////////////////////////////////////////////////////////////////////////////////////////// // Constructor, lifecycle @@ -1266,18 +1269,7 @@ abstract public class OfferBookView { + avatarIcon.refreshTag(); + }); + } + @NotNull private Region getSpacer() { final Region spacer = new Region(); diff --git a/desktop/src/main/java/bisq/desktop/main/support/dispute/DisputeView.java b/desktop/src/main/java/bisq/desktop/main/support/dispute/DisputeView.java index 9ebd7a3528..6e69a7309f 100644 --- a/desktop/src/main/java/bisq/desktop/main/support/dispute/DisputeView.java +++ b/desktop/src/main/java/bisq/desktop/main/support/dispute/DisputeView.java @@ -1495,8 +1495,6 @@ public abstract class DisputeView extends ActivatableView implements @Override public void avatarTagUpdated() { - // callback from one avatar letting us know that the user updated the tag text. - // we update all avatars, as some could be sharing the same tag log.info("Updating avatar tags, the avatarMap size is {}", avatarMap.size()); avatarMap.forEach((key, avatarIcon) -> { avatarIcon.refreshTag(); From 1e82070e7451f36597228a6ebffaf79fe6abafdb Mon Sep 17 00:00:00 2001 From: Android-X13 <76814540+Android-X13@users.noreply.github.com> Date: Sun, 11 Sep 2022 04:09:30 +0300 Subject: [PATCH 2/4] Handle avatar map better --- .../main/java/bisq/desktop/components/PeerInfoIcon.java | 1 - .../bisq/desktop/main/offer/offerbook/OfferBookView.java | 8 +++++--- .../bisq/desktop/main/support/dispute/DisputeView.java | 7 ++++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/components/PeerInfoIcon.java b/desktop/src/main/java/bisq/desktop/components/PeerInfoIcon.java index 9a7b7e101c..5f757a672b 100644 --- a/desktop/src/main/java/bisq/desktop/components/PeerInfoIcon.java +++ b/desktop/src/main/java/bisq/desktop/components/PeerInfoIcon.java @@ -188,7 +188,6 @@ public class PeerInfoIcon extends Group { .position(localToScene(new Point2D(0, 0))) .onSave(newTag -> { preferences.setTagForPeer(fullAddress, newTag); - refreshTag(); if (callback != null) { callback.avatarTagUpdated(); } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java index d4b47cd75e..b7ec009165 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java @@ -488,6 +488,8 @@ abstract public class OfferBookView { @@ -1269,7 +1271,7 @@ abstract public class OfferBookView implements filterTextField.textProperty().removeListener(filterTextFieldListener); sortedList.comparatorProperty().unbind(); selectedDisputeSubscription.unsubscribe(); + avatarMap.clear(); } @@ -1220,7 +1221,7 @@ public abstract class DisputeView extends ActivatableView implements super.updateItem(item, empty); if (item != null && !empty) { setText(getBuyerOnionAddressColumnLabel(item)); - PeerInfoIconDispute peerInfoIconDispute = findOrCreateAvatar(tableRowProperty().get().getIndex(), item.getContract(), true); + PeerInfoIconDispute peerInfoIconDispute = createAvatar(tableRowProperty().get().getIndex(), item.getContract(), true); setGraphic(peerInfoIconDispute); } else { setText(""); @@ -1250,7 +1251,7 @@ public abstract class DisputeView extends ActivatableView implements super.updateItem(item, empty); if (item != null && !empty) { setText(getSellerOnionAddressColumnLabel(item)); - PeerInfoIconDispute peerInfoIconDispute = findOrCreateAvatar(tableRowProperty().get().getIndex(), item.getContract(), false); + PeerInfoIconDispute peerInfoIconDispute = createAvatar(tableRowProperty().get().getIndex(), item.getContract(), false); setGraphic(peerInfoIconDispute); } else { setText(""); @@ -1477,7 +1478,7 @@ public abstract class DisputeView extends ActivatableView implements } } - private PeerInfoIconDispute findOrCreateAvatar(Integer tableRowId, Contract contract, boolean isBuyer) { + private PeerInfoIconDispute createAvatar(Integer tableRowId, Contract contract, boolean isBuyer) { NodeAddress nodeAddress = isBuyer ? contract.getBuyerNodeAddress() : contract.getSellerNodeAddress(); String key = tableRowId + nodeAddress.getHostNameWithoutPostFix() + (isBuyer ? "BUYER" : "SELLER"); Long accountAge = isBuyer ? From 73bb97d2ddf02688d91381f16b0a3a08ef99f668 Mon Sep 17 00:00:00 2001 From: Android-X13 <76814540+Android-X13@users.noreply.github.com> Date: Tue, 13 Sep 2022 21:16:52 +0300 Subject: [PATCH 3/4] Include ability to refresh all tags in Portfolio --- .../bisq/desktop/components/PeerInfoIcon.java | 32 +++++++------ .../desktop/components/PeerInfoIconSmall.java | 11 +++++ .../main/offer/offerbook/OfferBookView.java | 45 +++++++------------ .../bsqswaps/UnconfirmedBsqSwapsView.java | 11 ++++- .../closedtrades/ClosedTradesView.java | 11 ++++- .../pendingtrades/PendingTradesView.java | 9 +++- .../main/support/dispute/DisputeView.java | 15 ++----- 7 files changed, 74 insertions(+), 60 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/components/PeerInfoIcon.java b/desktop/src/main/java/bisq/desktop/components/PeerInfoIcon.java index 5f757a672b..5a83e78bbd 100644 --- a/desktop/src/main/java/bisq/desktop/components/PeerInfoIcon.java +++ b/desktop/src/main/java/bisq/desktop/components/PeerInfoIcon.java @@ -47,23 +47,13 @@ import java.security.NoSuchAlgorithmException; import java.util.Map; -import lombok.Setter; import lombok.extern.slf4j.Slf4j; import javax.annotation.Nullable; @Slf4j public class PeerInfoIcon extends Group { - public interface notify { - /** - * Callback from one avatar letting us know that the user updated the tag text. - * We need to update all avatars, as some could be sharing the same tag. - */ - void avatarTagUpdated(); - } - @Setter - private notify callback; protected Preferences preferences; protected final String fullAddress; protected String tooltipText; @@ -72,6 +62,7 @@ public class PeerInfoIcon extends Group { protected Pane tagPane; protected Pane numTradesPane; protected int numTrades = 0; + private Map avatarMap; public PeerInfoIcon(NodeAddress nodeAddress, Preferences preferences) { this.preferences = preferences; @@ -188,8 +179,11 @@ public class PeerInfoIcon extends Group { .position(localToScene(new Point2D(0, 0))) .onSave(newTag -> { preferences.setTagForPeer(fullAddress, newTag); - if (callback != null) { - callback.avatarTagUpdated(); + if (avatarMap != null) { + log.info("Updating avatar tags, the avatarMap size is {}", avatarMap.size()); + avatarMap.forEach((key, avatarIcon) -> avatarIcon.refreshTag()); + } else { + this.refreshTag(); } }) .show(); @@ -224,7 +218,7 @@ public class PeerInfoIcon extends Group { refreshTag(); } - public void refreshTag() { + protected void refreshTag() { String tag; Map peerTagMap = preferences.getPeerTagMap(); if (peerTagMap.containsKey(fullAddress)) { @@ -242,4 +236,16 @@ public class PeerInfoIcon extends Group { tagPane.setVisible(!tag.isEmpty()); } + + /** + * Sets the map where this icon is stored and associates the latter with the specified key. + * The map will be traversed later on if the user updates an icon's tag, and all avatars + * will be refreshed as some could be sharing the same tag. + * @param avatarMap The map to which this avatar is stored + * @param key Key that is associated with the avatar + */ + public void setAvatarMapAndKey(Map avatarMap, String key) { + this.avatarMap = avatarMap; + avatarMap.put(key, this); + } } diff --git a/desktop/src/main/java/bisq/desktop/components/PeerInfoIconSmall.java b/desktop/src/main/java/bisq/desktop/components/PeerInfoIconSmall.java index 32f70cf996..31f5e4a1d8 100644 --- a/desktop/src/main/java/bisq/desktop/components/PeerInfoIconSmall.java +++ b/desktop/src/main/java/bisq/desktop/components/PeerInfoIconSmall.java @@ -8,8 +8,13 @@ import bisq.core.user.Preferences; import bisq.network.p2p.NodeAddress; +import java.util.Map; + +import lombok.extern.slf4j.Slf4j; + import javax.annotation.Nullable; +@Slf4j public class PeerInfoIconSmall extends PeerInfoIconTrading { public PeerInfoIconSmall(NodeAddress nodeAddress, String role, @@ -53,4 +58,10 @@ public class PeerInfoIconSmall extends PeerInfoIconTrading { numTradesPane.setVisible(false); tagPane.setVisible(false); } + + @Override + public void setAvatarMapAndKey(Map avatarMap, String key) { + // We don't show a tag, so no map needs to be traversed to refresh any tags + log.error("setAvatarMapAndKey: method not supported"); + } } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java index b7ec009165..ac88cafcfa 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java @@ -121,7 +121,7 @@ import org.jetbrains.annotations.NotNull; import static bisq.desktop.util.FormBuilder.addTitledGroupBg; -abstract public class OfferBookView extends ActivatableViewAndModel implements PeerInfoIcon.notify { +abstract public class OfferBookView extends ActivatableViewAndModel { private final Navigation navigation; private final OfferDetailsWindow offerDetailsWindow; @@ -154,7 +154,7 @@ abstract public class OfferBookView avatarMap = new HashMap<>(); + private final Map avatarMap = new HashMap<>(); /////////////////////////////////////////////////////////////////////////////////////////// // Constructor, lifecycle @@ -1271,7 +1271,20 @@ abstract public class OfferBookView { - avatarIcon.refreshTag(); - }); - } - @NotNull private Region getSpacer() { final Region spacer = new Region(); diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/bsqswaps/UnconfirmedBsqSwapsView.java b/desktop/src/main/java/bisq/desktop/main/portfolio/bsqswaps/UnconfirmedBsqSwapsView.java index 8aeb3baf02..e5564dcbcc 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/bsqswaps/UnconfirmedBsqSwapsView.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/bsqswaps/UnconfirmedBsqSwapsView.java @@ -22,6 +22,7 @@ import bisq.desktop.common.view.FxmlView; import bisq.desktop.components.AutoTooltipButton; import bisq.desktop.components.AutoTooltipLabel; import bisq.desktop.components.HyperlinkWithIcon; +import bisq.desktop.components.PeerInfoIcon; import bisq.desktop.components.PeerInfoIconTrading; import bisq.desktop.components.list.FilterBox; import bisq.desktop.main.overlays.windows.BsqTradeDetailsWindow; @@ -46,7 +47,6 @@ import javafx.fxml.FXML; import javafx.stage.Stage; -import javafx.scene.Node; import javafx.scene.control.Label; import javafx.scene.control.TableCell; import javafx.scene.control.TableColumn; @@ -68,6 +68,8 @@ import javafx.collections.transformation.SortedList; import javafx.util.Callback; import java.util.Comparator; +import java.util.HashMap; +import java.util.Map; import java.util.function.Function; @FxmlView @@ -129,6 +131,7 @@ public class UnconfirmedBsqSwapsView extends ActivatableViewAndModel sortedList; private FilteredList filteredList; private ChangeListener widthListener; + private final Map avatarMap = new HashMap<>(); @Inject public UnconfirmedBsqSwapsView(UnconfirmedBsqSwapsViewModel model, @@ -259,6 +262,8 @@ public class UnconfirmedBsqSwapsView extends ActivatableViewAndModel> Comparator nullsFirstComparing( @@ -400,7 +405,7 @@ public class UnconfirmedBsqSwapsView extends ActivatableViewAndModel sortedList; private FilteredList filteredList; private ChangeListener widthListener; + private final Map avatarMap = new HashMap<>(); @Inject public ClosedTradesView(ClosedTradesViewModel model, @@ -344,6 +347,8 @@ public class ClosedTradesView extends ActivatableViewAndModel> Comparator nullsFirstComparing(Function keyExtractor) { @@ -528,7 +533,7 @@ public class ClosedTradesView extends ActivatableViewAndModel disputeStateListener; private ChangeListener mediationResultStateListener; private ChangeListener getMempoolStatusListener; + private final Map avatarMap = new HashMap<>(); /////////////////////////////////////////////////////////////////////////////////////////// @@ -357,6 +358,8 @@ public class PendingTradesView extends ActivatableViewAndModel implements PeerInfoIcon.notify, DisputeChatPopup.ChatCallback { +public abstract class DisputeView extends ActivatableView implements DisputeChatPopup.ChatCallback { public enum FilterResult { NO_MATCH("No Match"), NO_FILTER("No filter text"), @@ -191,7 +191,7 @@ public abstract class DisputeView extends ActivatableView implements private Map chatButtonByDispute = new HashMap<>(); private Map chatBadgeByDispute = new HashMap<>(); private Map newBadgeByDispute = new HashMap<>(); - private Map avatarMap = new HashMap<>(); + private final Map avatarMap = new HashMap<>(); protected DisputeChatPopup chatPopup; @@ -1489,19 +1489,10 @@ public abstract class DisputeView extends ActivatableView implements disputeManager.getNrOfDisputes(isBuyer, contract), accountAge, preferences); - peerInfoIcon.setCallback(this); - avatarMap.put(key, peerInfoIcon); + peerInfoIcon.setAvatarMapAndKey(avatarMap, key); return peerInfoIcon; } - @Override - public void avatarTagUpdated() { - log.info("Updating avatar tags, the avatarMap size is {}", avatarMap.size()); - avatarMap.forEach((key, avatarIcon) -> { - avatarIcon.refreshTag(); - }); - } - @Override public void onCloseDisputeFromChatWindow(Dispute dispute) { handleOnProcessDispute(dispute); From 1bbe90a5a25ea1c60acf3933da93d355deafcb5f Mon Sep 17 00:00:00 2001 From: Android-X13 <76814540+Android-X13@users.noreply.github.com> Date: Sun, 18 Sep 2022 21:37:12 +0300 Subject: [PATCH 4/4] Use custom map listening for tag change events --- .../bisq/desktop/components/PeerInfoIcon.java | 44 ++++++----------- .../desktop/components/PeerInfoIconMap.java | 48 +++++++++++++++++++ .../desktop/components/PeerInfoIconSmall.java | 11 ----- .../main/offer/offerbook/OfferBookView.java | 8 ++-- .../bsqswaps/UnconfirmedBsqSwapsView.java | 9 ++-- .../closedtrades/ClosedTradesView.java | 9 ++-- .../pendingtrades/PendingTradesView.java | 7 +-- .../main/support/dispute/DisputeView.java | 7 +-- 8 files changed, 83 insertions(+), 60 deletions(-) create mode 100644 desktop/src/main/java/bisq/desktop/components/PeerInfoIconMap.java diff --git a/desktop/src/main/java/bisq/desktop/components/PeerInfoIcon.java b/desktop/src/main/java/bisq/desktop/components/PeerInfoIcon.java index 5a83e78bbd..bc090c906a 100644 --- a/desktop/src/main/java/bisq/desktop/components/PeerInfoIcon.java +++ b/desktop/src/main/java/bisq/desktop/components/PeerInfoIcon.java @@ -42,6 +42,9 @@ import javafx.scene.paint.Color; import javafx.geometry.Point2D; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; + import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; @@ -62,11 +65,12 @@ public class PeerInfoIcon extends Group { protected Pane tagPane; protected Pane numTradesPane; protected int numTrades = 0; - private Map avatarMap; + private final StringProperty tag; public PeerInfoIcon(NodeAddress nodeAddress, Preferences preferences) { this.preferences = preferences; this.fullAddress = nodeAddress != null ? nodeAddress.getFullAddress() : ""; + this.tag = new SimpleStringProperty(""); } protected void createAvatar(Color ringColor) { @@ -179,12 +183,7 @@ public class PeerInfoIcon extends Group { .position(localToScene(new Point2D(0, 0))) .onSave(newTag -> { preferences.setTagForPeer(fullAddress, newTag); - if (avatarMap != null) { - log.info("Updating avatar tags, the avatarMap size is {}", avatarMap.size()); - avatarMap.forEach((key, avatarIcon) -> avatarIcon.refreshTag()); - } else { - this.refreshTag(); - } + tag.set(newTag); }) .show(); } @@ -212,40 +211,27 @@ public class PeerInfoIcon extends Group { numTradesLabel.relocate(scaleFactor * 5, scaleFactor * 1); } } - numTradesPane.setVisible(numTrades > 0); refreshTag(); } protected void refreshTag() { - String tag; Map peerTagMap = preferences.getPeerTagMap(); if (peerTagMap.containsKey(fullAddress)) { - tag = peerTagMap.get(fullAddress); - final String text = !tag.isEmpty() ? Res.get("peerInfoIcon.tooltip", tooltipText, tag) : tooltipText; - Tooltip.install(this, new Tooltip(text)); - } else { - tag = ""; - Tooltip.install(this, new Tooltip(tooltipText)); + tag.set(peerTagMap.get(fullAddress)); } - if (!tag.isEmpty()) { - tagLabel.setText(tag.substring(0, 1)); - } + Tooltip.install(this, new Tooltip(!tag.get().isEmpty() ? + Res.get("peerInfoIcon.tooltip", tooltipText, tag.get()) : tooltipText)); - tagPane.setVisible(!tag.isEmpty()); + if (!tag.get().isEmpty()) { + tagLabel.setText(tag.get().substring(0, 1)); + } + tagPane.setVisible(!tag.get().isEmpty()); } - /** - * Sets the map where this icon is stored and associates the latter with the specified key. - * The map will be traversed later on if the user updates an icon's tag, and all avatars - * will be refreshed as some could be sharing the same tag. - * @param avatarMap The map to which this avatar is stored - * @param key Key that is associated with the avatar - */ - public void setAvatarMapAndKey(Map avatarMap, String key) { - this.avatarMap = avatarMap; - avatarMap.put(key, this); + protected StringProperty tagProperty() { + return tag; } } diff --git a/desktop/src/main/java/bisq/desktop/components/PeerInfoIconMap.java b/desktop/src/main/java/bisq/desktop/components/PeerInfoIconMap.java new file mode 100644 index 0000000000..f7436a1937 --- /dev/null +++ b/desktop/src/main/java/bisq/desktop/components/PeerInfoIconMap.java @@ -0,0 +1,48 @@ +/* + * This file is part of Bisq. + * + * Bisq is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bisq is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bisq. If not, see . + */ + +package bisq.desktop.components; + +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; + +import java.util.HashMap; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class PeerInfoIconMap extends HashMap implements ChangeListener { + + @Override + public PeerInfoIcon put(String key, PeerInfoIcon icon) { + icon.tagProperty().addListener(this); + return super.put(key, icon); + } + + @Override + public void changed(ObservableValue o, String oldVal, String newVal) { + log.info("Updating avatar tags, the avatar map size is {}", size()); + forEach((key, icon) -> { + // We update all avatars, as some could be sharing the same tag. + // We also temporarily remove listeners to prevent firing of + // events while each icon's tagProperty is being reset. + icon.tagProperty().removeListener(this); + icon.refreshTag(); + icon.tagProperty().addListener(this); + }); + } +} diff --git a/desktop/src/main/java/bisq/desktop/components/PeerInfoIconSmall.java b/desktop/src/main/java/bisq/desktop/components/PeerInfoIconSmall.java index 31f5e4a1d8..32f70cf996 100644 --- a/desktop/src/main/java/bisq/desktop/components/PeerInfoIconSmall.java +++ b/desktop/src/main/java/bisq/desktop/components/PeerInfoIconSmall.java @@ -8,13 +8,8 @@ import bisq.core.user.Preferences; import bisq.network.p2p.NodeAddress; -import java.util.Map; - -import lombok.extern.slf4j.Slf4j; - import javax.annotation.Nullable; -@Slf4j public class PeerInfoIconSmall extends PeerInfoIconTrading { public PeerInfoIconSmall(NodeAddress nodeAddress, String role, @@ -58,10 +53,4 @@ public class PeerInfoIconSmall extends PeerInfoIconTrading { numTradesPane.setVisible(false); tagPane.setVisible(false); } - - @Override - public void setAvatarMapAndKey(Map avatarMap, String key) { - // We don't show a tag, so no map needs to be traversed to refresh any tags - log.error("setAvatarMapAndKey: method not supported"); - } } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java index ac88cafcfa..429e1420db 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java @@ -28,7 +28,7 @@ import bisq.desktop.components.AutocompleteComboBox; import bisq.desktop.components.ColoredDecimalPlacesWithZerosText; import bisq.desktop.components.HyperlinkWithIcon; import bisq.desktop.components.InfoAutoTooltipLabel; -import bisq.desktop.components.PeerInfoIcon; +import bisq.desktop.components.PeerInfoIconMap; import bisq.desktop.components.PeerInfoIconTrading; import bisq.desktop.components.TitledGroupBg; import bisq.desktop.main.MainView; @@ -113,7 +113,6 @@ import javafx.util.Callback; import javafx.util.StringConverter; import java.util.Comparator; -import java.util.HashMap; import java.util.Map; import java.util.Optional; @@ -154,7 +153,8 @@ abstract public class OfferBookView avatarMap = new HashMap<>(); + @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") + private final PeerInfoIconMap avatarMap = new PeerInfoIconMap(); /////////////////////////////////////////////////////////////////////////////////////////// // Constructor, lifecycle @@ -1284,7 +1284,7 @@ abstract public class OfferBookView sortedList; private FilteredList filteredList; private ChangeListener widthListener; - private final Map avatarMap = new HashMap<>(); + @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") + private final PeerInfoIconMap avatarMap = new PeerInfoIconMap(); @Inject public UnconfirmedBsqSwapsView(UnconfirmedBsqSwapsViewModel model, @@ -414,7 +413,7 @@ public class UnconfirmedBsqSwapsView extends ActivatableViewAndModel sortedList; private FilteredList filteredList; private ChangeListener widthListener; - private final Map avatarMap = new HashMap<>(); + @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") + private final PeerInfoIconMap avatarMap = new PeerInfoIconMap(); @Inject public ClosedTradesView(ClosedTradesViewModel model, @@ -542,7 +541,7 @@ public class ClosedTradesView extends ActivatableViewAndModel disputeStateListener; private ChangeListener mediationResultStateListener; private ChangeListener getMempoolStatusListener; - private final Map avatarMap = new HashMap<>(); + @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") + private final PeerInfoIconMap avatarMap = new PeerInfoIconMap(); /////////////////////////////////////////////////////////////////////////////////////////// @@ -841,7 +842,7 @@ public class PendingTradesView extends ActivatableViewAndModel implements private Map chatButtonByDispute = new HashMap<>(); private Map chatBadgeByDispute = new HashMap<>(); private Map newBadgeByDispute = new HashMap<>(); - private final Map avatarMap = new HashMap<>(); + @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") + private final PeerInfoIconMap avatarMap = new PeerInfoIconMap(); protected DisputeChatPopup chatPopup; @@ -1489,7 +1490,7 @@ public abstract class DisputeView extends ActivatableView implements disputeManager.getNrOfDisputes(isBuyer, contract), accountAge, preferences); - peerInfoIcon.setAvatarMapAndKey(avatarMap, key); + avatarMap.put(key, peerInfoIcon); return peerInfoIcon; }