From 7b6b3a28f3add46485ee3570bf040496260775b9 Mon Sep 17 00:00:00 2001 From: DieGurke <55625494+DieGurke@users.noreply.github.com> Date: Sun, 12 Jul 2020 14:46:35 +0200 Subject: [PATCH] Adjusted ChatControl constructor and added Javadoc --- src/main/java/envoy/client/data/Chat.java | 9 +++++++++ src/main/java/envoy/client/ui/listcell/ChatControl.java | 8 ++++---- .../envoy/client/ui/listcell/ContactListCellFactory.java | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main/java/envoy/client/data/Chat.java b/src/main/java/envoy/client/data/Chat.java index b08fb25..c1b8f37 100644 --- a/src/main/java/envoy/client/data/Chat.java +++ b/src/main/java/envoy/client/data/Chat.java @@ -114,8 +114,17 @@ public class Chat implements Serializable { messages.add(0, message); } + /** + * Increments the unreadMessagesAmount by 1 + * + * @since Envoy Client v0.1-beta + */ public void incrementUnreadAmount() { unreadAmount++; } + /** + * @return the amount of unreadMesages in this chat + * @since Envoy Client v0.1-beta + */ public int getUnreadAmount() { return unreadAmount; } /** diff --git a/src/main/java/envoy/client/ui/listcell/ChatControl.java b/src/main/java/envoy/client/ui/listcell/ChatControl.java index 5a8b9bc..98294a7 100644 --- a/src/main/java/envoy/client/ui/listcell/ChatControl.java +++ b/src/main/java/envoy/client/ui/listcell/ChatControl.java @@ -22,10 +22,10 @@ import envoy.data.User; public class ChatControl extends HBox { /** - * @param contact the contact that should be formatted + * @param chat the chat to display * @since Envoy Client v0.1-beta */ - public ChatControl(Chat chat, int unreadMessagesAmount) { + public ChatControl(Chat chat) { // Container with contact name final var vBox = new VBox(); final var nameLabel = new Label(chat.getRecipient().getName()); @@ -41,11 +41,11 @@ public class ChatControl extends HBox { vBox.getChildren().add(new Label(((Group) chat.getRecipient()).getContacts().size() + " members")); getChildren().add(vBox); - if (unreadMessagesAmount != 0) { + if (chat.getUnreadAmount() != 0) { Region spacing = new Region(); setHgrow(spacing, Priority.ALWAYS); getChildren().add(spacing); - final var unreadMessagesLabel = new Label("" + unreadMessagesAmount); + final var unreadMessagesLabel = new Label(Integer.toString(chat.getUnreadAmount())); unreadMessagesLabel.setMinSize(15, 15); var vBox2 = new VBox(); vBox2.setAlignment(Pos.CENTER_RIGHT); diff --git a/src/main/java/envoy/client/ui/listcell/ContactListCellFactory.java b/src/main/java/envoy/client/ui/listcell/ContactListCellFactory.java index acf116f..3d34aa9 100644 --- a/src/main/java/envoy/client/ui/listcell/ContactListCellFactory.java +++ b/src/main/java/envoy/client/ui/listcell/ContactListCellFactory.java @@ -36,7 +36,7 @@ public class ContactListCellFactory extends ListCell { setText(null); setGraphic(null); } else { - final var control = new ChatControl(chat, chat.getUnreadAmount()); + final var control = new ChatControl(chat); prefWidthProperty().bind(listView.widthProperty().subtract(40)); setGraphic(control); }