Skip to content

Commit

Permalink
Refactor code for updating person detail view
Browse files Browse the repository at this point in the history
The updates rearrange the order of operations for resetting the avatar, text, and boxes when a person's detail view is refreshed. Additionally, the updateBadge() and updatePersonLinkedObjectBox() functions have been adjusted to directly receive the person object as a parameter and the labels of badges have been corrected.
  • Loading branch information
leewyatt committed Jul 19, 2024
1 parent 8968a76 commit 08459ce
Showing 1 changed file with 23 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,32 +79,32 @@ public MobilePersonDetailView() {
}

private void updateView() {
Person person = getPerson();

// reset the avatar image
if (avatarView.imageProperty().isBound()) {
avatarView.imageProperty().unbind();
}
if (person != null) {
avatarView.imageProperty().bind(ImageManager.getInstance().personImageProperty(person));

Person person = getPerson();
if (person == null) {
nameLabel.setText("");
descriptionLabel.setText("");
badgeBox.getChildren().clear();
personLinkedObjectBox.getChildren().clear();
return;
}

// reset the avatar
avatarView.imageProperty().bind(ImageManager.getInstance().personImageProperty(person));

// reset the text
nameLabel.setText(person == null ? "" : person.getName());
descriptionLabel.setText(person == null ? "" : DataRepository2.getInstance().getPersonReadMe(person));
nameLabel.setText(person.getName());
descriptionLabel.setText(DataRepository2.getInstance().getPersonReadMe(person));

// reset the boxes
updateBadge();
updatePersonLinkedObjectBox();
updateBadge(person);
updatePersonLinkedObjectBox(person);
}

private void updatePersonLinkedObjectBox() {
personLinkedObjectBox.getChildren().clear();
Person person = getPerson();
if (person == null) {
return;
}

private void updatePersonLinkedObjectBox(Person person) {
List<RealWorldApp> linkedApps = getLinkedObjects(person, RealWorldApp.class);
if (!linkedApps.isEmpty()) {
CategoryPreviewView showCasePreviewView = CategoryPreviewView.createShowCasePreviewView(linkedApps);
Expand Down Expand Up @@ -148,24 +148,19 @@ private void updatePersonLinkedObjectBox() {
// learn part
}

private void updateBadge() {
badgeBox.getChildren().clear();
Person person = getPerson();
if (person == null) {
return;
}
private void updateBadge(Person person) {
if (person.isChampion()) {
Label championBadge = new Label("Rockstar", new FontIcon(IkonUtil.champion));
championBadge.getStyleClass().addAll("badge-item", "rockstar");
Label championBadge = new Label("Champion", new FontIcon(IkonUtil.champion));
championBadge.getStyleClass().addAll("badge-item", "champion");
championBadge.setMinWidth(Region.USE_PREF_SIZE);
badgeBox.getChildren().add(championBadge);
}

if (person.isRockstar()) {
Label rockStartBadge = new Label("Champion", new FontIcon(IkonUtil.rockstar));
rockStartBadge.getStyleClass().addAll("badge-item", "champion");
rockStartBadge.setMinWidth(Region.USE_PREF_SIZE);
badgeBox.getChildren().add(rockStartBadge);
Label rockstarBadge = new Label("Rockstar", new FontIcon(IkonUtil.rockstar));
rockstarBadge.getStyleClass().addAll("badge-item", "rockstar");
rockstarBadge.setMinWidth(Region.USE_PREF_SIZE);
badgeBox.getChildren().add(rockstarBadge);
}
}

Expand Down

0 comments on commit 08459ce

Please sign in to comment.