Skip to content

Commit

Permalink
Fix user and reputation tooltips in user profile selection
Browse files Browse the repository at this point in the history
  • Loading branch information
axpoems committed Sep 19, 2024
1 parent 1e5fe1b commit 2851e31
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,22 @@ public class UserProfileDisplay extends HBox {
private final Label userName;

public UserProfileDisplay() {
this(null, DEFAULT_ICON_SIZE);
this(null, DEFAULT_ICON_SIZE, null);
}

public UserProfileDisplay(double size) {
this(null, size);
this(null, size, null);
}

public UserProfileDisplay(@Nullable UserProfile userProfile) {
this(userProfile, DEFAULT_ICON_SIZE);
this(userProfile, DEFAULT_ICON_SIZE, null);
}

public UserProfileDisplay(@Nullable UserProfile userProfile, double size) {
public UserProfileDisplay(@Nullable UserProfile userProfile, @Nullable ReputationScore reputationScore) {
this(userProfile, DEFAULT_ICON_SIZE, reputationScore);
}

public UserProfileDisplay(@Nullable UserProfile userProfile, double size, @Nullable ReputationScore reputationScore) {
super(10);

setAlignment(Pos.CENTER_LEFT);
Expand All @@ -69,6 +73,10 @@ public UserProfileDisplay(@Nullable UserProfile userProfile, double size) {
if (userProfile != null) {
setUserProfile(userProfile);
}

if (reputationScore != null) {
setReputationScore(reputationScore);
}
}

public void setUserProfile(@Nullable UserProfile userProfile) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import bisq.i18n.Res;
import bisq.user.identity.UserIdentity;
import bisq.user.identity.UserIdentityService;
import bisq.user.reputation.ReputationScore;
import bisq.user.reputation.ReputationService;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.ObjectProperty;
Expand All @@ -49,6 +51,7 @@
import javafx.scene.layout.Pane;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.fxmisc.easybind.EasyBind;
import org.fxmisc.easybind.Subscription;
Expand Down Expand Up @@ -105,12 +108,14 @@ private static class Controller implements bisq.desktop.common.view.Controller {
private final View view;
private final UserIdentityService userIdentityService;
private final Map<ChatChannelDomain, ChatChannelSelectionService> chatChannelSelectionServices;
private final ReputationService reputationService;
private Pin selectedUserProfilePin, chatChannelSelectionPin, navigationPin, userIdentitiesPin;
private Subscription isPrivateChannelPin;

private Controller(ServiceProvider serviceProvider, int iconSize, boolean useMaterialStyle) {
this.userIdentityService = serviceProvider.getUserService().getUserIdentityService();
chatChannelSelectionServices = serviceProvider.getChatService().getChatChannelSelectionServices();
reputationService = serviceProvider.getUserService().getReputationService();

model = new Model();
view = new View(model, this, iconSize, useMaterialStyle);
Expand All @@ -119,7 +124,10 @@ private Controller(ServiceProvider serviceProvider, int iconSize, boolean useMat
@Override
public void onActivate() {
selectedUserProfilePin = FxBindings.subscribe(userIdentityService.getSelectedUserIdentityObservable(),
userIdentity -> UIThread.run(() -> model.getSelectedUserIdentity().set(userIdentity)));
userIdentity -> UIThread.run(() -> {
model.setUserReputationScore(reputationService.getReputationScore(userIdentity.getUserProfile()));
model.getSelectedUserIdentity().set(userIdentity);
}));
userIdentitiesPin = userIdentityService.getUserIdentities().addObserver(() -> UIThread.run(this::updateUserProfiles));
navigationPin = Navigation.getCurrentNavigationTarget().addObserver(this::navigationTargetChanged);
isPrivateChannelPin = EasyBind.subscribe(model.getIsPrivateChannel(), isPrivate -> updateShouldShowMenu());
Expand All @@ -140,7 +148,8 @@ private void updateUserProfiles() {
model.getUserProfiles().forEach(UserProfileMenuItem::dispose);
model.getUserProfiles().clear();
userIdentityService.getUserIdentities().forEach(userIdentity -> {
UserProfileMenuItem userProfileMenuItem = new UserProfileMenuItem(userIdentity);
UserProfileMenuItem userProfileMenuItem = new UserProfileMenuItem(
userIdentity, reputationService.getReputationScore(userIdentity.getUserProfile()));
userProfileMenuItem.setOnAction(e -> onSelected(userProfileMenuItem));
model.getUserProfiles().add(userProfileMenuItem);
});
Expand All @@ -157,6 +166,7 @@ private void onSelected(UserProfileMenuItem selectedItem) {
selectedUserIdentity.getUserProfile().getUserName()))
.onClose(() -> {
UIThread.run(() -> {
model.setUserReputationScore(reputationService.getReputationScore(selectedUserIdentity.getUserProfile()));
model.getSelectedUserIdentity().set(null);
model.getSelectedUserIdentity().set(selectedUserIdentity);
});
Expand Down Expand Up @@ -225,6 +235,8 @@ private static class Model implements bisq.desktop.common.view.Model {
private final BooleanProperty isPrivateChannel = new SimpleBooleanProperty(false);
private final BooleanProperty shouldShowMenu = new SimpleBooleanProperty(false);
private final DoubleProperty menuWidth = new SimpleDoubleProperty();
@Setter
private ReputationScore userReputationScore;
}

@Slf4j
Expand All @@ -244,7 +256,6 @@ private View(Model model, Controller controller, int iconSize, boolean useMateri

userProfileDisplay = new UserProfileDisplay(iconSize);
dropdownMenu = new DropdownMenu("chevron-drop-menu-grey", "chevron-drop-menu-white", false);
dropdownMenu.setTooltip(Res.get("user.userProfile.comboBox.description"));
dropdownMenu.setContent(userProfileDisplay);
dropdownMenu.useSpaceBetweenContentAndIcon();

Expand Down Expand Up @@ -272,7 +283,9 @@ protected void onViewAttached() {

selectedUserProfilePin = EasyBind.subscribe(model.getSelectedUserIdentity(), selectedUserIdentity -> {
userProfileDisplay.setUserProfile(selectedUserIdentity.getUserProfile());
userProfileDisplay.setReputationScore(model.getUserReputationScore());
singleUserProfileDisplay.setUserProfile(selectedUserIdentity.getUserProfile());
singleUserProfileDisplay.setReputationScore(model.getUserReputationScore());
model.getUserProfiles().forEach(userProfileMenuItem ->
userProfileMenuItem.updateSelection(selectedUserIdentity.equals(userProfileMenuItem.getUserIdentity())));
});
Expand Down Expand Up @@ -319,8 +332,8 @@ public static final class UserProfileMenuItem extends DropdownMenuItem {
@EqualsAndHashCode.Include
private final UserIdentity userIdentity;

private UserProfileMenuItem(UserIdentity userIdentity) {
super("check-white", "check-white", new UserProfileDisplay(userIdentity.getUserProfile()));
private UserProfileMenuItem(UserIdentity userIdentity, ReputationScore reputationScore) {
super("check-white", "check-white", new UserProfileDisplay(userIdentity.getUserProfile(), reputationScore));

this.userIdentity = userIdentity;
getStyleClass().add("dropdown-menu-item");
Expand Down

0 comments on commit 2851e31

Please sign in to comment.