From 60791f29135b9b6134b5f6f01b1521361e406b36 Mon Sep 17 00:00:00 2001 From: DieGurke <55625494+DieGurke@users.noreply.github.com> Date: Mon, 20 Jul 2020 14:09:30 +0200 Subject: [PATCH] Fixed problems with groupMemberName displaying --- .../envoy/client/ui/controller/ChatScene.java | 2 +- .../client/ui/controller/LoginScene.java | 1 + .../client/ui/listcell/MessageControl.java | 38 +++++++++---------- 3 files changed, 19 insertions(+), 22 deletions(-) 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 afc56a8..4b4ea9b 100644 --- a/client/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/client/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -242,7 +242,7 @@ public final class ChatScene implements Restorable { chatList.setItems(FXCollections.observableList(localDB.getChats())); contactLabel.setText(localDB.getUser().getName()); - MessageControl.setUser(localDB.getUser()); + MessageControl.setLocalDB(localDB); if (!client.isOnline()) updateInfoLabel("You are offline", "infoLabel-info"); recorder = new AudioRecorder(); diff --git a/client/src/main/java/envoy/client/ui/controller/LoginScene.java b/client/src/main/java/envoy/client/ui/controller/LoginScene.java index 6140223..def2bb6 100644 --- a/client/src/main/java/envoy/client/ui/controller/LoginScene.java +++ b/client/src/main/java/envoy/client/ui/controller/LoginScene.java @@ -238,5 +238,6 @@ public final class LoginScene { sceneContext.getStage().setMinWidth(843); sceneContext.load(SceneContext.SceneInfo.CHAT_SCENE); sceneContext.getController().initializeData(sceneContext, localDB, client, writeProxy); + sceneContext.getStage().centerOnScreen(); } } diff --git a/client/src/main/java/envoy/client/ui/listcell/MessageControl.java b/client/src/main/java/envoy/client/ui/listcell/MessageControl.java index e3b4e76..3da2ec8 100644 --- a/client/src/main/java/envoy/client/ui/listcell/MessageControl.java +++ b/client/src/main/java/envoy/client/ui/listcell/MessageControl.java @@ -18,6 +18,7 @@ import javafx.scene.image.ImageView; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; +import envoy.client.data.LocalDB; import envoy.client.ui.AudioControl; import envoy.client.ui.IconUtil; import envoy.data.GroupMessage; @@ -34,11 +35,12 @@ import envoy.util.EnvoyLog; * Created: 01.07.2020
* * @author Leon Hofmeister - * @since Envoy Client v0.1-beta + * @author Maximilian Käfer + * @since Envoy Client v0.2-beta */ public class MessageControl extends Label { - private static User client; + private static LocalDB localDB; private boolean ownMessage; private static final DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm:ss") @@ -54,24 +56,18 @@ public class MessageControl extends Label { public MessageControl(Message message) { // Creating the underlying VBox and the dateLabel final var hbox = new HBox(); - if (message.getSenderID() != client.getID() && message instanceof GroupMessage) { - client.getContacts() + if (message.getSenderID() != localDB.getUser().getID() && message instanceof GroupMessage) { + Label label = new Label(); + label.getStyleClass().add("groupMemberNames"); + label.setText(localDB.getUsers() + .values() .stream() - .filter(c -> c instanceof User) .filter(c -> c.getID() == message.getSenderID()) .findFirst() - .ifPresentOrElse(c -> { - Label label = new Label(c.getName() + " "); - label.getStyleClass().add("groupMemberNames"); - hbox.getChildren().add(label); - }, () -> { - Label label = new Label("Unknown User "); - label.getStyleClass().add("groupMemberNames"); - hbox.getChildren().add(label); - }); - // TODO improve offline login (contacts list is empty when logging in offline) - // TODO when contact is added, unknown user has to change immediately to the - // name, not only after relogging + .map(User::getName) + .orElse("Unknown User")); + label.setPadding(new Insets(0, 5, 0, 0)); + hbox.getChildren().add(label); } hbox.getChildren().add(new Label(dateFormat.format(message.getCreationDate()))); final var vbox = new VBox(hbox); @@ -114,7 +110,7 @@ public class MessageControl extends Label { textLabel.setWrapText(true); vbox.getChildren().add(textLabel); // Setting the message status icon and background color - if (message.getSenderID() == client.getID()) { + if (message.getSenderID() == localDB.getUser().getID()) { final var statusIcon = new ImageView(statusImages.get(message.getStatus())); statusIcon.setPreserveRatio(true); vbox.getChildren().add(statusIcon); @@ -147,10 +143,10 @@ public class MessageControl extends Label { private void saveAttachment(Message message) { logger.log(Level.FINEST, "attachment saving was requested for " + message); } /** - * @param client the user who has logged in - * @since Envoy Client v0.1-beta + * @param localDB the localDB + * @since Envoy Client v0.2-beta */ - public static void setUser(User client) { MessageControl.client = client; } + public static void setLocalDB(LocalDB localDB) { MessageControl.localDB = localDB; } public boolean isOwnMessage() { return ownMessage; } }