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] 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); }