From 3810fdef02084d337a1c2780b73daa8e10bccb79 Mon Sep 17 00:00:00 2001 From: delvh Date: Thu, 8 Oct 2020 14:34:21 +0200 Subject: [PATCH] Fixed a bug showing the wrong user status in ChatScene top bar Additionally refactored UI components a bit --- .../envoy/client/ui/control/ChatControl.java | 13 +++---- .../client/ui/control/ContactControl.java | 10 ++---- .../client/ui/control/GroupSizeLabel.java | 20 +++++++++++ .../client/ui/control/UserStatusLabel.java | 23 ++++++++++++ .../envoy/client/ui/controller/ChatScene.java | 36 +++++++++++-------- client/src/main/resources/fxml/ChatScene.fxml | 9 ++--- 6 files changed, 75 insertions(+), 36 deletions(-) create mode 100644 client/src/main/java/envoy/client/ui/control/GroupSizeLabel.java create mode 100644 client/src/main/java/envoy/client/ui/control/UserStatusLabel.java diff --git a/client/src/main/java/envoy/client/ui/control/ChatControl.java b/client/src/main/java/envoy/client/ui/control/ChatControl.java index eca5cb5..353bdaf 100644 --- a/client/src/main/java/envoy/client/ui/control/ChatControl.java +++ b/client/src/main/java/envoy/client/ui/control/ChatControl.java @@ -2,9 +2,8 @@ package envoy.client.ui.control; import javafx.geometry.*; import javafx.scene.control.Label; -import javafx.scene.image.*; +import javafx.scene.image.Image; import javafx.scene.layout.*; -import javafx.scene.shape.Rectangle; import envoy.client.data.*; import envoy.client.util.IconUtil; @@ -23,6 +22,8 @@ public final class ChatControl extends HBox { groupIcon = IconUtil.loadIconThemeSensitive("group_icon", 32); /** + * Creates a new {@code ChatControl}. + * * @param chat the chat to display * @since Envoy Client v0.1-beta */ @@ -31,13 +32,7 @@ public final class ChatControl extends HBox { setPadding(new Insets(0, 0, 3, 0)); // Profile picture - ImageView contactProfilePic = new ImageView(chat instanceof GroupChat ? groupIcon : userIcon); - final var clip = new Rectangle(); - clip.setWidth(32); - clip.setHeight(32); - clip.setArcHeight(32); - clip.setArcWidth(32); - contactProfilePic.setClip(clip); + final var contactProfilePic = new ProfilePicImageView(chat instanceof GroupChat ? groupIcon : userIcon, 32); getChildren().add(contactProfilePic); // Spacing diff --git a/client/src/main/java/envoy/client/ui/control/ContactControl.java b/client/src/main/java/envoy/client/ui/control/ContactControl.java index 8a85739..fea200c 100644 --- a/client/src/main/java/envoy/client/ui/control/ContactControl.java +++ b/client/src/main/java/envoy/client/ui/control/ContactControl.java @@ -26,14 +26,8 @@ public final class ContactControl extends VBox { getChildren().add(nameLabel); // Online status (user) or member count (group) - if (contact instanceof User) { - final var status = ((User) contact).getStatus().toString(); - final var statusLabel = new Label(status); - statusLabel.getStyleClass().add(status.toLowerCase()); - getChildren().add(statusLabel); - } else { - getChildren().add(new Label(contact.getContacts().size() + " members")); - } + getChildren().add(contact instanceof User ? new UserStatusLabel((User) contact) : new GroupSizeLabel((Group) contact)); + getStyleClass().add("list-element"); } } diff --git a/client/src/main/java/envoy/client/ui/control/GroupSizeLabel.java b/client/src/main/java/envoy/client/ui/control/GroupSizeLabel.java new file mode 100644 index 0000000..8413744 --- /dev/null +++ b/client/src/main/java/envoy/client/ui/control/GroupSizeLabel.java @@ -0,0 +1,20 @@ +package envoy.client.ui.control; + +import javafx.scene.control.Label; + +import envoy.data.Group; + +/** + * Displays the amount of members in a {@link Group}. + * + * @author Leon Hofmeister + * @since Envoy Client v0.3-beta + */ +public final class GroupSizeLabel extends Label { + + /** + * @param recipient the group whose members to show + * @since Envoy Client v0.3-beta + */ + public GroupSizeLabel(Group recipient) { super(recipient.getContacts().size() + " members"); } +} diff --git a/client/src/main/java/envoy/client/ui/control/UserStatusLabel.java b/client/src/main/java/envoy/client/ui/control/UserStatusLabel.java new file mode 100644 index 0000000..4f942cb --- /dev/null +++ b/client/src/main/java/envoy/client/ui/control/UserStatusLabel.java @@ -0,0 +1,23 @@ +package envoy.client.ui.control; + +import javafx.scene.control.Label; + +import envoy.data.User; + +/** + * Displays the status of a {@link User}. + * + * @author Leon Hofmeister + * @since Envoy Client v0.3-beta + */ +public final class UserStatusLabel extends Label { + + /** + * @param user the user whose status to display + * @since Envoy Client v0.3-beta + */ + public UserStatusLabel(User user) { + super(user.getStatus().toString()); + getStyleClass().add(user.getStatus().toString().toLowerCase()); + } +} diff --git a/client/src/main/java/envoy/client/ui/controller/ChatScene.java b/client/src/main/java/envoy/client/ui/controller/ChatScene.java index ad3caaf..d1a5eb6 100644 --- a/client/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/client/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -51,12 +51,6 @@ import dev.kske.eventbus.Event; */ public final class ChatScene implements EventListener, Restorable { - @FXML - private GridPane scene; - - @FXML - private Label contactLabel; - @FXML private ListView messageList; @@ -85,7 +79,7 @@ public final class ChatScene implements EventListener, Restorable { private Button newContactButton; @FXML - private TextArea messageTextArea; + private Label contactLabel; @FXML private Label remainingChars; @@ -93,24 +87,27 @@ public final class ChatScene implements EventListener, Restorable { @FXML private Label infoLabel; - @FXML - private MenuItem deleteContactMenuItem; - - @FXML - private ImageView attachmentView; - @FXML private Label topBarContactLabel; @FXML private Label topBarStatusLabel; + @FXML + private MenuItem deleteContactMenuItem; + + @FXML + private ImageView attachmentView; + @FXML private ImageView clientProfilePic; @FXML private ImageView recipientProfilePic; + @FXML + private TextArea messageTextArea; + @FXML private TextArea contactSearch; @@ -251,8 +248,17 @@ public final class ChatScene implements EventListener, Restorable { .ifPresent(msg -> Platform.runLater(messageList::refresh)); } - @Event(eventType = UserStatusChange.class) - private void onUserStatusChange() { Platform.runLater(chatList::refresh); } + @Event + private void onUserStatusChange(UserStatusChange statusChange) { + Platform.runLater(() -> { + chatList.refresh(); + if (currentChat != null && currentChat.getRecipient().getID() == statusChange.getID()) { + topBarStatusLabel.getStyleClass().clear(); + topBarStatusLabel.setText(statusChange.get().toString()); + topBarStatusLabel.getStyleClass().add(statusChange.get().toString().toLowerCase()); + } + }); + } @Event private void onContactOperation(ContactOperation operation) { diff --git a/client/src/main/resources/fxml/ChatScene.fxml b/client/src/main/resources/fxml/ChatScene.fxml index f557974..5de351f 100644 --- a/client/src/main/resources/fxml/ChatScene.fxml +++ b/client/src/main/resources/fxml/ChatScene.fxml @@ -22,14 +22,15 @@ - - +