Refresh all avatars upon setting a tag

This commit is contained in:
Android-X13 2022-09-03 19:12:49 +03:00
parent 854c6218b3
commit 76d85b1940
No known key found for this signature in database
GPG key ID: 161BE7DF6FC78FC7
4 changed files with 55 additions and 34 deletions

View file

@ -55,6 +55,10 @@ import javax.annotation.Nullable;
@Slf4j @Slf4j
public class PeerInfoIcon extends Group { public class PeerInfoIcon extends Group {
public interface notify { 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(); void avatarTagUpdated();
} }
@ -184,7 +188,7 @@ public class PeerInfoIcon extends Group {
.position(localToScene(new Point2D(0, 0))) .position(localToScene(new Point2D(0, 0)))
.onSave(newTag -> { .onSave(newTag -> {
preferences.setTagForPeer(fullAddress, newTag); preferences.setTagForPeer(fullAddress, newTag);
updatePeerInfoIcon(); refreshTag();
if (callback != null) { if (callback != null) {
callback.avatarTagUpdated(); callback.avatarTagUpdated();
} }
@ -205,20 +209,6 @@ public class PeerInfoIcon extends Group {
} }
protected void updatePeerInfoIcon() { protected void updatePeerInfoIcon() {
String tag;
Map<String, String> 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) { if (numTrades > 0) {
numTradesLabel.setText(numTrades > 99 ? "*" : String.valueOf(numTrades)); numTradesLabel.setText(numTrades > 99 ? "*" : String.valueOf(numTrades));
@ -232,6 +222,25 @@ public class PeerInfoIcon extends Group {
numTradesPane.setVisible(numTrades > 0); numTradesPane.setVisible(numTrades > 0);
refreshTag();
}
public void refreshTag() {
String tag;
Map<String, String> 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()); tagPane.setVisible(!tag.isEmpty());
} }
} }

View file

@ -42,8 +42,4 @@ public class PeerInfoIconDispute extends PeerInfoIcon {
addMouseListener(numTrades, null, null, null, preferences, false, addMouseListener(numTrades, null, null, null, preferences, false,
false, accountAge, 0L, null, null, null); false, accountAge, 0L, null, null, null);
} }
public void refreshTag() {
updatePeerInfoIcon();
}
} }

View file

@ -28,6 +28,7 @@ import bisq.desktop.components.AutocompleteComboBox;
import bisq.desktop.components.ColoredDecimalPlacesWithZerosText; import bisq.desktop.components.ColoredDecimalPlacesWithZerosText;
import bisq.desktop.components.HyperlinkWithIcon; import bisq.desktop.components.HyperlinkWithIcon;
import bisq.desktop.components.InfoAutoTooltipLabel; import bisq.desktop.components.InfoAutoTooltipLabel;
import bisq.desktop.components.PeerInfoIcon;
import bisq.desktop.components.PeerInfoIconTrading; import bisq.desktop.components.PeerInfoIconTrading;
import bisq.desktop.components.TitledGroupBg; import bisq.desktop.components.TitledGroupBg;
import bisq.desktop.main.MainView; import bisq.desktop.main.MainView;
@ -112,6 +113,7 @@ import javafx.util.Callback;
import javafx.util.StringConverter; import javafx.util.StringConverter;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
@ -119,7 +121,7 @@ import org.jetbrains.annotations.NotNull;
import static bisq.desktop.util.FormBuilder.addTitledGroupBg; import static bisq.desktop.util.FormBuilder.addTitledGroupBg;
abstract public class OfferBookView<R extends GridPane, M extends OfferBookViewModel> extends ActivatableViewAndModel<R, M> { abstract public class OfferBookView<R extends GridPane, M extends OfferBookViewModel> extends ActivatableViewAndModel<R, M> implements PeerInfoIcon.notify {
private final Navigation navigation; private final Navigation navigation;
private final OfferDetailsWindow offerDetailsWindow; private final OfferDetailsWindow offerDetailsWindow;
@ -152,6 +154,7 @@ abstract public class OfferBookView<R extends GridPane, M extends OfferBookViewM
private static final int SHOW_ALL = 0; private static final int SHOW_ALL = 0;
private Label disabledCreateOfferButtonTooltip; private Label disabledCreateOfferButtonTooltip;
protected VBox currencyComboBoxContainer; protected VBox currencyComboBoxContainer;
private Map<String, PeerInfoIconTrading> avatarMap = new HashMap<>();
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
// Constructor, lifecycle // Constructor, lifecycle
@ -1266,18 +1269,7 @@ abstract public class OfferBookView<R extends GridPane, M extends OfferBookViewM
public void updateItem(final OfferBookListItem newItem, boolean empty) { public void updateItem(final OfferBookListItem newItem, boolean empty) {
super.updateItem(newItem, empty); super.updateItem(newItem, empty);
if (newItem != null && !empty) { if (newItem != null && !empty) {
final Offer offer = newItem.getOffer(); PeerInfoIconTrading peerInfoIcon = findOrCreateAvatar(tableRowProperty().get().getIndex(), newItem.getOffer());
final NodeAddress makersNodeAddress = offer.getOwnerNodeAddress();
String role = Res.get("peerInfoIcon.tooltip.maker");
int numTrades = model.getNumTrades(offer);
PeerInfoIconTrading peerInfoIcon = new PeerInfoIconTrading(makersNodeAddress,
role,
numTrades,
privateNotificationManager,
offer,
model.preferences,
model.accountAgeWitnessService,
useDevPrivilegeKeys);
setGraphic(peerInfoIcon); setGraphic(peerInfoIcon);
} else { } else {
setGraphic(null); setGraphic(null);
@ -1289,6 +1281,32 @@ abstract public class OfferBookView<R extends GridPane, M extends OfferBookViewM
return column; return column;
} }
private PeerInfoIconTrading findOrCreateAvatar(Integer tableRowId, Offer offer) {
final NodeAddress makersNodeAddress = offer.getOwnerNodeAddress();
String key = tableRowId + makersNodeAddress.getHostNameWithoutPostFix();
String role = Res.get("peerInfoIcon.tooltip.maker");
int numTrades = model.getNumTrades(offer);
PeerInfoIconTrading peerInfoIcon = new PeerInfoIconTrading(makersNodeAddress,
role,
numTrades,
privateNotificationManager,
offer,
model.preferences,
model.accountAgeWitnessService,
useDevPrivilegeKeys);
peerInfoIcon.setCallback(this);
avatarMap.put(key, peerInfoIcon);
return peerInfoIcon;
}
@Override
public void avatarTagUpdated() {
log.info("Updating avatar tags, the avatarMap size is {}", avatarMap.size());
avatarMap.forEach((key, avatarIcon) -> {
avatarIcon.refreshTag();
});
}
@NotNull @NotNull
private Region getSpacer() { private Region getSpacer() {
final Region spacer = new Region(); final Region spacer = new Region();

View file

@ -1495,8 +1495,6 @@ public abstract class DisputeView extends ActivatableView<VBox, Void> implements
@Override @Override
public void avatarTagUpdated() { 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()); log.info("Updating avatar tags, the avatarMap size is {}", avatarMap.size());
avatarMap.forEach((key, avatarIcon) -> { avatarMap.forEach((key, avatarIcon) -> {
avatarIcon.refreshTag(); avatarIcon.refreshTag();