From 11b3cebcb90cc159b793c726703aa99b07e8f17c Mon Sep 17 00:00:00 2001 From: DieGurke <55625494+DieGurke@users.noreply.github.com> Date: Fri, 10 Jul 2020 22:41:59 +0200 Subject: [PATCH 01/14] Added getUnreadAmount function and changed ContactListCellFac' constr. --- src/main/java/envoy/client/data/Chat.java | 9 ++++++++ .../envoy/client/ui/controller/ChatScene.java | 18 ++++++++------- .../ui/controller/ContactSearchScene.java | 23 ++++++++++++------- .../ui/controller/GroupCreationScene.java | 13 +++++++---- .../client/ui/listcell/ContactControl.java | 3 +++ .../ui/listcell/ContactListCellFactory.java | 16 ++++++------- 6 files changed, 54 insertions(+), 28 deletions(-) diff --git a/src/main/java/envoy/client/data/Chat.java b/src/main/java/envoy/client/data/Chat.java index 739d335..68d55fd 100644 --- a/src/main/java/envoy/client/data/Chat.java +++ b/src/main/java/envoy/client/data/Chat.java @@ -111,6 +111,15 @@ public class Chat implements Serializable { messages.add(0, message); } + public int getUnreadAmount() { + int unreadMessagesAmount = 0; + for (int i = messages.size() - 1; i >= 0; i--) { + if (messages.get(i).getStatus() == MessageStatus.RECEIVED) unreadMessagesAmount++; + else break; + } + return unreadMessagesAmount; + } + /** * @return all messages in the current chat * @since Envoy Client v0.1-beta diff --git a/src/main/java/envoy/client/ui/controller/ChatScene.java b/src/main/java/envoy/client/ui/controller/ChatScene.java index 2cf116b..d3940eb 100644 --- a/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -52,7 +52,7 @@ public final class ChatScene implements Restorable { private ListView messageList; @FXML - private ListView userList; + private ListView userList; @FXML private Button postButton; @@ -121,7 +121,7 @@ public final class ChatScene implements Restorable { logger.log(Level.WARNING, "Could not read current chat: ", e1); } Platform.runLater(() -> { messageList.refresh(); scrollToMessageListEnd(); }); - } + } // TODO set lable to getunreadmessages return value }); }); @@ -143,8 +143,9 @@ public final class ChatScene implements Restorable { eventBus.register(UserStatusChange.class, e -> userList.getItems() .stream() - .filter(c -> c.getID() == e.getID()) + .filter(c -> c.getRecipient().getID() == e.getID()) .findAny() + .map(u -> u.getRecipient()) .ifPresent(u -> { ((User) u).setStatus(e.get()); Platform.runLater(userList::refresh); })); // Listen to contacts changes @@ -153,13 +154,14 @@ public final class ChatScene implements Restorable { switch (e.getOperationType()) { case ADD: localDB.getUsers().put(contact.getName(), contact); - localDB.getChats().add(contact instanceof User ? new Chat(contact) : new GroupChat(client.getSender(), contact)); - Platform.runLater(() -> userList.getItems().add(contact)); + Chat chat = contact instanceof User ? new Chat(contact) : new GroupChat(client.getSender(), contact); + localDB.getChats().add(chat); + Platform.runLater(() -> userList.getItems().add(chat)); break; case REMOVE: localDB.getUsers().remove(contact.getName()); localDB.getChats().removeIf(c -> c.getRecipient().getID() == contact.getID()); - Platform.runLater(() -> userList.getItems().removeIf(c -> c.getID() == contact.getID())); + Platform.runLater(() -> userList.getItems().removeIf(c -> c.getRecipient().getID() == contact.getID())); break; } }); @@ -181,7 +183,7 @@ public final class ChatScene implements Restorable { this.client = client; this.writeProxy = writeProxy; - userList.setItems(FXCollections.observableList(localDB.getChats().stream().map(Chat::getRecipient).collect(Collectors.toList()))); + userList.setItems(FXCollections.observableList(localDB.getChats().stream().collect(Collectors.toList()))); contactLabel.setText(localDB.getUser().getName()); MessageControl.setUser(localDB.getUser()); if (!client.isOnline()) updateInfoLabel("You are offline", "infoLabel-info"); @@ -199,7 +201,7 @@ public final class ChatScene implements Restorable { */ @FXML private void userListClicked() { - final Contact user = userList.getSelectionModel().getSelectedItem(); + final Contact user = userList.getSelectionModel().getSelectedItem().getRecipient(); if (user != null && (currentChat == null || !user.equals(currentChat.getRecipient()))) { // LEON: JFC <===> JAVA FRIED CHICKEN <=/=> Java Foundation Classes diff --git a/src/main/java/envoy/client/ui/controller/ContactSearchScene.java b/src/main/java/envoy/client/ui/controller/ContactSearchScene.java index 4fe48d2..f7ac941 100644 --- a/src/main/java/envoy/client/ui/controller/ContactSearchScene.java +++ b/src/main/java/envoy/client/ui/controller/ContactSearchScene.java @@ -1,5 +1,7 @@ package envoy.client.ui.controller; +import java.util.ArrayList; +import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -10,12 +12,12 @@ import javafx.scene.control.Alert.AlertType; import javafx.scene.control.ButtonType; import javafx.scene.control.ListView; +import envoy.client.data.Chat; import envoy.client.data.LocalDB; import envoy.client.event.SendEvent; import envoy.client.ui.ClearableTextField; import envoy.client.ui.SceneContext; import envoy.client.ui.listcell.ContactListCellFactory; -import envoy.data.Contact; import envoy.event.ElementOperation; import envoy.event.EventBus; import envoy.event.contact.ContactOperation; @@ -37,7 +39,7 @@ public class ContactSearchScene { private ClearableTextField searchBar; @FXML - private ListView contactList; + private ListView contactList; private SceneContext sceneContext; @@ -61,7 +63,12 @@ public class ContactSearchScene { contactList.setCellFactory(ContactListCellFactory::new); searchBar.setClearButtonListener(e -> { searchBar.getTextField().clear(); contactList.getItems().clear(); }); eventBus.register(ContactSearchResult.class, - response -> Platform.runLater(() -> { contactList.getItems().clear(); contactList.getItems().addAll(response.get()); })); + response -> Platform.runLater(() -> { + List chats = new ArrayList(); + response.get().stream().forEach(r -> chats.add(new Chat(r))); + contactList.getItems().clear(); + contactList.getItems().addAll(chats); + })); } /** @@ -96,21 +103,21 @@ public class ContactSearchScene { */ @FXML private void contactListClicked() { - final var contact = contactList.getSelectionModel().getSelectedItem(); - if (contact != null) { + final var chat = contactList.getSelectionModel().getSelectedItem(); + if (chat != null) { final var alert = new Alert(AlertType.CONFIRMATION); alert.setTitle("Add Contact to Contact List"); - alert.setHeaderText("Add the user " + contact.getName() + " to your contact list?"); + alert.setHeaderText("Add the user " + chat.getRecipient().getName() + " to your contact list?"); // Normally, this would be total BS (we are already on the FX Thread), however // it could be proven that the creation of this dialog wrapped in // Platform.runLater is less error-prone than without it Platform.runLater(() -> alert.showAndWait().filter(btn -> btn == ButtonType.OK).ifPresent(btn -> { - final var event = new ContactOperation(contact, ElementOperation.ADD); + final var event = new ContactOperation(chat.getRecipient(), ElementOperation.ADD); // Sends the event to the server eventBus.dispatch(new SendEvent(event)); // Updates the UI eventBus.dispatch(event); - logger.log(Level.INFO, "Added contact " + contact); + logger.log(Level.INFO, "Added contact " + chat); })); } } diff --git a/src/main/java/envoy/client/ui/controller/GroupCreationScene.java b/src/main/java/envoy/client/ui/controller/GroupCreationScene.java index 76573b8..da88370 100644 --- a/src/main/java/envoy/client/ui/controller/GroupCreationScene.java +++ b/src/main/java/envoy/client/ui/controller/GroupCreationScene.java @@ -7,12 +7,13 @@ import javafx.fxml.FXML; import javafx.scene.control.*; import javafx.scene.control.Alert.AlertType; +import envoy.client.data.Chat; import envoy.client.data.LocalDB; import envoy.client.event.SendEvent; import envoy.client.ui.ClearableTextField; import envoy.client.ui.SceneContext; import envoy.client.ui.listcell.ContactListCellFactory; -import envoy.data.Contact; +import envoy.data.Group; import envoy.event.EventBus; import envoy.event.GroupCreation; import envoy.util.Bounds; @@ -34,7 +35,7 @@ public class GroupCreationScene { private ClearableTextField groupNameField; @FXML - private ListView contactList; + private ListView contactList; private SceneContext sceneContext; @@ -56,7 +57,11 @@ public class GroupCreationScene { public void initializeData(SceneContext sceneContext, LocalDB localDB) { this.sceneContext = sceneContext; Platform.runLater(() -> contactList.getItems() - .addAll(localDB.getUsers().values().stream().filter(c -> c.getID() != localDB.getUser().getID()).collect(Collectors.toList()))); + .addAll(localDB.getChats() + .stream() + .filter(c -> !(c.getRecipient() instanceof Group)) + .filter(c -> c.getRecipient().getID() != localDB.getUser().getID()) + .collect(Collectors.toList()))); } /** @@ -93,7 +98,7 @@ public class GroupCreationScene { groupNameField.getTextField().clear(); } else { eventBus.dispatch(new SendEvent(new GroupCreation(name, - contactList.getSelectionModel().getSelectedItems().stream().map(Contact::getID).collect(Collectors.toSet())))); + contactList.getSelectionModel().getSelectedItems().stream().map(c -> c.getRecipient().getID()).collect(Collectors.toSet())))); new Alert(AlertType.INFORMATION, String.format("Group '%s' successfully created.", name)).showAndWait(); sceneContext.pop(); } diff --git a/src/main/java/envoy/client/ui/listcell/ContactControl.java b/src/main/java/envoy/client/ui/listcell/ContactControl.java index 2a802fc..077068c 100644 --- a/src/main/java/envoy/client/ui/listcell/ContactControl.java +++ b/src/main/java/envoy/client/ui/listcell/ContactControl.java @@ -36,5 +36,8 @@ public class ContactControl extends VBox { getChildren().add(statusLabel); } else // Member count getChildren().add(new Label(((Group) contact).getContacts().size() + " members")); + + final var unreadMessagesLabel = new Label("5"); + getChildren().add(unreadMessagesLabel); } } diff --git a/src/main/java/envoy/client/ui/listcell/ContactListCellFactory.java b/src/main/java/envoy/client/ui/listcell/ContactListCellFactory.java index 8f8d3f0..fd0b1b9 100644 --- a/src/main/java/envoy/client/ui/listcell/ContactListCellFactory.java +++ b/src/main/java/envoy/client/ui/listcell/ContactListCellFactory.java @@ -3,7 +3,7 @@ package envoy.client.ui.listcell; import javafx.scene.control.ListCell; import javafx.scene.control.ListView; -import envoy.data.Contact; +import envoy.client.data.Chat; /** * Project: envoy-client
@@ -13,15 +13,15 @@ import envoy.data.Contact; * @author Kai S. K. Engelbart * @since Envoy Client v0.1-beta */ -public class ContactListCellFactory extends ListCell { +public class ContactListCellFactory extends ListCell { - private final ListView listView; + private final ListView listView; /** * @param listView the list view inside which this cell is contained * @since Envoy Client v0.1-beta */ - public ContactListCellFactory(ListView listView) { this.listView = listView; } + public ContactListCellFactory(ListView listView) { this.listView = listView; } /** * Displays the name of a contact. If the contact is a user, their online status @@ -30,13 +30,13 @@ public class ContactListCellFactory extends ListCell { * @since Envoy Client v0.1-beta */ @Override - protected void updateItem(Contact contact, boolean empty) { - super.updateItem(contact, empty); - if (empty || contact == null) { + protected void updateItem(Chat chat, boolean empty) { + super.updateItem(chat, empty); + if (empty || chat.getRecipient() == null) { setText(null); setGraphic(null); } else { - final var control = new ContactControl(contact); + final var control = new ContactControl(chat.getRecipient()); prefWidthProperty().bind(listView.widthProperty().subtract(40)); setGraphic(control); } From 6cb9c41ea00bd43c3899d98544b9feb776137d18 Mon Sep 17 00:00:00 2001 From: DieGurke <55625494+DieGurke@users.noreply.github.com> Date: Fri, 10 Jul 2020 23:25:55 +0200 Subject: [PATCH 02/14] UnreadMessagesAmount gets displayed correctly now (despite refresh bug) --- src/main/java/envoy/client/data/Chat.java | 2 +- src/main/java/envoy/client/data/GroupChat.java | 10 ++++++++++ .../java/envoy/client/ui/controller/ChatScene.java | 4 +++- .../java/envoy/client/ui/listcell/ContactControl.java | 4 ++-- .../client/ui/listcell/ContactListCellFactory.java | 5 ++++- 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/main/java/envoy/client/data/Chat.java b/src/main/java/envoy/client/data/Chat.java index 68d55fd..69f5d5e 100644 --- a/src/main/java/envoy/client/data/Chat.java +++ b/src/main/java/envoy/client/data/Chat.java @@ -114,7 +114,7 @@ public class Chat implements Serializable { public int getUnreadAmount() { int unreadMessagesAmount = 0; for (int i = messages.size() - 1; i >= 0; i--) { - if (messages.get(i).getStatus() == MessageStatus.RECEIVED) unreadMessagesAmount++; + if (messages.get(i).getSenderID() == recipient.getID() && messages.get(i).getStatus() == MessageStatus.RECEIVED) unreadMessagesAmount++; else break; } return unreadMessagesAmount; diff --git a/src/main/java/envoy/client/data/GroupChat.java b/src/main/java/envoy/client/data/GroupChat.java index 3c1e98d..d664124 100644 --- a/src/main/java/envoy/client/data/GroupChat.java +++ b/src/main/java/envoy/client/data/GroupChat.java @@ -37,6 +37,16 @@ public class GroupChat extends Chat { this.sender = sender; } + @Override + public int getUnreadAmount() { + int unreadMessagesAmount = 0; + for (int i = messages.size() - 1; i >= 0; i--) { + if (messages.get(i).getSenderID() != sender.getID() && messages.get(i).getStatus() == MessageStatus.RECEIVED) unreadMessagesAmount++; + else break; + } + return unreadMessagesAmount; + } + @Override public void read(WriteProxy writeProxy) throws IOException { for (int i = messages.size() - 1; i >= 0; --i) { diff --git a/src/main/java/envoy/client/ui/controller/ChatScene.java b/src/main/java/envoy/client/ui/controller/ChatScene.java index d3940eb..36f4a7f 100644 --- a/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -121,7 +121,8 @@ public final class ChatScene implements Restorable { logger.log(Level.WARNING, "Could not read current chat: ", e1); } Platform.runLater(() -> { messageList.refresh(); scrollToMessageListEnd(); }); - } // TODO set lable to getunreadmessages return value + } + userList.refresh(); }); }); @@ -236,6 +237,7 @@ public final class ChatScene implements Restorable { } messageTextArea.setDisable(currentChat == null || postingPermanentlyDisabled); voiceButton.setDisable(!recorder.isSupported()); + userList.refresh(); } /** diff --git a/src/main/java/envoy/client/ui/listcell/ContactControl.java b/src/main/java/envoy/client/ui/listcell/ContactControl.java index 077068c..b13b51e 100644 --- a/src/main/java/envoy/client/ui/listcell/ContactControl.java +++ b/src/main/java/envoy/client/ui/listcell/ContactControl.java @@ -23,7 +23,7 @@ public class ContactControl extends VBox { * @param contact the contact that should be formatted * @since Envoy Client v0.1-beta */ - public ContactControl(Contact contact) { + public ContactControl(Contact contact, int unreadMessagesAmount) { // Container with contact name final var nameLabel = new Label(contact.getName()); nameLabel.setWrapText(true); @@ -37,7 +37,7 @@ public class ContactControl extends VBox { } else // Member count getChildren().add(new Label(((Group) contact).getContacts().size() + " members")); - final var unreadMessagesLabel = new Label("5"); + final var unreadMessagesLabel = new Label("" + unreadMessagesAmount); getChildren().add(unreadMessagesLabel); } } diff --git a/src/main/java/envoy/client/ui/listcell/ContactListCellFactory.java b/src/main/java/envoy/client/ui/listcell/ContactListCellFactory.java index fd0b1b9..117a8b4 100644 --- a/src/main/java/envoy/client/ui/listcell/ContactListCellFactory.java +++ b/src/main/java/envoy/client/ui/listcell/ContactListCellFactory.java @@ -16,6 +16,7 @@ import envoy.client.data.Chat; public class ContactListCellFactory extends ListCell { private final ListView listView; + private Boolean displayUnreadMessagesAmount = false; /** * @param listView the list view inside which this cell is contained @@ -23,6 +24,8 @@ public class ContactListCellFactory extends ListCell { */ public ContactListCellFactory(ListView listView) { this.listView = listView; } + public void displayUnreadMessagesAmount() { displayUnreadMessagesAmount = true; } + /** * Displays the name of a contact. If the contact is a user, their online status * is displayed as well. @@ -36,7 +39,7 @@ public class ContactListCellFactory extends ListCell { setText(null); setGraphic(null); } else { - final var control = new ContactControl(chat.getRecipient()); + final var control = new ContactControl(chat.getRecipient(), chat.getUnreadAmount()); prefWidthProperty().bind(listView.widthProperty().subtract(40)); setGraphic(control); } From 022b516ceb1b7ddde61d2598efb85b169475d8f5 Mon Sep 17 00:00:00 2001 From: DieGurke <55625494+DieGurke@users.noreply.github.com> Date: Sat, 11 Jul 2020 10:40:42 +0200 Subject: [PATCH 03/14] Implemented nice UI --- .../{ContactControl.java => ChatControl.java} | 28 +++++++++++++------ .../ui/listcell/ContactListCellFactory.java | 5 +--- src/main/resources/css/base.css | 7 +++++ 3 files changed, 28 insertions(+), 12 deletions(-) rename src/main/java/envoy/client/ui/listcell/{ContactControl.java => ChatControl.java} (55%) diff --git a/src/main/java/envoy/client/ui/listcell/ContactControl.java b/src/main/java/envoy/client/ui/listcell/ChatControl.java similarity index 55% rename from src/main/java/envoy/client/ui/listcell/ContactControl.java rename to src/main/java/envoy/client/ui/listcell/ChatControl.java index b13b51e..444d3e5 100644 --- a/src/main/java/envoy/client/ui/listcell/ContactControl.java +++ b/src/main/java/envoy/client/ui/listcell/ChatControl.java @@ -1,7 +1,8 @@ package envoy.client.ui.listcell; +import javafx.geometry.Pos; import javafx.scene.control.Label; -import javafx.scene.layout.VBox; +import javafx.scene.layout.*; import envoy.data.Contact; import envoy.data.Group; @@ -17,27 +18,38 @@ import envoy.data.User; * @author Leon Hofmeister * @since Envoy Client v0.1-beta */ -public class ContactControl extends VBox { +public class ChatControl extends HBox { /** * @param contact the contact that should be formatted * @since Envoy Client v0.1-beta */ - public ContactControl(Contact contact, int unreadMessagesAmount) { + public ChatControl(Contact contact, int unreadMessagesAmount) { // Container with contact name + final var vBox = new VBox(); final var nameLabel = new Label(contact.getName()); nameLabel.setWrapText(true); - getChildren().add(nameLabel); + vBox.getChildren().add(nameLabel); if (contact instanceof User) { // Online status final var user = (User) contact; final var statusLabel = new Label(user.getStatus().toString()); statusLabel.getStyleClass().add(user.getStatus().toString().toLowerCase()); - getChildren().add(statusLabel); + vBox.getChildren().add(statusLabel); } else // Member count - getChildren().add(new Label(((Group) contact).getContacts().size() + " members")); - + vBox.getChildren().add(new Label(((Group) contact).getContacts().size() + " members")); + + getChildren().add(vBox); + Region spacing = new Region(); + setHgrow(spacing, Priority.ALWAYS); + getChildren().add(spacing); final var unreadMessagesLabel = new Label("" + unreadMessagesAmount); - getChildren().add(unreadMessagesLabel); + unreadMessagesLabel.setMinSize(15, 15); + var vBox2 = new VBox(); + vBox2.setAlignment(Pos.CENTER_RIGHT); + unreadMessagesLabel.setAlignment(Pos.CENTER); + unreadMessagesLabel.getStyleClass().add("unreadMessagesAmount"); + vBox2.getChildren().add(unreadMessagesLabel); + getChildren().add(vBox2); } } diff --git a/src/main/java/envoy/client/ui/listcell/ContactListCellFactory.java b/src/main/java/envoy/client/ui/listcell/ContactListCellFactory.java index 117a8b4..9379bfe 100644 --- a/src/main/java/envoy/client/ui/listcell/ContactListCellFactory.java +++ b/src/main/java/envoy/client/ui/listcell/ContactListCellFactory.java @@ -16,7 +16,6 @@ import envoy.client.data.Chat; public class ContactListCellFactory extends ListCell { private final ListView listView; - private Boolean displayUnreadMessagesAmount = false; /** * @param listView the list view inside which this cell is contained @@ -24,8 +23,6 @@ public class ContactListCellFactory extends ListCell { */ public ContactListCellFactory(ListView listView) { this.listView = listView; } - public void displayUnreadMessagesAmount() { displayUnreadMessagesAmount = true; } - /** * Displays the name of a contact. If the contact is a user, their online status * is displayed as well. @@ -39,7 +36,7 @@ public class ContactListCellFactory extends ListCell { setText(null); setGraphic(null); } else { - final var control = new ContactControl(chat.getRecipient(), chat.getUnreadAmount()); + final var control = new ChatControl(chat.getRecipient(), chat.getUnreadAmount()); prefWidthProperty().bind(listView.widthProperty().subtract(40)); setGraphic(control); } diff --git a/src/main/resources/css/base.css b/src/main/resources/css/base.css index 2830bc6..78fff9e 100644 --- a/src/main/resources/css/base.css +++ b/src/main/resources/css/base.css @@ -58,6 +58,13 @@ -fx-text-alignment: left; } +.unreadMessagesAmount { + -fx-alignment: center; + -fx-background-color: orange; + -fx-background-radius: 4.0em; + -fx-text-alignment: center; +} + #remainingCharsLabel { -fx-text-fill: #00FF00; -fx-background-color: transparent; From d1368d43c827f5be6cdf513ac53384f6c0b83842 Mon Sep 17 00:00:00 2001 From: DieGurke <55625494+DieGurke@users.noreply.github.com> Date: Sat, 11 Jul 2020 10:46:17 +0200 Subject: [PATCH 04/14] UI isn't shown if there arn't any unread messages --- .../envoy/client/ui/listcell/ChatControl.java | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/main/java/envoy/client/ui/listcell/ChatControl.java b/src/main/java/envoy/client/ui/listcell/ChatControl.java index 444d3e5..68e3548 100644 --- a/src/main/java/envoy/client/ui/listcell/ChatControl.java +++ b/src/main/java/envoy/client/ui/listcell/ChatControl.java @@ -40,16 +40,18 @@ public class ChatControl extends HBox { vBox.getChildren().add(new Label(((Group) contact).getContacts().size() + " members")); getChildren().add(vBox); - Region spacing = new Region(); - setHgrow(spacing, Priority.ALWAYS); - getChildren().add(spacing); - final var unreadMessagesLabel = new Label("" + unreadMessagesAmount); - unreadMessagesLabel.setMinSize(15, 15); - var vBox2 = new VBox(); - vBox2.setAlignment(Pos.CENTER_RIGHT); - unreadMessagesLabel.setAlignment(Pos.CENTER); - unreadMessagesLabel.getStyleClass().add("unreadMessagesAmount"); - vBox2.getChildren().add(unreadMessagesLabel); - getChildren().add(vBox2); + if (unreadMessagesAmount != 0) { + Region spacing = new Region(); + setHgrow(spacing, Priority.ALWAYS); + getChildren().add(spacing); + final var unreadMessagesLabel = new Label("" + unreadMessagesAmount); + unreadMessagesLabel.setMinSize(15, 15); + var vBox2 = new VBox(); + vBox2.setAlignment(Pos.CENTER_RIGHT); + unreadMessagesLabel.setAlignment(Pos.CENTER); + unreadMessagesLabel.getStyleClass().add("unreadMessagesAmount"); + vBox2.getChildren().add(unreadMessagesLabel); + getChildren().add(vBox2); + } } } From 5caa5381b05847b569f3ff38af47b86b879c38b0 Mon Sep 17 00:00:00 2001 From: DieGurke <55625494+DieGurke@users.noreply.github.com> Date: Sat, 11 Jul 2020 14:18:38 +0200 Subject: [PATCH 05/14] chats with most recent messages get moved to the top --- .../envoy/client/ui/controller/ChatScene.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/envoy/client/ui/controller/ChatScene.java b/src/main/java/envoy/client/ui/controller/ChatScene.java index 4175f17..1c626b2 100644 --- a/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -135,6 +135,13 @@ public final class ChatScene implements Restorable { } Platform.runLater(() -> { messageList.refresh(); scrollToMessageListEnd(); }); } + // Moving chat with most recent unreadMessages to the top + Platform.runLater(() -> { + userList.getItems().remove(chat); + userList.getItems().add(0, chat); + localDB.getChats().remove(chat); + localDB.getChats().add(0, chat); + }); userList.refresh(); }); }); @@ -453,6 +460,14 @@ public final class ChatScene implements Restorable { // Add message to LocalDB and update UI currentChat.insert(message); + // Moving currentChat to the top + Platform.runLater(() -> { + userList.getItems().remove(currentChat); + userList.getItems().add(0, currentChat); + userList.getSelectionModel().select(0); + localDB.getChats().remove(currentChat); + localDB.getChats().add(0, currentChat); + }); messageList.refresh(); scrollToMessageListEnd(); From 9111880dcf4ecb9672d70fe0f16ea240127a7b12 Mon Sep 17 00:00:00 2001 From: DieGurke <55625494+DieGurke@users.noreply.github.com> Date: Sat, 11 Jul 2020 14:46:13 +0200 Subject: [PATCH 06/14] Little Bug Fix --- src/main/java/envoy/client/ui/controller/ChatScene.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/envoy/client/ui/controller/ChatScene.java b/src/main/java/envoy/client/ui/controller/ChatScene.java index 1c626b2..b2ae0ef 100644 --- a/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -139,6 +139,7 @@ public final class ChatScene implements Restorable { Platform.runLater(() -> { userList.getItems().remove(chat); userList.getItems().add(0, chat); + if (chat.equals(currentChat)) userList.getSelectionModel().select(0); localDB.getChats().remove(chat); localDB.getChats().add(0, chat); }); From b5e83272a6d4f074e336fcc66e82df18722e22b9 Mon Sep 17 00:00:00 2001 From: DieGurke <55625494+DieGurke@users.noreply.github.com> Date: Sat, 11 Jul 2020 14:57:15 +0200 Subject: [PATCH 07/14] When opening a chat holding unread messages, it scrolls to the first one --- src/main/java/envoy/client/ui/controller/ChatScene.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/envoy/client/ui/controller/ChatScene.java b/src/main/java/envoy/client/ui/controller/ChatScene.java index b2ae0ef..1d2a974 100644 --- a/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -232,7 +232,7 @@ public final class ChatScene implements Restorable { currentChat = localDB.getChat(user.getID()).get(); messageList.setItems(FXCollections.observableList(currentChat.getMessages())); - final var scrollIndex = messageList.getItems().size() - 1; + final var scrollIndex = messageList.getItems().size() - currentChat.getUnreadAmount() - 1; messageList.scrollTo(scrollIndex); logger.log(Level.FINEST, "Loading chat with " + user + " at index " + scrollIndex); deleteContactMenuItem.setText("Delete " + user.getName()); From d8eb2d6f6ec68ef2a02f1c25e9991bd42c875a32 Mon Sep 17 00:00:00 2001 From: DieGurke <55625494+DieGurke@users.noreply.github.com> Date: Sun, 12 Jul 2020 13:07:46 +0200 Subject: [PATCH 08/14] Implemented some suggestions made by @delvh --- .../java/envoy/client/ui/controller/ChatScene.java | 2 +- .../client/ui/controller/ContactSearchScene.java | 9 +++------ .../java/envoy/client/ui/listcell/ChatControl.java | 11 ++++++----- .../client/ui/listcell/ContactListCellFactory.java | 2 +- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/main/java/envoy/client/ui/controller/ChatScene.java b/src/main/java/envoy/client/ui/controller/ChatScene.java index 1d2a974..ef88dea 100644 --- a/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -140,10 +140,10 @@ public final class ChatScene implements Restorable { userList.getItems().remove(chat); userList.getItems().add(0, chat); if (chat.equals(currentChat)) userList.getSelectionModel().select(0); + userList.refresh(); localDB.getChats().remove(chat); localDB.getChats().add(0, chat); }); - userList.refresh(); }); }); diff --git a/src/main/java/envoy/client/ui/controller/ContactSearchScene.java b/src/main/java/envoy/client/ui/controller/ContactSearchScene.java index f7ac941..d440ee4 100644 --- a/src/main/java/envoy/client/ui/controller/ContactSearchScene.java +++ b/src/main/java/envoy/client/ui/controller/ContactSearchScene.java @@ -1,9 +1,8 @@ package envoy.client.ui.controller; -import java.util.ArrayList; -import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.stream.Collectors; import javafx.application.Platform; import javafx.fxml.FXML; @@ -64,10 +63,8 @@ public class ContactSearchScene { searchBar.setClearButtonListener(e -> { searchBar.getTextField().clear(); contactList.getItems().clear(); }); eventBus.register(ContactSearchResult.class, response -> Platform.runLater(() -> { - List chats = new ArrayList(); - response.get().stream().forEach(r -> chats.add(new Chat(r))); contactList.getItems().clear(); - contactList.getItems().addAll(chats); + contactList.getItems().addAll(response.get().stream().map(Chat::new).collect(Collectors.toList())); })); } @@ -117,7 +114,7 @@ public class ContactSearchScene { eventBus.dispatch(new SendEvent(event)); // Updates the UI eventBus.dispatch(event); - logger.log(Level.INFO, "Added contact " + chat); + logger.log(Level.INFO, "Added contact " + chat.getRecipient()); })); } } diff --git a/src/main/java/envoy/client/ui/listcell/ChatControl.java b/src/main/java/envoy/client/ui/listcell/ChatControl.java index 68e3548..5a8b9bc 100644 --- a/src/main/java/envoy/client/ui/listcell/ChatControl.java +++ b/src/main/java/envoy/client/ui/listcell/ChatControl.java @@ -4,6 +4,7 @@ import javafx.geometry.Pos; import javafx.scene.control.Label; import javafx.scene.layout.*; +import envoy.client.data.Chat; import envoy.data.Contact; import envoy.data.Group; import envoy.data.User; @@ -24,20 +25,20 @@ public class ChatControl extends HBox { * @param contact the contact that should be formatted * @since Envoy Client v0.1-beta */ - public ChatControl(Contact contact, int unreadMessagesAmount) { + public ChatControl(Chat chat, int unreadMessagesAmount) { // Container with contact name final var vBox = new VBox(); - final var nameLabel = new Label(contact.getName()); + final var nameLabel = new Label(chat.getRecipient().getName()); nameLabel.setWrapText(true); vBox.getChildren().add(nameLabel); - if (contact instanceof User) { + if (chat.getRecipient() instanceof User) { // Online status - final var user = (User) contact; + final var user = (User) chat.getRecipient(); final var statusLabel = new Label(user.getStatus().toString()); statusLabel.getStyleClass().add(user.getStatus().toString().toLowerCase()); vBox.getChildren().add(statusLabel); } else // Member count - vBox.getChildren().add(new Label(((Group) contact).getContacts().size() + " members")); + vBox.getChildren().add(new Label(((Group) chat.getRecipient()).getContacts().size() + " members")); getChildren().add(vBox); if (unreadMessagesAmount != 0) { diff --git a/src/main/java/envoy/client/ui/listcell/ContactListCellFactory.java b/src/main/java/envoy/client/ui/listcell/ContactListCellFactory.java index 9379bfe..acf116f 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.getRecipient(), chat.getUnreadAmount()); + final var control = new ChatControl(chat, chat.getUnreadAmount()); prefWidthProperty().bind(listView.widthProperty().subtract(40)); setGraphic(control); } From d2ec04b568772cf091044dda4c8d5b63dbd4e863 Mon Sep 17 00:00:00 2001 From: DieGurke <55625494+DieGurke@users.noreply.github.com> Date: Sun, 12 Jul 2020 14:34:07 +0200 Subject: [PATCH 09/14] Implemented good suggestion by @delvh regarding performance increase --- src/main/java/envoy/client/data/Chat.java | 14 ++++++-------- src/main/java/envoy/client/data/GroupChat.java | 11 +---------- .../java/envoy/client/ui/controller/ChatScene.java | 2 +- 3 files changed, 8 insertions(+), 19 deletions(-) diff --git a/src/main/java/envoy/client/data/Chat.java b/src/main/java/envoy/client/data/Chat.java index 69f5d5e..b08fb25 100644 --- a/src/main/java/envoy/client/data/Chat.java +++ b/src/main/java/envoy/client/data/Chat.java @@ -29,6 +29,8 @@ public class Chat implements Serializable { protected final Contact recipient; protected final List messages = new ArrayList<>(); + protected int unreadAmount; + private static final long serialVersionUID = 1L; /** @@ -87,6 +89,7 @@ public class Chat implements Serializable { writeProxy.writeMessageStatusChange(new MessageStatusChange(m)); } } + unreadAmount = 0; } /** @@ -111,14 +114,9 @@ public class Chat implements Serializable { messages.add(0, message); } - public int getUnreadAmount() { - int unreadMessagesAmount = 0; - for (int i = messages.size() - 1; i >= 0; i--) { - if (messages.get(i).getSenderID() == recipient.getID() && messages.get(i).getStatus() == MessageStatus.RECEIVED) unreadMessagesAmount++; - else break; - } - return unreadMessagesAmount; - } + public void incrementUnreadAmount() { unreadAmount++; } + + public int getUnreadAmount() { return unreadAmount; } /** * @return all messages in the current chat diff --git a/src/main/java/envoy/client/data/GroupChat.java b/src/main/java/envoy/client/data/GroupChat.java index d664124..1bdbde3 100644 --- a/src/main/java/envoy/client/data/GroupChat.java +++ b/src/main/java/envoy/client/data/GroupChat.java @@ -37,16 +37,6 @@ public class GroupChat extends Chat { this.sender = sender; } - @Override - public int getUnreadAmount() { - int unreadMessagesAmount = 0; - for (int i = messages.size() - 1; i >= 0; i--) { - if (messages.get(i).getSenderID() != sender.getID() && messages.get(i).getStatus() == MessageStatus.RECEIVED) unreadMessagesAmount++; - else break; - } - return unreadMessagesAmount; - } - @Override public void read(WriteProxy writeProxy) throws IOException { for (int i = messages.size() - 1; i >= 0; --i) { @@ -60,5 +50,6 @@ public class GroupChat extends Chat { } } } + super.unreadAmount = 0; } } diff --git a/src/main/java/envoy/client/ui/controller/ChatScene.java b/src/main/java/envoy/client/ui/controller/ChatScene.java index ef88dea..851833e 100644 --- a/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -134,7 +134,7 @@ public final class ChatScene implements Restorable { logger.log(Level.WARNING, "Could not read current chat: ", e1); } Platform.runLater(() -> { messageList.refresh(); scrollToMessageListEnd(); }); - } + } else chat.incrementUnreadAmount(); // Moving chat with most recent unreadMessages to the top Platform.runLater(() -> { userList.getItems().remove(chat); 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 10/14] 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); } From 52766a37cec18fee7cde601fee70c9b8ab627559 Mon Sep 17 00:00:00 2001 From: DieGurke <55625494+DieGurke@users.noreply.github.com> Date: Sun, 12 Jul 2020 14:54:07 +0200 Subject: [PATCH 11/14] Removed unnecessary userList refreshing --- src/main/java/envoy/client/ui/controller/ChatScene.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/envoy/client/ui/controller/ChatScene.java b/src/main/java/envoy/client/ui/controller/ChatScene.java index 851833e..703ec5d 100644 --- a/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -140,7 +140,6 @@ public final class ChatScene implements Restorable { userList.getItems().remove(chat); userList.getItems().add(0, chat); if (chat.equals(currentChat)) userList.getSelectionModel().select(0); - userList.refresh(); localDB.getChats().remove(chat); localDB.getChats().add(0, chat); }); From fb4c58f9ff3da1a7afec17b025d948f7e24998a3 Mon Sep 17 00:00:00 2001 From: DieGurke <55625494+DieGurke@users.noreply.github.com> Date: Sun, 12 Jul 2020 16:27:20 +0200 Subject: [PATCH 12/14] Apply suggestions from code review Co-authored-by: CyB3RC0nN0R --- src/main/java/envoy/client/data/Chat.java | 4 ++-- src/main/java/envoy/client/data/GroupChat.java | 3 ++- src/main/java/envoy/client/ui/controller/ChatScene.java | 7 +++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/envoy/client/data/Chat.java b/src/main/java/envoy/client/data/Chat.java index c1b8f37..b1c2beb 100644 --- a/src/main/java/envoy/client/data/Chat.java +++ b/src/main/java/envoy/client/data/Chat.java @@ -115,14 +115,14 @@ public class Chat implements Serializable { } /** - * Increments the unreadMessagesAmount by 1 + * Increments the amount of unread messages. * * @since Envoy Client v0.1-beta */ public void incrementUnreadAmount() { unreadAmount++; } /** - * @return the amount of unreadMesages in this chat + * @return the amount of unread mesages in this chat * @since Envoy Client v0.1-beta */ public int getUnreadAmount() { return unreadAmount; } diff --git a/src/main/java/envoy/client/data/GroupChat.java b/src/main/java/envoy/client/data/GroupChat.java index 1bdbde3..76c0317 100644 --- a/src/main/java/envoy/client/data/GroupChat.java +++ b/src/main/java/envoy/client/data/GroupChat.java @@ -50,6 +50,7 @@ public class GroupChat extends Chat { } } } - super.unreadAmount = 0; + unreadAmount = 0; + } } diff --git a/src/main/java/envoy/client/ui/controller/ChatScene.java b/src/main/java/envoy/client/ui/controller/ChatScene.java index 703ec5d..a91436b 100644 --- a/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -166,7 +166,7 @@ public final class ChatScene implements Restorable { .stream() .filter(c -> c.getRecipient().getID() == e.getID()) .findAny() - .map(u -> u.getRecipient()) + .map(Chat::getRecipient) .ifPresent(u -> { ((User) u).setStatus(e.get()); Platform.runLater(userList::refresh); })); // Listen to contacts changes @@ -204,7 +204,7 @@ public final class ChatScene implements Restorable { this.client = client; this.writeProxy = writeProxy; - userList.setItems(FXCollections.observableList(localDB.getChats().stream().collect(Collectors.toList()))); + userList.setItems(FXCollections.observableList(localDB.getChats())); contactLabel.setText(localDB.getUser().getName()); MessageControl.setUser(localDB.getUser()); if (!client.isOnline()) updateInfoLabel("You are offline", "infoLabel-info"); @@ -462,8 +462,7 @@ public final class ChatScene implements Restorable { currentChat.insert(message); // Moving currentChat to the top Platform.runLater(() -> { - userList.getItems().remove(currentChat); - userList.getItems().add(0, currentChat); + userList.getItems().add(0, userList.getItems().remove(currentChat)); userList.getSelectionModel().select(0); localDB.getChats().remove(currentChat); localDB.getChats().add(0, currentChat); From 5f410e5d65b7b59384a78627d1e8156afd6f3073 Mon Sep 17 00:00:00 2001 From: DieGurke <55625494+DieGurke@users.noreply.github.com> Date: Sun, 12 Jul 2020 17:10:22 +0200 Subject: [PATCH 13/14] Did some renaming --- .../envoy/client/ui/controller/ChatScene.java | 32 +++++++++---------- .../ui/controller/ContactSearchScene.java | 18 +++++------ .../ui/controller/GroupCreationScene.java | 14 ++++---- src/main/resources/fxml/ChatScene.fxml | 2 +- .../resources/fxml/ContactSearchScene.fxml | 4 +-- .../resources/fxml/GroupCreationScene.fxml | 4 +-- 6 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/main/java/envoy/client/ui/controller/ChatScene.java b/src/main/java/envoy/client/ui/controller/ChatScene.java index a91436b..3d789ef 100644 --- a/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -8,7 +8,6 @@ import java.io.IOException; import java.nio.file.Files; import java.util.logging.Level; import java.util.logging.Logger; -import java.util.stream.Collectors; import javafx.application.Platform; import javafx.collections.FXCollections; @@ -57,7 +56,7 @@ public final class ChatScene implements Restorable { private ListView messageList; @FXML - private ListView userList; + private ListView chatList; @FXML private Button postButton; @@ -115,7 +114,7 @@ public final class ChatScene implements Restorable { // Initialize message and user rendering messageList.setCellFactory(MessageListCellFactory::new); - userList.setCellFactory(ContactListCellFactory::new); + chatList.setCellFactory(ContactListCellFactory::new); settingsButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("settings", DEFAULT_ICON_SIZE))); voiceButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("microphone", DEFAULT_ICON_SIZE))); @@ -137,9 +136,9 @@ public final class ChatScene implements Restorable { } else chat.incrementUnreadAmount(); // Moving chat with most recent unreadMessages to the top Platform.runLater(() -> { - userList.getItems().remove(chat); - userList.getItems().add(0, chat); - if (chat.equals(currentChat)) userList.getSelectionModel().select(0); + chatList.getItems().remove(chat); + chatList.getItems().add(0, chat); + if (chat.equals(currentChat)) chatList.getSelectionModel().select(0); localDB.getChats().remove(chat); localDB.getChats().add(0, chat); }); @@ -162,12 +161,12 @@ public final class ChatScene implements Restorable { // Listen to user status changes eventBus.register(UserStatusChange.class, - e -> userList.getItems() + e -> chatList.getItems() .stream() .filter(c -> c.getRecipient().getID() == e.getID()) .findAny() .map(Chat::getRecipient) - .ifPresent(u -> { ((User) u).setStatus(e.get()); Platform.runLater(userList::refresh); })); + .ifPresent(u -> { ((User) u).setStatus(e.get()); Platform.runLater(chatList::refresh); })); // Listen to contacts changes eventBus.register(ContactOperation.class, e -> { @@ -177,12 +176,12 @@ public final class ChatScene implements Restorable { localDB.getUsers().put(contact.getName(), contact); Chat chat = contact instanceof User ? new Chat(contact) : new GroupChat(client.getSender(), contact); localDB.getChats().add(chat); - Platform.runLater(() -> userList.getItems().add(chat)); + Platform.runLater(() -> chatList.getItems().add(chat)); break; case REMOVE: localDB.getUsers().remove(contact.getName()); localDB.getChats().removeIf(c -> c.getRecipient().getID() == contact.getID()); - Platform.runLater(() -> userList.getItems().removeIf(c -> c.getRecipient().getID() == contact.getID())); + Platform.runLater(() -> chatList.getItems().removeIf(c -> c.getRecipient().getID() == contact.getID())); break; } }); @@ -204,7 +203,7 @@ public final class ChatScene implements Restorable { this.client = client; this.writeProxy = writeProxy; - userList.setItems(FXCollections.observableList(localDB.getChats())); + chatList.setItems(FXCollections.observableList(localDB.getChats())); contactLabel.setText(localDB.getUser().getName()); MessageControl.setUser(localDB.getUser()); if (!client.isOnline()) updateInfoLabel("You are offline", "infoLabel-info"); @@ -221,8 +220,8 @@ public final class ChatScene implements Restorable { * @since Envoy Client v0.1-beta */ @FXML - private void userListClicked() { - final Contact user = userList.getSelectionModel().getSelectedItem().getRecipient(); + private void chatListClicked() { + final Contact user = chatList.getSelectionModel().getSelectedItem().getRecipient(); if (user != null && (currentChat == null || !user.equals(currentChat.getRecipient()))) { // LEON: JFC <===> JAVA FRIED CHICKEN <=/=> Java Foundation Classes @@ -258,7 +257,7 @@ public final class ChatScene implements Restorable { messageTextArea.setDisable(currentChat == null || postingPermanentlyDisabled); voiceButton.setDisable(!recorder.isSupported()); attachmentButton.setDisable(false); - userList.refresh(); + chatList.refresh(); } /** @@ -462,8 +461,9 @@ public final class ChatScene implements Restorable { currentChat.insert(message); // Moving currentChat to the top Platform.runLater(() -> { - userList.getItems().add(0, userList.getItems().remove(currentChat)); - userList.getSelectionModel().select(0); + chatList.getItems().remove(currentChat); + chatList.getItems().add(0, currentChat); + chatList.getSelectionModel().select(0); localDB.getChats().remove(currentChat); localDB.getChats().add(0, currentChat); }); diff --git a/src/main/java/envoy/client/ui/controller/ContactSearchScene.java b/src/main/java/envoy/client/ui/controller/ContactSearchScene.java index d440ee4..a86d79d 100644 --- a/src/main/java/envoy/client/ui/controller/ContactSearchScene.java +++ b/src/main/java/envoy/client/ui/controller/ContactSearchScene.java @@ -38,7 +38,7 @@ public class ContactSearchScene { private ClearableTextField searchBar; @FXML - private ListView contactList; + private ListView chatList; private SceneContext sceneContext; @@ -59,12 +59,12 @@ public class ContactSearchScene { @FXML private void initialize() { - contactList.setCellFactory(ContactListCellFactory::new); - searchBar.setClearButtonListener(e -> { searchBar.getTextField().clear(); contactList.getItems().clear(); }); + chatList.setCellFactory(ContactListCellFactory::new); + searchBar.setClearButtonListener(e -> { searchBar.getTextField().clear(); chatList.getItems().clear(); }); eventBus.register(ContactSearchResult.class, response -> Platform.runLater(() -> { - contactList.getItems().clear(); - contactList.getItems().addAll(response.get().stream().map(Chat::new).collect(Collectors.toList())); + chatList.getItems().clear(); + chatList.getItems().addAll(response.get().stream().map(Chat::new).collect(Collectors.toList())); })); } @@ -77,7 +77,7 @@ public class ContactSearchScene { private void sendRequest() { final var text = searchBar.getTextField().getText().strip(); if (!text.isBlank()) eventBus.dispatch(new SendEvent(new ContactSearchRequest(text))); - else contactList.getItems().clear(); + else chatList.getItems().clear(); } /** @@ -89,7 +89,7 @@ public class ContactSearchScene { @FXML private void clear() { searchBar.getTextField().setText(null); - contactList.getItems().clear(); + chatList.getItems().clear(); } /** @@ -99,8 +99,8 @@ public class ContactSearchScene { * @since Envoy Client v0.1-beta */ @FXML - private void contactListClicked() { - final var chat = contactList.getSelectionModel().getSelectedItem(); + private void chatListClicked() { + final var chat = chatList.getSelectionModel().getSelectedItem(); if (chat != null) { final var alert = new Alert(AlertType.CONFIRMATION); alert.setTitle("Add Contact to Contact List"); diff --git a/src/main/java/envoy/client/ui/controller/GroupCreationScene.java b/src/main/java/envoy/client/ui/controller/GroupCreationScene.java index da88370..e7bbf93 100644 --- a/src/main/java/envoy/client/ui/controller/GroupCreationScene.java +++ b/src/main/java/envoy/client/ui/controller/GroupCreationScene.java @@ -35,7 +35,7 @@ public class GroupCreationScene { private ClearableTextField groupNameField; @FXML - private ListView contactList; + private ListView chatList; private SceneContext sceneContext; @@ -43,8 +43,8 @@ public class GroupCreationScene { @FXML private void initialize() { - contactList.setCellFactory(ContactListCellFactory::new); - contactList.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); + chatList.setCellFactory(ContactListCellFactory::new); + chatList.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); groupNameField.setClearButtonListener(e -> { groupNameField.getTextField().clear(); createButton.setDisable(true); }); } @@ -56,7 +56,7 @@ public class GroupCreationScene { */ public void initializeData(SceneContext sceneContext, LocalDB localDB) { this.sceneContext = sceneContext; - Platform.runLater(() -> contactList.getItems() + Platform.runLater(() -> chatList.getItems() .addAll(localDB.getChats() .stream() .filter(c -> !(c.getRecipient() instanceof Group)) @@ -70,8 +70,8 @@ public class GroupCreationScene { * @since Envoy Client v0.1-beta */ @FXML - private void contactListClicked() { - createButton.setDisable(contactList.getSelectionModel().isEmpty() || groupNameField.getTextField().getText().isBlank()); + private void chatListClicked() { + createButton.setDisable(chatList.getSelectionModel().isEmpty() || groupNameField.getTextField().getText().isBlank()); } /** @@ -98,7 +98,7 @@ public class GroupCreationScene { groupNameField.getTextField().clear(); } else { eventBus.dispatch(new SendEvent(new GroupCreation(name, - contactList.getSelectionModel().getSelectedItems().stream().map(c -> c.getRecipient().getID()).collect(Collectors.toSet())))); + chatList.getSelectionModel().getSelectedItems().stream().map(c -> c.getRecipient().getID()).collect(Collectors.toSet())))); new Alert(AlertType.INFORMATION, String.format("Group '%s' successfully created.", name)).showAndWait(); sceneContext.pop(); } diff --git a/src/main/resources/fxml/ChatScene.fxml b/src/main/resources/fxml/ChatScene.fxml index fd48b75..ad8e3f2 100644 --- a/src/main/resources/fxml/ChatScene.fxml +++ b/src/main/resources/fxml/ChatScene.fxml @@ -44,7 +44,7 @@ minHeight="-Infinity" prefHeight="40.0" vgrow="NEVER" /> - diff --git a/src/main/resources/fxml/ContactSearchScene.fxml b/src/main/resources/fxml/ContactSearchScene.fxml index b69d15c..a88430c 100644 --- a/src/main/resources/fxml/ContactSearchScene.fxml +++ b/src/main/resources/fxml/ContactSearchScene.fxml @@ -46,8 +46,8 @@ - diff --git a/src/main/resources/fxml/GroupCreationScene.fxml b/src/main/resources/fxml/GroupCreationScene.fxml index 90a8516..0085b03 100644 --- a/src/main/resources/fxml/GroupCreationScene.fxml +++ b/src/main/resources/fxml/GroupCreationScene.fxml @@ -45,8 +45,8 @@ - From 6f4ad4608a411f2e550850acdc51a583a494527d Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Mon, 13 Jul 2020 08:47:44 +0000 Subject: [PATCH 14/14] Remove unnecessary empty line Co-authored-by: delvh --- src/main/java/envoy/client/data/GroupChat.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/envoy/client/data/GroupChat.java b/src/main/java/envoy/client/data/GroupChat.java index 76c0317..aafd3a0 100644 --- a/src/main/java/envoy/client/data/GroupChat.java +++ b/src/main/java/envoy/client/data/GroupChat.java @@ -51,6 +51,5 @@ public class GroupChat extends Chat { } } unreadAmount = 0; - } }