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
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<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) {
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<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());
}
}

View file

@ -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();
}
}

View file

@ -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<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 OfferDetailsWindow offerDetailsWindow;
@ -152,6 +154,7 @@ abstract public class OfferBookView<R extends GridPane, M extends OfferBookViewM
private static final int SHOW_ALL = 0;
private Label disabledCreateOfferButtonTooltip;
protected VBox currencyComboBoxContainer;
private Map<String, PeerInfoIconTrading> avatarMap = new HashMap<>();
///////////////////////////////////////////////////////////////////////////////////////////
// Constructor, lifecycle
@ -1266,8 +1269,21 @@ abstract public class OfferBookView<R extends GridPane, M extends OfferBookViewM
public void updateItem(final OfferBookListItem newItem, boolean empty) {
super.updateItem(newItem, empty);
if (newItem != null && !empty) {
final Offer offer = newItem.getOffer();
PeerInfoIconTrading peerInfoIcon = findOrCreateAvatar(tableRowProperty().get().getIndex(), newItem.getOffer());
setGraphic(peerInfoIcon);
} else {
setGraphic(null);
}
}
};
}
});
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,
@ -1278,15 +1294,17 @@ abstract public class OfferBookView<R extends GridPane, M extends OfferBookViewM
model.preferences,
model.accountAgeWitnessService,
useDevPrivilegeKeys);
setGraphic(peerInfoIcon);
} else {
setGraphic(null);
}
}
};
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();
});
return column;
}
@NotNull

View file

@ -1495,8 +1495,6 @@ public abstract class DisputeView extends ActivatableView<VBox, Void> 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();